Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Run(string sendTo, string message, bool persist)
- {
- // Initialize and startup the platform.
- Exception ex = null;
- try
- {
- // Create the UserEndpoint
- _messageToSend = message;
- _persist = persist;
- _helper = new Helper();
- _userEndpoint = _helper.CreateEstablishedUserEndpoint(
- "Network Monitor" /*endpointFriendlyName*/);
- logger.Info("The User Endpoint owned by URI: ");
- //logger.Info(_userEndpoint.OwnerUri);
- logger.Info(" is now established and registered.");
- // Setup the conversation and place the call.
- ConversationSettings convSettings = new ConversationSettings();
- convSettings.Priority = _conversationPriority;
- convSettings.Subject = _conversationSubject;
- _userEndpoint.PresenceServices.BeginUpdatePresenceState(new PresenceState(PresenceStateType.UserState,
- (int)PresenceAvailability.Busy,
- new PresenceActivity(new LocalizedString("Monitoring"))),
- ar => _userEndpoint.PresenceServices.EndUpdatePresenceState(ar),
- null);
- // Conversation represents a collection of modes of communication
- // (media types)in the context of a dialog with one or multiple
- // callees.
- Conversation conversation = new Conversation(_userEndpoint, convSettings);
- _instantMessagingCall = new InstantMessagingCall(conversation);
- logger.Info("Conversation Setup, getting ready to send to: " + sendTo);
- // Call: StateChanged: Only hooked up for logging. Generally,
- // this can be used to surface changes in Call state to the UI
- _instantMessagingCall.StateChanged += this.InstantMessagingCall_StateChanged;
- // Subscribe for the flow created event; the flow will be used to
- // send the media (here, IM).
- // Ultimately, as a part of the callback, the messages will be
- // sent/received.
- _instantMessagingCall.InstantMessagingFlowConfigurationRequested +=
- this.InstantMessagingCall_FlowConfigurationRequested;
- // Get the sip address of the far end user to communicate with.
- String _calledParty = "sip:" + sendTo;
- // Place the call to the remote party, without specifying any
- // custom options. Please note that the conversation subject
- // overrides the toast message, so if you want to see the toast
- // message, please set the conversation subject to null.
- _instantMessagingCall.BeginEstablish(_calledParty, new ToastMessage("Hello Toast"), null,
- CallEstablishCompleted, _instantMessagingCall);
- }
- catch (InvalidOperationException iOpEx)
- {
- // Invalid Operation Exception may be thrown if the data provided
- // to the BeginXXX methods was invalid/malformed.
- // TODO (Left to the reader): Write actual handling code here.
- ex = iOpEx;
- }
- finally
- {
- if (ex != null)
- {
- // If the action threw an exception, terminate the sample,
- // and print the exception to the console.
- // TODO (Left to the reader): Write actual handling code here.
- logger.Info(ex.ToString());
- logger.Info("Shutting down platform due to error");
- _helper.ShutdownPlatform();
- }
- }
- // Wait for sample to complete
- _sampleCompletedEvent.WaitOne();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement