private void OnIncomingInstantMessagingCallReceived(object sender, CallReceivedEventArgs<InstantMessagingCall> e) { _imCall = e.Call; try { // Accept the incoming call. _imCall.BeginAccept(ar => { try { _imCall.EndAccept(ar); _logger.Log("Accepted incoming call."); } catch (RealTimeException rtex) { _logger.Log("Failed accepting incoming IM call.", rtex); } }, null); } catch (InvalidOperationException ioex) { _logger.Log("Failed accepting incoming IM call.", ioex); } }
private void InstantMessagingCallAcceptedCallBack(IAsyncResult ar) { InstantMessagingCall instantMessagingCall = ar.AsyncState as InstantMessagingCall; try { // Determine whether the call was accepted successfully. instantMessagingCall.EndAccept(ar); Message m = new Message("InstantMessagingCall Accepted. Call state: " + instantMessagingCall.State.ToString() + ". CallId: " + instantMessagingCall.CallId + ".", instantMessagingCall.RemoteEndpoint.Participant.DisplayName, instantMessagingCall.RemoteEndpoint.Participant.UserAtHost, instantMessagingCall.RemoteEndpoint.Participant.Uri, MessageType.InstantMessage, _transcriptRecorder.Conversation.Id, MessageDirection.Incoming); _transcriptRecorder.OnMessageReceived(m); _transcriptRecorder.OnRemoteParticipantAdded(null, instantMessagingCall.RemoteEndpoint); } catch (RealTimeException exception) { // RealTimeException may be thrown on media or link-layer failures. // A production application should catch additional exceptions, such as OperationTimeoutException, // OperationTimeoutException, and CallOperationTimeoutException. NonBlockingConsole.WriteLine(exception.ToString()); } finally { // Synchronize with main thread. _waitForIMCallAccepted.Set(); _state = TranscriptRecorderState.Active; } }
internal void HandleSupervisorInitialCall(InstantMessagingCall imCall) { Debug.Assert(imCall is InstantMessagingCall); _logger.Log("AcdSupervisorSession receives first incoming Call from " + imCall.RemoteEndpoint.Participant.Uri); if (_state == SupervisorSessionState.Incoming) { // sets the initial customer call _initialSupervisorCall = imCall; // monitors the customer-facing conversation state this.SetFrontEndConversationProperties(imCall); try { imCall.BeginAccept(ar => { try { imCall.EndAccept(ar); this.InitializeSupervisorControlChannel(); } catch (RealTimeException rtex) { _logger.Log("AcdSupervisorSession failed to end accept the incoming call from Supervisor", rtex); this.BeginShutDown(sdar => { this.EndShutDown(sdar); }, null); } }, null); } catch (InvalidOperationException ivoex) { _logger.Log("AcdSupervisorSession failed to accept the incoming call from Supervisor", ivoex); this.BeginShutDown(sdar => { this.EndShutDown(sdar); }, null); } } else { _logger.Log("AcdSupervisorSession is not in the correct state to process the new initial call"); this.BeginShutDown(ar => { this.EndShutDown(ar); }, null); } }
// Callback method referred to in the call to BeginAccept on the InstantMessagingCall instance. private void CallAcceptCB(IAsyncResult ar) { InstantMessagingCall instantMessagingCall = ar.AsyncState as InstantMessagingCall; try { // Determine whether the IM Call was accepted successfully. instantMessagingCall.EndAccept(ar); } catch (RealTimeException exception) { // RealTimeException can be thrown on media or link-layer failures. Console.WriteLine(exception.ToString()); } finally { // Synchronize with main thread. _waitUntilIncomingCallIsAccepted.Set(); } }
private void EndAcceptCall(IAsyncResult ar) { InstantMessagingCall instantMessagingCall = ar.AsyncState as InstantMessagingCall; try { // Determine whether the IM Call was accepted successfully. instantMessagingCall.EndAccept(ar); } catch (RealTimeException exception) { // RealTimeException may be thrown on media or link-layer // failures. // TODO: Add actual error handling code here. Console.WriteLine(exception.ToString()); } finally { //Again, just to sync the completion of the code. _autoResetEvent.Set(); } }
private void HandleIMCall(object state) { CallReceivedEventArgs <InstantMessagingCall> e = state as CallReceivedEventArgs <InstantMessagingCall>; ConversationParticipant caller = e.Call.RemoteEndpoint.Participant; InstantMessagingCall imCall = e.Call; InstantMessagingFlow imFlow = null; int messageCount = 0; imCall.InstantMessagingFlowConfigurationRequested += delegate(object sender2, InstantMessagingFlowConfigurationRequestedEventArgs e2) { imFlow = e2.Flow; imFlow.MessageReceived += delegate(object sender3, InstantMessageReceivedEventArgs e3) { messageCount++; string message = e3.TextBody; message = message.Trim(); if (!String.IsNullOrEmpty(message) && message.StartsWith("add", StringComparison.OrdinalIgnoreCase)) { string[] tokens = message.Split(' '); if (this.AppPlatform.ReverseNumberLookUp.AddEntry(tokens[1], caller.Uri)) { this.SendIMResponse(imFlow, "Added telephone number."); } else { this.SendIMResponse(imFlow, "Telephone number exists."); } } else if (!String.IsNullOrEmpty(message) && message.StartsWith("remove", StringComparison.OrdinalIgnoreCase)) { string[] tokens = message.Split(' '); if (this.AppPlatform.ReverseNumberLookUp.RemoveEntry(tokens[1], caller.Uri)) { this.SendIMResponse(imFlow, "Removed telephone number."); } else { this.SendIMResponse(imFlow, "Telephone number does not exist or you do not own the tel #."); } } else if (!String.IsNullOrEmpty(message) && message.Equals("list", StringComparison.OrdinalIgnoreCase)) { Collection <string> list = this.AppPlatform.ReverseNumberLookUp.FindPhoneNumbers(caller.Uri); StringBuilder response = new StringBuilder(); foreach (string s in list) { response.Append(s); response.Append("\r\n"); } this.SendIMResponse(imFlow, response.ToString()); } else { this.SendIMHelpMessage(imFlow); } if (messageCount > 5) // We could also terminate based on timer. { this.TerminateIMCall(imCall); } }; }; try { imCall.BeginAccept( delegate(IAsyncResult ar) { try { imCall.EndAccept(ar); this.SendIMHelpMessage(imFlow); } catch (RealTimeException) { } }, null); } catch (InvalidOperationException) { } }
/// <summary> /// Handle incoming IM call from the customer. /// </summary> /// <param name="imCall">IM call.</param> public void HandleIncomingInstantMessagingCall(InstantMessagingCall imCall) { lock (syncRoot) { if (this.conversation == null) { this.conversation = imCall.Conversation; this.RegisterConversationEventHandlers(this.conversation); } if (this.conversationContextChannel == null && !String.IsNullOrEmpty(this.application.CweGuid)) { this.conversationContextChannel = new ConversationContextChannel(this.conversation, imCall.RemoteEndpoint); this.RegisterContextChannelHandlers(this.conversationContextChannel); } this.imIvr = new InstantMessagingIVR(this, imCall, this.conversationContextChannel, this.menu, this.logger); this.imIvr.isUserEndpointFirstMessage = true; try { imCall.BeginAccept((asyncResult) => { try { imCall.EndAccept(asyncResult); if (this.conversationContextChannel != null && this.conversationContextChannel.State == ConversationContextChannelState.Idle) { ConversationContextChannelEstablishOptions channelOptions = new ConversationContextChannelEstablishOptions(); channelOptions.ApplicationName = this.application.Name; channelOptions.ContextualData = "Context channel is open."; channelOptions.Toast = "Please check the accompaining CWE window for Graphical Experience"; Guid appGuid = new Guid(this.application.CweGuid); try { this.conversationContextChannel.BeginEstablish(appGuid, channelOptions, (contextChannelAsyncResult) => { try { this.conversationContextChannel.EndEstablish(contextChannelAsyncResult); } catch (RealTimeException rte) { Console.WriteLine("Error establishing conversation context channel {0}", rte); this.logger.Log("Error establishing conversation context channel {0}", rte); } }, null); } catch (InvalidOperationException ioe) { Console.WriteLine("Error establishing conversation context channel {0}", ioe); this.logger.Log("Error establishing conversation context channel {0}", ioe); } } } catch (RealTimeException rte) { Console.WriteLine("Error accepting incoming IM call {0}", rte); this.logger.Log("Error accepting incoming IM call {0}", rte); } }, null); } catch (InvalidOperationException ioe) { Console.WriteLine("Error accepting incoming IM call {0}", ioe); this.logger.Log("Error accepting incoming IM call {0}", ioe); } } }