/// <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); } } }
/// <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> /// 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> /// Im flow state changed event handler. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ImFlowStateChanged(object sender, MediaFlowStateChangedEventArgs e) { if (e.State == MediaFlowState.Active) { InstantMessagingFlow imFlow = sender as InstantMessagingFlow; MimePartContentDescription package = null; // Get the top level menu. if (this.menu.Level == MenuLevel.None) { package = this.menu.HandleUserInput(" "); } else { package = this.menu.GetMessage(); } if (package != null) { this.SendStatusMessageToCustomer(package.ContentType, package.GetBody()); } } }
/// <summary> /// Pmethod wraps two versions of the message into a single 'package' /// that will degrade gracefully, providing the plain text version to /// clients that cannot handle the HTML, or will provide the HTML if the client supports it. /// </summary> /// <param name="textToConvert">The text to convert.</param> /// <returns></returns> private static MimePartContentDescription PackageText(string textToConvert) { MimePartContentDescription plainText = null; MimePartContentDescription htmlText = null; MimePartContentDescription package = null; plainText = new MimePartContentDescription( new ContentType("text/plain"), Encoding.UTF8.GetBytes(textToConvert)); htmlText = new MimePartContentDescription( new ContentType("text/html"), Encoding.UTF8.GetBytes(textToConvert)); package = new MimePartContentDescription( new ContentType("multipart/alternative"), null ); package.Add(htmlText); package.Add(plainText); return(package); }