Advertisement
Guest User

Untitled

a guest
Jun 18th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. return found;
  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
Advertisement