Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 2.01 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2. C# Way
  3.  
  4.         public UUID FindUUIDForName(string nameString)
  5.         {
  6.  
  7.             ManualResetEvent NameSearchEvent = new ManualResetEvent(false);
  8.             UUID queryID = UUID.Random();
  9.             UUID found = UUID.Zero;
  10.             EventHandler<AvatarPickerReplyEventArgs> callback =
  11.                 new EventHandler<AvatarPickerReplyEventArgs>((s, e) =>
  12.                 {
  13.                     if (queryID == e.QueryID)
  14.                     {
  15.  
  16.                         foreach (KeyValuePair<UUID, string> kvp in e.Avatars)
  17.                         {
  18.                             if (kvp.Value == nameString) {
  19.                                found = kvp.Key;
  20.                                break;
  21.                             }
  22.                         }
  23.                         NameSearchEvent.Set();
  24.                     }
  25.                 });
  26.             try
  27.             {
  28.                 client.Avatars.AvatarPickerReply += callback;
  29.                 // Send the Query
  30.                 client.Avatars.RequestAvatarNameSearch(nameString, queryID);
  31.  
  32.                 NameSearchEvent.WaitOne(10000, false);
  33.             }
  34.             finally
  35.             {
  36.                 client.Avatars.AvatarPickerReply -= callback;
  37.             }
  38.         }
  39.  
  40. */
  41.  
  42. %% Prolog Way
  43. findUUIDForName(NameString,Found):-
  44.    cli_call('UUID','Random',QID),      % make a random UUID
  45.    botget(['Avatars'],AvMan),          % get the AvatarManager object
  46.    cli_new_event_waiter(AvMan,'AvatarPickerReply',WaitOn),  % create a new event handler object (and register it)
  47.    cli_call(AvMan,'RequestAvatarNameSearch'(NameString,QID),_),   % make the request to the server
  48.    cli_block_until_event(WaitOn, 10000, c(Evt,cli_get(Evt,'QueryID',QID)), _),  %  wait for up to 10 seconds for the right the QueryID
  49.    cli_get(Evt,'Avatars',U2SDict),  % get the UUID2Name dictionary
  50.    cli_map(U2SDict,Found,NameString),   % Search that dictionary for the UUID by matching the String
  51.    cli_call(WaitOn,'Dispose',_).  % unregister the handler and dispose