Пример #1
0
        private void InstantMessagingFlow_MessageReceived(object sender, InstantMessageReceivedEventArgs e)
        {
            //xueming
            InstantMessagingFlow _instantMessagingFlow = sender as InstantMessagingFlow;

            // On an incoming Instant Message, print the contents to the console.
            Console.WriteLine(e.Sender.Uri + " said: " + e.TextBody);

            // Shutdown if the far end tells us to.
            if (e.TextBody.Equals("bye", StringComparison.OrdinalIgnoreCase))
            {
                // Shutting down the platform will terminate all attached objects.
                // If this was a production application, it would tear down the
                // Call/Conversation, rather than terminating the entire platform.
                _instantMessagingFlow.BeginSendInstantMessage("Shutting Down...", SendMessageCompleted,
                                                              _instantMessagingFlow);
                _helper.ShutdownPlatform();
                _OCSCompletedEvent.Set();
            }
            else
            {
                // Echo the instant message back to the far end (the sender of
                // the instant message).
                // Change the composing state of the local end user while sending messages to the far end.
                // A delay is introduced purposely to demonstrate the typing notification displayed by the
                // far end client; otherwise the notification will not last long enough to notice.
                _instantMessagingFlow.LocalComposingState = ComposingState.Composing;
                Thread.Sleep(2000);

                //Echo the message with an "Echo" prefix.
                _instantMessagingFlow.BeginSendInstantMessage("Echo: " + e.TextBody, SendMessageCompleted,
                                                              _instantMessagingFlow);
            }
        }
Пример #2
0
        private void InstantMessagingFlow_StateChanged(object sender, MediaFlowStateChangedEventArgs e)
        {
            Console.WriteLine("Flow state changed from " + e.PreviousState + " to " + e.State);

            // When flow is active, media operations (here, sending an IM)
            // may begin.
            if (e.State == MediaFlowState.Active)
            {
                // Send the message on the InstantMessagingFlow.
                _instantMessagingFlow.BeginSendInstantMessage(_messageToSend, SendMessageCompleted,
                                                              _instantMessagingFlow);
            }
        }
 //Handler for the InstantMessagingFlow.StateChanged event.
 void ImFlow_StateChanged(object sender, MediaFlowStateChangedEventArgs e)
 {
     if (e.State == MediaFlowState.Active)
     {
         ImFlow.BeginSendInstantMessage(messageText, SendMessageCompleted, ImFlow);
     }
 }
        /// <summary>
        /// Overridden process method.
        /// </summary>
        public override void Process()
        {
            bool      exceptionEncountered = true;
            Exception exceptionCaught      = null;

            try
            {
                m_imFlow.BeginSendInstantMessage(m_textBody, this.InstantMessagingSendMessageCompleted, null /*state*/);
                exceptionEncountered = false;
            }
            catch (InvalidOperationException ioe)
            {
                Helper.Logger.Info("Exception = {0}", EventLogger.ToString(ioe));
                exceptionCaught = ioe;
            }
            finally
            {
                if (exceptionEncountered)
                {
                    OperationFault operationFault = null;
                    if (exceptionCaught != null)
                    {
                        operationFault = FaultHelper.CreateClientOperationFault(exceptionCaught.Message, exceptionCaught.InnerException);
                    }
                    else
                    {
                        operationFault = FaultHelper.CreateServerOperationFault(FailureStrings.GenericFailures.UnexpectedException, null /*innerException*/);
                    }

                    this.CompleteSendMessageOperationWithException(new FaultException <OperationFault>(operationFault));
                }
            }
        }
Пример #5
0
        private void instantMessagingFlow2_MessageReceived(object sender, InstantMessageReceivedEventArgs e)
        {
            InstantMessagingFlow instantMessagingFlow = sender as InstantMessagingFlow;

            //On an incoming Instant Message, print the contents to the console.
            Console.WriteLine("In callee's message handler: " + e.Sender.DisplayName + " said: " + e.TextBody);

            //Shutdown the platform
            if (e.TextBody.Equals("bye", StringComparison.OrdinalIgnoreCase))
            {
                _helper.ShutdownPlatform();
                _waitForShutdown.Set();
                return;
            }

            Console.WriteLine("Message received will be echoed");
            _messageToSend = "echo: " + e.TextBody;
            //Send the message on the InstantMessagingFlow.
            if (_IMFlow2 != null && _IMFlow2.State == MediaFlowState.Active)
            {
                _IMFlow2.BeginSendInstantMessage(_messageToSend, EndSendMessage, instantMessagingFlow);
            }
            else
            {
                Console.WriteLine("Could not echo message because flow was either null or inactive");
            }

            _waitForMessage2Received.Set();
        }
