/// <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> /// 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> /// Constructor to create the poller. /// </summary> internal WebConversationPoller(WebConversationManager webConversationManager, TimerWheel timerWheel) { m_conversationManager = webConversationManager; m_timerWheel = timerWheel; }