/// <summary> /// Helper method to create new web conversation. /// </summary> /// <param name="request">Create conversation request.</param> /// <param name="conversationCallback">Conversation callback.</param> /// <param name="contextChannel">Context channel.</param> /// <returns>WebConversation.</returns> internal WebConversation CreateNewWebConversation(CreateConversationRequest request, IConversationCallback conversationCallback, IContextChannel contextChannel) { WebConversation webConversation = null; ConversationSettings convSettings = new ConversationSettings(); convSettings.Subject = request.ConversationSubject; //First create a ucma conversation. Conversation ucmaConversation = new Conversation(this.ApplicationEndpoint, convSettings); ucmaConversation.Impersonate(WebConversationManager.CreateUserUri(this.ApplicationEndpoint.DefaultDomain), null /*phoneUri*/, request.DisplayName); //Register for state changes. ucmaConversation.StateChanged += this.UcmaConversation_StateChanged; //Now create a web conversation. webConversation = new WebConversation(ucmaConversation, conversationCallback, request.ConversationContext, contextChannel); //Add conversation to local cache. lock (m_conversationDictionary) { m_conversationDictionary.Add(webConversation.Id, webConversation); } return(webConversation); }
/// <summary> /// Overridden process method. /// </summary> public override void Process() { bool unhandledExceptionDetected = true; Exception caughtException = null; WebConversation webConversation = this.ConversationModel.WebConversation; try { this.ConversationModel.ContactCenterService.BeginEstablishAvCall(webConversation, null /*destination*/, this.CallbackNumber, this.AvCallEstablishmentCompleted, null /*state*/); unhandledExceptionDetected = false; } catch (FaultException <OperationFault> fex) { caughtException = fex; unhandledExceptionDetected = false; } finally { if (unhandledExceptionDetected) { Debug.Assert(null == caughtException, "Caught exception is not null"); caughtException = new Exception(ExceptionResource.UnhandledExceptionOccured); } if (caughtException != null) { this.Complete(caughtException); } } }
/// <summary> /// Initiates an operation to establish a new im call with the contact center service. /// </summary> /// <param name="webConversation">Web conversation.</param> /// <param name="destination">Destination.</param> /// <param name="callback">Callback method.</param> /// <param name="state">State.</param> /// <returns>Async result reference.</returns> public IAsyncResult BeginEstablishImCall(WebConversation webConversation, string destination, AsyncCallback callback, object state) { //Create new request. EstablishInstantMessagingCallRequest request = new EstablishInstantMessagingCallRequest(); request.RequestId = ContactCenterService.GenerateNewRequestId(); request.Conversation = webConversation; request.Destination = destination; return(((IContactCenterWcfService)this.WcfClient).BeginEstablishInstantMessagingCall(request, callback, state)); }
/// <summary> /// Initiates an operation to establish a new im call with the contact center service. /// </summary> /// <param name="webConversation">Web conversation.</param> /// <param name="message">Message.</param> /// <param name="callback">Callback method.</param> /// <param name="state">State.</param> /// <returns>Async result reference.</returns> public IAsyncResult BeginSendImMessage(WebConversation webConversation, string message, AsyncCallback callback, object state) { //Create new request. SendInstantMessageRequest request = new SendInstantMessageRequest(); request.RequestId = ContactCenterService.GenerateNewRequestId(); request.Conversation = webConversation; request.Message = message; return(((IContactCenterWcfService)this.WcfClient).BeginSendInstantMessage(request, callback, state)); }
/// <summary> /// Initiates an operation to establish a new av call with the contact center service. /// </summary> /// <param name="webConversation">Web conversation.</param> /// <param name="destination">Destination.</param> /// <param name="callback">Callback method.</param> /// <param name="state">State.</param> /// <returns>Async result reference.</returns> public IAsyncResult BeginEstablishAvCall(WebConversation webConversation, string destination, string callbackPhoneNumber, AsyncCallback callback, object state) { //Create new request. EstablishAudioVideoCallRequest request = new EstablishAudioVideoCallRequest(); request.RequestId = ContactCenterService.GenerateNewRequestId(); request.Conversation = webConversation; request.Destination = destination; request.CallbackPhoneNumber = callbackPhoneNumber; return(((IContactCenterWcfService)this.WcfClient).BeginEstablishAudioVideoCall(request, callback, state)); }
/// <summary> /// Constructor to create new TerminateConversationAsyncResult. /// </summary> /// <param name="request">Terminate conversation request. cannot be null.</param> /// <param name="webConversation">Web conversation to terminate. Cannot be null.</param> /// <param name="userCallback">User callback.</param> /// <param name="state">User state.</param> internal TerminateConversationAsyncResult(TerminateConversationRequest request, WebConversation webConversation, AsyncCallback userCallback, object state) : base(userCallback, state) { Debug.Assert(null != webConversation, "Web conversation is null"); Debug.Assert(null != request, "Request is null"); m_webConversation = webConversation; m_terminateConversationRequest = request; }
/// <summary> /// Initiates a conversation termination operation. /// </summary> /// <param name="webConversation">Web conversation.</param> /// <param name="asyncCallback">Async callback.</param> /// <param name="state">State.</param> /// <returns>Async result reference</returns> public IAsyncResult BeginTerminateConversation(WebConversation webConversation, AsyncCallback callback, object state) { //Create new request. if (webConversation == null) { throw new ArgumentNullException("webConversation", "Web conversation cannot be null"); } TerminateConversationRequest request = new TerminateConversationRequest(); request.RequestId = ContactCenterService.GenerateNewRequestId(); request.Conversation = webConversation; return(((IContactCenterWcfService)this.WcfClient).BeginTerminateConversation(request, callback, state)); }
/// <summary> /// Session terminated. /// </summary> /// <param name="webConversation">Web conversation.</param> public void SessionTerminated(WebConversation webConversation) { if (webConversation == null) { throw new ArgumentNullException("webConversation", "Web conversation cannot be null"); } SessionTerminationRequest request = new SessionTerminationRequest(); request.RequestId = ContactCenterService.GenerateNewRequestId(); request.Conversations = new System.Collections.ObjectModel.ObservableCollection <WebConversation>(); request.Conversations.Add(webConversation); ((IContactCenterWcfService)this.WcfClient).BeginSessionTerminated(request, this.SessionTerminatedCompleted, null); }
/// <summary> /// Returns active conversation callback handler. Can return null if the callback handler is not active. /// </summary> /// <param name="webConversation">Web conversation for which we need an active callback handler.</param> /// <returns>Active conversation callback.</returns> internal static IConversationCallback GetActiveConversationCallback(WebConversation webConversation) { IConversationCallback callback = null; Debug.Assert(null != webConversation, "Web conversation cannot be null"); ICommunicationObject communicationObject = webConversation.ConversationCallback as ICommunicationObject; if (communicationObject != null && (communicationObject.State == CommunicationState.Opened)) { callback = webConversation.ConversationCallback; } return(callback); }
/// <summary> /// Conversation terminated event handler. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">Event args.</param> private void ConversationTerminatedHandler(object sender, ConversationNotificationReceivedEventArgs <ConversationTerminatedNotification> e) { WebConversation webConversation = this.WebConversation; if (webConversation != null) { if (e.Notification.WebConversation.Id.Equals(webConversation.Id)) { lock (m_syncRoot) { this.TryUpdateState(ConversationModelState.Terminating); this.TryUpdateState(ConversationModelState.Terminated); } } } }
/// <summary> /// Im typing notification handler. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">Event args.</param> private void ImComposingStatusNotificationReceivedHandler(object sender, ConversationNotificationReceivedEventArgs <ImComposingStatusNotification> e) { WebConversation webConversation = this.WebConversation; if (webConversation != null) { if (e.Notification.WebConversation.Id.Equals(webConversation.Id)) { var imTypingNotificationReceived = this.ImTypingNotificationReceived; if (imTypingNotificationReceived != null) { var eventArgs = new InstantMessageTypingNotificationReceivedEventArgs(e.Notification.RemoteComposingStatus); imTypingNotificationReceived(this, eventArgs); } } } }
/// <summary> /// Im received handler. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">Event args.</param> private void ImMessageReceivedHandler(object sender, ConversationNotificationReceivedEventArgs <ImMessageReceivedNotification> e) { WebConversation webConversation = this.WebConversation; if (webConversation != null) { if (e.Notification.WebConversation.Id.Equals(webConversation.Id)) { var imMessageReceived = this.ImMessageReceived; if (imMessageReceived != null) { var eventArgs = new InstantMessageReceivedEventArgs(e.Notification.Message, e.Notification.MessageSender); imMessageReceived(this, eventArgs); } } } }
/// <summary> /// Gets the mathcing web conversation, if any, based on given id. /// </summary> /// <param name="id">Conversation id.</param> /// <returns>Matching web conversation if any.</returns> internal WebConversation GetWebConversationFromId(string id) { WebConversation webConversation = null; string conversationId = id; if (!String.IsNullOrEmpty(conversationId)) { lock (m_conversationDictionary) { if (m_conversationDictionary.ContainsKey(conversationId)) { webConversation = m_conversationDictionary[conversationId]; } } } return(webConversation); }
/// <summary> /// Constructor to create new EstablishClickToCallAsyncResult. /// </summary> /// <param name="request">Establish Av call request. cannot be null.</param> /// <param name="callbackAvCall">Callback Audio Video call to establish. Cannot be null.</param> /// <param name="webConversation">Web conversation to use.</param> /// <param name="completingActionDelegate">Delegate to be invoked just before completion of this async result.</param> /// <param name="userCallback">User callback.</param> /// <param name="state">User state.</param> internal EstablishClickToCallAsyncResult(EstablishAudioVideoCallRequest request, AudioVideoCall callbackAvCall, WebConversation webConversation, Action <EstablishClickToCallAsyncResult> completingActionDelegate, AsyncCallback userCallback, object state) : base(userCallback, state) { Debug.Assert(null != callbackAvCall, "Av call is null"); Debug.Assert(null != request, "Request is null"); Debug.Assert(!String.IsNullOrEmpty(request.CallbackPhoneNumber), "Callback number is null or empty"); Debug.Assert(null != webConversation, "Web conversation is null"); m_establishAvCallRequest = request; m_callbackCall = callbackAvCall; m_completingDelegate = completingActionDelegate; m_webConversation = webConversation; }
/// <summary> /// Constructor to create new EstablishInstantMessagingCallAsyncResult. /// </summary> /// <param name="request">Establish Im call request. cannot be null.</param> /// <param name="webConversation">Web conversation.</param> /// <param name="destinationUri">Destination uri.</param> /// <param name="imCall">Instant messaging call to establish. Cannot be null.</param> /// <param name="customMimePart">Custom MIME part to use. Can be null.</param> /// <param name="userCallback">User callback.</param> /// <param name="state">User state.</param> internal EstablishInstantMessagingCallAsyncResult(EstablishInstantMessagingCallRequest request, WebConversation webConversation, string destinationUri, InstantMessagingCall imCall, MimePartContentDescription customMimePart, AsyncCallback userCallback, object state) : base(userCallback, state) { Debug.Assert(null != imCall, "Im call is null"); Debug.Assert(null != request, "Request is null"); Debug.Assert(null != webConversation, "WebConversation is null"); m_imCall = imCall; m_cutomMimePart = customMimePart; m_establishImCallRequest = request; m_webConversation = webConversation; m_destinationUri = destinationUri; }
/// <summary> /// Constructor to create new EstablishAudioVideoCallAsyncResult. /// </summary> /// <param name="request">Establish Av call request. cannot be null.</param> /// <param name="avCall">Audio Video call to establish. Cannot be null.</param> /// <param name="destinationUri">Destination uri.</param> /// <param name="webConversation">Web conversation to use.</param> /// <param name="customMimePart">Custom MIME part to use. Can be null.</param> /// <param name="userCallback">User callback.</param> /// <param name="state">User state.</param> internal EstablishAudioVideoCallAsyncResult(EstablishAudioVideoCallRequest request, AudioVideoCall avCall, string destinationUri, WebConversation webConversation, MimePartContentDescription customMimePart, AsyncCallback userCallback, object state) : base(userCallback, state) { Debug.Assert(null != avCall, "Av call is null"); Debug.Assert(null != request, "Request is null"); Debug.Assert(null != webConversation, "Web conversation to use is null."); m_cutomMimePart = customMimePart; m_establishAvCallRequest = request; m_avCall = avCall; m_webConversation = webConversation; m_destinationUri = destinationUri; }
/// <summary> /// conv establish completed callback method. /// </summary> /// <param name="asyncResult">Async result.</param> private void ConversationEstablishmentCompleted(IAsyncResult asyncResult) { Exception caughtException = null; bool unhandledExceptionDetected = true; WebConversation webConversation = null; try { webConversation = this.ConversationModel.ContactCenterService.EndEstablishConversation(asyncResult); this.ConversationModel.WebConversation = webConversation; if (!this.ConversationModel.TryUpdateState(ConversationModelState.Established)) { caughtException = new Exception(ExceptionResource.InvalidState); //Start termination operation since we cannot update state. this.ConversationModel.BeginTerminateConversation(this.ConversationTerminationCompleted, null); } unhandledExceptionDetected = false; } catch (FaultException <OperationFault> fex) { caughtException = fex; unhandledExceptionDetected = false; } finally { if (unhandledExceptionDetected) { Debug.Assert(null == caughtException, "Caught exception is not null"); caughtException = new Exception(ExceptionResource.UnhandledExceptionOccured); } if (caughtException != null) { this.Complete(caughtException); } else { Debug.Assert(null != webConversation, "For successful case web conversation should not be null"); EstablishConversationResult result = new EstablishConversationResult(webConversation); this.Complete(result); } } }
/// <summary> /// conv establish completed callback method. /// </summary> /// <param name="asyncResult">Async result.</param> private void ConversationEstablishmentCompleted(IAsyncResult asyncResult) { Exception caughtException = null; bool unhandledExceptionDetected = true; WebConversation webConversation = null; try { webConversation = this.ConversationModel.ContactCenterService.EndEstablishConversation(asyncResult); this.ConversationModel.WebConversation = webConversation; if (!this.ConversationModel.TryUpdateState(ConversationModelState.Established)) { caughtException = new Exception(ExceptionResource.InvalidState); //Start termination operation since we cannot update state. this.ConversationModel.BeginTerminateConversation(this.ConversationTerminationCompleted, null); } else { //Proceed to establish IM call. this.ConversationModel.ContactCenterService.BeginEstablishImCall(webConversation, m_destinationQueue, this.ImCallEstablishmentCompleted, webConversation /*state*/); } unhandledExceptionDetected = false; } catch (FaultException <OperationFault> fex) { caughtException = fex; unhandledExceptionDetected = false; } finally { if (unhandledExceptionDetected) { Debug.Assert(null == caughtException, "Caught exception is not null"); caughtException = new Exception(ExceptionResource.UnhandledExceptionOccured); } if (caughtException != null) { this.Complete(caughtException); } } }
/// <summary> /// Overridden process method. /// </summary> public override void Process() { bool unhandledExceptionDetected = true; Exception caughtException = null; try { WebConversation webConversation = this.ConversationModel.WebConversation; if (webConversation != null) { this.ConversationModel.ContactCenterService.BeginTerminateConversation(webConversation, this.ConversationTerminationCompleted, null /*state*/); } else { this.CompleteConversationTermination(); } unhandledExceptionDetected = false; } catch (FaultException <OperationFault> fex) { caughtException = fex; unhandledExceptionDetected = false; } finally { if (unhandledExceptionDetected) { Debug.Assert(null == caughtException, "Caught exception is not null"); caughtException = new Exception(ExceptionResource.UnhandledExceptionOccured); } if (caughtException != null) { //Even though exception occured terminate the conversation because app might not be ready to handle exceptions during termination. this.CompleteConversationTermination(); } } }
/// <summary> /// Im call established completed. /// </summary> /// <param name="asyncResult">Async result.</param> private void ImCallEstablishmentCompleted(IAsyncResult asyncResult) { Exception caughtException = null; bool unhandledExceptionDetected = true; WebConversation webConversation = asyncResult.AsyncState as WebConversation; Debug.Assert(null != webConversation, "Web conversation is null"); try { this.ConversationModel.ContactCenterService.EndEstablishImCall(asyncResult); unhandledExceptionDetected = false; } catch (FaultException <OperationFault> fex) { caughtException = fex; unhandledExceptionDetected = false; } finally { if (unhandledExceptionDetected) { Debug.Assert(null == caughtException, "Caught exception is not null"); caughtException = new Exception(ExceptionResource.UnhandledExceptionOccured); } if (caughtException != null) { this.Complete(caughtException); } else { EstablishConversationAndImCallResult result = new EstablishConversationAndImCallResult(webConversation); this.Complete(result); } } }
/// <summary> /// Ucma conversation state changed handler. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">Event args.</param> private void UcmaConversation_StateChanged(object sender, Microsoft.Rtc.Signaling.StateChangedEventArgs <ConversationState> e) { if (e.State == ConversationState.Terminating) { Conversation conversation = sender as Conversation; WebConversation webConversation = null; //If conversation is terminating remove it from local dictionary. lock (m_conversationDictionary) { conversation.StateChanged -= this.UcmaConversation_StateChanged; if (!m_conversationDictionary.TryGetValue(conversation.Id, out webConversation)) { webConversation = null; } m_conversationDictionary.Remove(conversation.Id); } if (webConversation != null) { ConversationTerminationNotification conversationTerminationNotification = new ConversationTerminationNotification(); conversationTerminationNotification.Conversation = webConversation; IConversationCallback convCallback = WebConversationManager.GetActiveConversationCallback(webConversation); if (convCallback != null) { try { convCallback.ConversationTerminated(conversationTerminationNotification); } catch (System.TimeoutException) { } } } } }
/// <summary> /// Internal constructor to create im message received event args. /// </summary> /// <param name="webConversation">Web conversation.</param> /// <param name="message">Message</param> /// <param name="messageSender">Message sender.</param> internal ImMessageReceivedNotification(WebConversation webConversation, string message, string messageSender) : base(webConversation) { m_message = message ?? String.Empty; m_messageSender = messageSender ?? String.Empty; }
/// <summary> /// Callback. /// </summary> /// <param name="asyncResult"></param> private void WebConversationTerminationCompleted(IAsyncResult asyncResult) { WebConversation webConveration = asyncResult.AsyncState as WebConversation; webConveration.EndTerminate(asyncResult); }
/// <summary> /// Constructor. /// </summary> /// <param name="webConversation">web conversation. Cannot be null or empty.</param> internal ConversationNotification(WebConversation webConversation) { Debug.Assert(webConversation != null, "web Conversation cannot be null or empty"); m_webConversation = webConversation; }
/// <summary> /// Constructor. /// </summary> /// <param name="webConversation">Web conversation. Cannot be null.</param> internal AddClickToCallResult(WebConversation webConversation) : base(webConversation) { }
/// <summary> /// Constructor. /// </summary> /// <param name="webConversation">Web conversation. Cannot be null.</param> internal EstablishConversationAndImCallResult(WebConversation webConversation) : base(webConversation) { }
/// <summary> /// Constructor. /// </summary> /// <param name="webConversation">Web conversation. Cannot be null.</param> internal EstablishConversationResult(WebConversation webConversation) : base(webConversation) { }
/// <summary> /// Constructor. /// </summary> /// <param name="webConversation">Web conversation. Cannot be null.</param> internal ConversationResult(WebConversation webConversation) { Debug.Assert(null != webConversation, "Web conversation is null"); m_webConversation = webConversation; }
/// <summary> /// Internal constructor to create av call terminated notification. /// </summary> /// <param name="webConversation">Web conversation.</param> internal AvCallTerminatedNotification(WebConversation webConversation) : base(webConversation) { }
/// <summary> /// Internal constructor to create im composing status notification. /// </summary> /// <param name="webConversation">Web conversation.</param> /// <param name="remoteComposingStatus">Remote composing status.</param> internal ImComposingStatusNotification(WebConversation webConversation, RemoteComposingStatus remoteComposingStatus) : base(webConversation) { m_composingStatus = remoteComposingStatus; }