Пример #6
0
 /// <summary>
 /// Send status message to customer on the IM channel.
 /// </summary>
 public void SendStatusMessageToCustomer(ContentType contentType, byte[] body)
 {
     try
     {
         InstantMessagingFlow imFlow = this.imCall.Flow;
         imFlow.BeginSendInstantMessage(contentType,
                                        body,
                                        (asyncResult) =>
         {
             try
             {
                 imFlow.EndSendInstantMessage(asyncResult);
             }
             catch (RealTimeException rte)
             {
                 Console.WriteLine("Exception while sending message {0}", rte);
                 this.logger.Log("Exception while sending message {0}", rte);
             }
         },
                                        null);
     }
     catch (InvalidOperationException ioe)
     {
         Console.WriteLine("Exception while sending message {0}", ioe);
         this.logger.Log("Exception while sending message {0}", ioe);
     }
 }
Пример #7
0
        private void instantMessagingFlow_StateChanged(object sender, MediaFlowStateChangedEventArgs e)
        {
            InstantMessagingFlow instantMessagingFlow = sender as InstantMessagingFlow;

            Console.WriteLine("Flow state changed from " + e.PreviousState + " to " + e.State);

            //When flow is active, media operations (here, sending an IM) may begin.
            if (e.State == MediaFlowState.Active)
            {
                _IMFlow = instantMessagingFlow;
                Console.WriteLine("Please type the message to send...");
                string msg = Console.ReadLine();
                //Send the message on the InstantMessagingFlow.
                instantMessagingFlow.BeginSendInstantMessage(msg, EndSendMessage, instantMessagingFlow);
            }
        }
Пример #8
0
        /// <summary>
        /// Im flow message received event handler.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImFlowMessageReceived(object sender, InstantMessageReceivedEventArgs e)
        {
            if (Boolean.Parse(System.Configuration.ConfigurationManager.AppSettings["UseUserEndPoint"]))
            {
                if (this.isUserEndpointFirstMessage)
                {
                    this.isUserEndpointFirstMessage = false;
                    return;
                }
            }

            InstantMessagingFlow imFlow = sender as InstantMessagingFlow;
            string userResponse         = e.TextBody.Trim();

            Console.WriteLine("Received _ :" + userResponse + " from " + e.Sender.Uri);
            MimePartContentDescription package = this.menu.HandleUserInput(userResponse);

            if (package != null)
            {
                try
                {
                    imFlow.BeginSendInstantMessage(package.ContentType,
                                                   package.GetBody(),
                                                   (asyncResult) =>
                    {
                        try
                        {
                            imFlow.EndSendInstantMessage(asyncResult);
                        }
                        catch (RealTimeException rte)
                        {
                            Console.WriteLine("Exception while sending message {0}", rte);
                            this.logger.Log("Exception while sending message {0}", rte);
                        }
                    },
                                                   null);
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine("Exception while sending message {0}", ioe);
                    this.logger.Log("Exception while sending message {0}", ioe);
                }
            }
        }
Пример #9
0
        private void InstantMessagingFlow_StateChanged(object sender, MediaFlowStateChangedEventArgs e)
        {
            Console.WriteLine("Flow state changed from " + e.PreviousState + " to " + e.State);
            // When flow is active, media operations (here, sending an IM)
            // may begin.
            //xueming
            InstantMessagingFlow instantMessagingFlow = sender as InstantMessagingFlow;

            if (e.State == MediaFlowState.Active)
            {
                // Send the message on the InstantMessagingFlow.
                // _instantMessagingFlow.BeginSendInstantMessage(_messageToSend, SendMessageCompleted,
                //    _instantMessagingFlow);
                string str   = _messageToSend.ToString();
                byte[] bytes = Encoding.UTF8.GetBytes(str);
                instantMessagingFlow.BeginSendInstantMessage(new ContentType("text/html"), bytes, SendMessageCompleted,
                                                             instantMessagingFlow);
            }
        }
Пример #10
0
 private void SendIMResponse(InstantMessagingFlow imFlow, string message)
 {
     try
     {
         imFlow.BeginSendInstantMessage(
             message,
             delegate(IAsyncResult ar)
         {
             try
             {
                 imFlow.EndSendInstantMessage(ar);
             }
             catch (RealTimeException)
             {
             }
         },
             null);
     }
     catch (InvalidOperationException)
     {
     }
 }
        private void Run()
        {
            // A helper class to take care of platform and endpoint setup and cleanup.
            _helper = new UCMASampleHelper();

            // Create and establish a user endpoint using the user’s network credentials.
            _userEndpoint = _helper.CreateEstablishedUserEndpoint(
                "FindContact Sample User" /* endpointFriendlyName */);

            // Register a delegate to be called when an incoming InstantMessagingCall arrives.
            _userEndpoint.RegisterForIncomingCall <InstantMessagingCall>(InstantMessagingCall_Received);

            Console.WriteLine("Waiting for an incoming instant messaging call...");
            int ThreadID = Thread.CurrentThread.ManagedThreadId;

            Console.WriteLine("Main thread: ID " + ThreadID);
            // Pause main thread until an incoming call arrives and is accepted.
            _waitUntilIncomingCallIsAccepted.WaitOne();

            InstantMessagingFlow imFlow = _instantMessagingCall.Flow;

            imFlow.BeginSendInstantMessage("Press 1 for Service Department.\n" +
                                           "Press 2 for Sales Department.", CallSendInstantMessageCB, _instantMessagingCall);
            imFlow.MessageReceived += new EventHandler <InstantMessageReceivedEventArgs>(IMFlow_MessageReceived);
            _waitForAvailableTarget.WaitOne();

            if (_remoteContactUri != null)
            {
                imFlow.BeginSendInstantMessage("Contact found: " + _remoteContactUri.ToString(), CallSendInstantMessageCB, _instantMessagingCall);
                // Join the conversation to the IM MCU.
                _conferenceSession = _incomingConversation.ConferenceSession;
                ConferenceJoinOptions confJoinOptions = new ConferenceJoinOptions();
                confJoinOptions.JoinMode = JoinMode.Default;
                _conferenceSession.BeginJoin(confJoinOptions, ConferenceJoinCB, _conferenceSession);

                ThreadID = Thread.CurrentThread.ManagedThreadId;
                Console.WriteLine("Main thread: ID " + ThreadID);
                _waitUntilConferenceInvitationIsDelivered.WaitOne();
            }
            else
            {
                Console.WriteLine("Could not find an available contact.");
                imFlow.BeginSendInstantMessage("Could not find an available contact.\nPlease call again later.", CallSendInstantMessageCB, _instantMessagingCall);
            }
            // Unregister for notification of the MessageReceived event.
            imFlow.MessageReceived -= new EventHandler <InstantMessageReceivedEventArgs>(IMFlow_MessageReceived);
            // Cancel the subscription to the presence session by unsubscribing.
            _userEndpoint.ContactGroupServices.BeginUnsubscribe(ContactGroupUnsubscribeCB, _userEndpoint.ContactGroupServices);
            _remotePresenceView.BeginTerminate(ViewTerminateCB, _remotePresenceView);
            UCMASampleHelper.PauseBeforeContinuing("Press ENTER to shut down and exit.");

            // Terminate the call, the conversation, and then unregister the
            // endpoint from receiving an incoming call. Terminating these
            // additional objects individually is made redundant by shutting down
            // the platform right after, but in the multiple call case, this is
            // needed for object hygiene. Terminating a Conversation terminates
            // all its associated calls, and terminating an endpoint
            // terminates all conversations on that endpoint.
            _instantMessagingCall.BeginTerminate(CallTerminateCB, _instantMessagingCall);
            _waitUntilConversationIsTerminated.WaitOne();
            _userEndpoint.UnregisterForIncomingCall <InstantMessagingCall>(InstantMessagingCall_Received);

            // Clean up by shutting down the platform.
            _helper.ShutdownPlatform();
        }
Пример #12
0
 private void SendMessage(InstantMessagingFlow flow, string message)
 {
     try
     {
         flow.BeginSendInstantMessage(message, ar =>
         {
             try
             {
                 flow.EndSendInstantMessage(ar);
             }
             catch (RealTimeException ex)
             {
                 Console.WriteLine(ex);
             }
         },
         null);
     }
     catch (InvalidOperationException ex)
     {
         Console.WriteLine(ex);
     }
 }