Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new conversation with given subject and id.
        /// </summary>
        /// <param name="conversation">Ucma conversation.</param>
        /// <param name="conversationCallback">Conversation callback.</param>
        /// <param name="conversationContext">Conversation context.</param>
        /// <param name="channel">Context channel.</param>
        internal WebConversation(Conversation conversation, IConversationCallback conversationCallback, IDictionary <string, string> conversationContext, IContextChannel channel)
        {
            if (conversation == null)
            {
                throw new ArgumentException("Ucma conversation cannot be null", "conversation");
            }

            this.Id                = conversation.Id;
            this.Subject           = conversation.Subject;
            m_conversation         = conversation;
            m_conversationCallback = conversationCallback;
            if (conversationContext != null)
            {
                m_conversationContext = new Dictionary <string, string>(conversationContext);
            }
            m_channel          = channel;
            m_channel.Faulted += this.ChannelClosed;
            m_channel.Closed  += this.ChannelClosed;
        }
Ejemplo n.º 3
0
        /// <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)
                        {
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <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);
        }