Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. public void Run(string sendTo, string message, bool persist)
  2. {
  3.  
  4. // Initialize and startup the platform.
  5. Exception ex = null;
  6. try
  7. {
  8.  
  9. // Create the UserEndpoint
  10. _messageToSend = message;
  11. _persist = persist;
  12. _helper = new Helper();
  13. _userEndpoint = _helper.CreateEstablishedUserEndpoint(
  14. "Network Monitor" /*endpointFriendlyName*/);
  15.  
  16. logger.Info("The User Endpoint owned by URI: ");
  17. //logger.Info(_userEndpoint.OwnerUri);
  18. logger.Info(" is now established and registered.");
  19.  
  20. // Setup the conversation and place the call.
  21. ConversationSettings convSettings = new ConversationSettings();
  22. convSettings.Priority = _conversationPriority;
  23. convSettings.Subject = _conversationSubject;
  24.  
  25.  
  26. _userEndpoint.PresenceServices.BeginUpdatePresenceState(new PresenceState(PresenceStateType.UserState,
  27. (int)PresenceAvailability.Busy,
  28. new PresenceActivity(new LocalizedString("Monitoring"))),
  29. ar => _userEndpoint.PresenceServices.EndUpdatePresenceState(ar),
  30. null);
  31. // Conversation represents a collection of modes of communication
  32. // (media types)in the context of a dialog with one or multiple
  33. // callees.
  34. Conversation conversation = new Conversation(_userEndpoint, convSettings);
  35. _instantMessagingCall = new InstantMessagingCall(conversation);
  36. logger.Info("Conversation Setup, getting ready to send to: " + sendTo);
  37. // Call: StateChanged: Only hooked up for logging. Generally,
  38. // this can be used to surface changes in Call state to the UI
  39. _instantMessagingCall.StateChanged += this.InstantMessagingCall_StateChanged;
  40.  
  41. // Subscribe for the flow created event; the flow will be used to
  42. // send the media (here, IM).
  43. // Ultimately, as a part of the callback, the messages will be
  44. // sent/received.
  45. _instantMessagingCall.InstantMessagingFlowConfigurationRequested +=
  46. this.InstantMessagingCall_FlowConfigurationRequested;
  47.  
  48. // Get the sip address of the far end user to communicate with.
  49. String _calledParty = "sip:" + sendTo;
  50.  
  51. // Place the call to the remote party, without specifying any
  52. // custom options. Please note that the conversation subject
  53. // overrides the toast message, so if you want to see the toast
  54. // message, please set the conversation subject to null.
  55. _instantMessagingCall.BeginEstablish(_calledParty, new ToastMessage("Hello Toast"), null,
  56. CallEstablishCompleted, _instantMessagingCall);
  57.  
  58.  
  59. }
  60. catch (InvalidOperationException iOpEx)
  61. {
  62. // Invalid Operation Exception may be thrown if the data provided
  63. // to the BeginXXX methods was invalid/malformed.
  64. // TODO (Left to the reader): Write actual handling code here.
  65. ex = iOpEx;
  66. }
  67. finally
  68. {
  69. if (ex != null)
  70. {
  71. // If the action threw an exception, terminate the sample,
  72. // and print the exception to the console.
  73. // TODO (Left to the reader): Write actual handling code here.
  74. logger.Info(ex.ToString());
  75. logger.Info("Shutting down platform due to error");
  76. _helper.ShutdownPlatform();
  77. }
  78. }
  79.  
  80. // Wait for sample to complete
  81. _sampleCompletedEvent.WaitOne();
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement