Пример #1
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);
     }
 }
Пример #2
0
        private void SendMessageCompleted(IAsyncResult result)
        {
            InstantMessagingFlow instantMessagingFlow = result.AsyncState as InstantMessagingFlow;
            Exception            ex = null;

            try
            {
                instantMessagingFlow.EndSendInstantMessage(result);
                _sendCount += 1;
                _helper.log("The message has been sent.");
            }
            catch (OperationTimeoutException opTimeEx)
            {
                // OperationFailureException: Indicates failure to connect the
                // IM to the remote party due to timeout (called party failed to
                // respond within the expected time).
                // TODO (Left to the reader): Write real error handling code.
                ex = opTimeEx;
            }
            catch (RealTimeException rte)
            {
                // Other errors may cause other RealTimeExceptions to be thrown.
                // TODO (Left to the reader): Write real error handling code.
                ex = rte;
            }
            finally
            {
                // Reset the composing state of the local end user so that the typing notifcation as seen
                // by the far end client disappears.
                //_instantMessagingFlow.LocalComposingState = ComposingState.Idle;
                instantMessagingFlow.LocalComposingState = ComposingState.Idle;
                if (ex != null)
                {
                    // If the action threw an exception, terminate the sample,
                    // and print the exception to the console.
                    // TODO (Left to the reader): Write real error handling code.
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine("Shutting down platform due to error");
                    _helper.ShutdownPlatform();
                }

                //xueming
                if (_sendCount >= _sentTotal)
                {
                    _helper.log("Shutting down platform after send all Message!");
                    _OCSCompletedEvent.Set();
                    _helper.ShutdownPlatform();
                }
            }
        }
Пример #3
0
        private void EndSendMessage(IAsyncResult ar)
        {
            InstantMessagingFlow instantMessagingFlow = ar.AsyncState as InstantMessagingFlow;

            try
            {
                instantMessagingFlow.EndSendInstantMessage(ar);
                Console.WriteLine("The message has been sent.");
            }
            catch (OperationTimeoutException opTimeEx)
            {
                // OperationFailureException: Indicates failure to connect the
                // IM to the remote party due to timeout (called party failed
                // to respond within the expected time).
                // TODO (Left to the reader): Add error handling code
                Console.WriteLine(opTimeEx.ToString());
            }
        }
Пример #4
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);
                }
            }
        }
Пример #5
0
 private void SendIMResponse(InstantMessagingFlow imFlow, string message)
 {
     try
     {
         imFlow.BeginSendInstantMessage(
             message,
             delegate(IAsyncResult ar)
         {
             try
             {
                 imFlow.EndSendInstantMessage(ar);
             }
             catch (RealTimeException)
             {
             }
         },
             null);
     }
     catch (InvalidOperationException)
     {
     }
 }
        /// <summary>
        /// Im call establish completed callback method.
        /// </summary>
        /// <param name="asyncResult">Async result.</param>
        private void InstantMessagingSendMessageCompleted(IAsyncResult asyncResult)
        {
            Exception exceptionCaught      = null;
            bool      exceptionEncountered = true;

            try
            {
                m_imFlow.EndSendInstantMessage(asyncResult);
                exceptionEncountered = false;
            }
            catch (RealTimeException rte)
            {
                Helper.Logger.Info("Exception = {0}", EventLogger.ToString(rte));
                exceptionCaught = rte;
            }
            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));
                }
                else
                {
                    SendInstantMessageResponse response = new SendInstantMessageResponse(m_sendImMessageRequest);
                    this.CompleteSendMessageOperationSuccessfully(response);
                }
            }
        }
Пример #7
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);
     }
 }
 //Callback method for the InstantMessagingFlow.BeginSendInstantMessage method.
 private void SendMessageCompleted(IAsyncResult res)
 {
     ImFlow.EndSendInstantMessage(res);
 }