Guest User

Untitled

a guest
Jun 17th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /*
  3. C# Way
  4.  
  5. public UUID FindUUIDForName(string nameString)
  6. {
  7.  
  8. ManualResetEvent NameSearchEvent = new ManualResetEvent(false);
  9. UUID queryID = UUID.Random();
  10. UUID found = UUID.Zero;
  11. EventHandler<AvatarPickerReplyEventArgs> callback =
  12. new EventHandler<AvatarPickerReplyEventArgs>((s, e) =>
  13. {
  14. if (queryID == e.QueryID)
  15. {
  16.  
  17. foreach (KeyValuePair<UUID, string> kvp in e.Avatars)
  18. {
  19. if (kvp.Value == nameString) {
  20. found = kvp.Key;
  21. break;
  22. }
  23. }
  24. NameSearchEvent.Set();
  25. }
  26. });
  27. try
  28. {
  29. client.Avatars.AvatarPickerReply += callback;
  30. // Send the Query
  31. client.Avatars.RequestAvatarNameSearch(nameString, queryID);
  32.  
  33. NameSearchEvent.WaitOne(10000, false);
  34. }
  35. finally
  36. {
  37. client.Avatars.AvatarPickerReply -= callback;
  38. }
  39. }
  40.  
  41. */
  42. /*
  43. Prolog Way
  44.  
  45. ?- findUUIDForName("Douglas Miles",X).
  46. X = uuid("8f6ce54e-95f5-46d0-b090-c5361c821232").
  47.  
  48. */
  49. findUUIDForName(NameString,Found):-
  50. cli_call('UUID','Random',QID), % make a random UUID
  51. botget(['Avatars'],AvMan), % get the AvatarManager object
  52. cli_new_event_waiter(AvMan,'AvatarPickerReply',WaitOn), % create a new event handler object (and register it)
  53. cli_call(AvMan,'RequestAvatarNameSearch'(NameString,QID),_), % make the request to the server
  54. cli_block_until_event(WaitOn, 10000, closure(Evt,cli_get(Evt,'QueryID',QID)), _), % wait for up to 10 seconds for the right the QueryID
  55. cli_get(Evt,'Avatars',U2SDict), % get the UUID2Name dictionary
  56. cli_map(U2SDict,Found,NameString), % Search that dictionary for the UUID by matching the String
  57. cli_call(WaitOn,'Dispose',_). % unregister the handler and dispose
Advertisement
Add Comment
Please, Sign In to add comment