Exemplo n.º 1
0
        /// <summary>
        /// Get activities of dialog.
        /// </summary>
        /// <returns></returns>
        public override IEnumerator <Task> GetActivities()
        {
            Task <ActivityResult> outboundCall = this.CreateOutboundImCall();

            yield return(outboundCall);

            this.imCall = outboundCall.Result.Output["Result"] as InstantMessagingCall;
            Task <ActivityResult> imQa = this.CreateImQaActivity();

            yield return(imQa.ContinueWith((task) =>
            {
                if (task.Exception != null)
                {
                    base.Exception = task.Exception;
                    Task <ActivityResult> disc = this.CreateDisconnectImCallActivity();
                }
                else
                {
                    this.result = imQa.Result.Output["Result"] as string;
                }
            }));


            Task <ActivityResult> code = this.CreateCodeActivity();

            yield return(code);
        }
Exemplo n.º 2
0
        void On_InstantMessagingCall_Received(object sender, CallReceivedEventArgs <InstantMessagingCall> e)
        {
            //Type checking was done by the platform; no risk of this being any
            // type other than the type expected.
            _instantMessagingCall = e.Call;

            // Call: StateChanged: Only hooked up for logging, to show the call
            // state transitions.
            _instantMessagingCall.StateChanged += new
                                                  EventHandler <CallStateChangedEventArgs>(_instantMessagingCall_StateChanged);

            // Remote Participant URI represents the far end (caller) in this
            // conversation. Toast is the message set by the caller as the 'greet'
            // message for this call. In Microsoft Lync, the toast will
            // show up in the lower-right of the screen.
            Console.WriteLine("Call Received! From: " + e.RemoteParticipant.Uri + " Toast is: " +
                              e.ToastMessage.Message);

            // Now, decline the call. CallDeclineOptions can be used to supply a
            // response code, here, 486 (Busy Here). Decline is asynchronous, as
            // no reply will be received from the far end.
            _instantMessagingCall.Decline(new CallDeclineOptions(486));

            _autoResetEvent.Set();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initialize Parameters required for the acttivity.
 /// </summary>
 /// <param name="parameters"></param>
 public override void InitializeParameters(Dictionary <string, object> parameters)
 {
     if (parameters.ContainsKey("Call"))
     {
         this.InstantMessagingCall = parameters["Call"] as InstantMessagingCall;
     }
 }
Exemplo n.º 4
0
        void IMCall_EstablishCompleted(IAsyncResult result)
        {
            try
            {
                InstantMessagingCall imCall = result.AsyncState as InstantMessagingCall;
                imCall.EndEstablish(result);

                Message m = new Message("InstantMessagingCall Established. Call state: " + _instantMessagingCall.State.ToString() + ". CallId: " + _instantMessagingCall.CallId + ".",
                                        _instantMessagingCall.RemoteEndpoint.Participant.DisplayName, _instantMessagingCall.RemoteEndpoint.Participant.UserAtHost,
                                        _instantMessagingCall.RemoteEndpoint.Participant.Uri,
                                        MessageType.InstantMessage, _transcriptRecorder.Conversation.Id, MessageDirection.Incoming);
                _transcriptRecorder.OnMessageReceived(m);

                _transcriptRecorder.OnRemoteParticipantAdded(null, imCall.RemoteEndpoint);
            }
            catch (RealTimeException ex)
            {
                NonBlockingConsole.WriteLine("Error: imCall.EndEstablish failed. Exception: {0}", ex.ToString());
                // TODO: error message
            }
            finally
            {
                _state = TranscriptRecorderState.Active;
                this._waitForIMCallEstablished.Set();
            }
        }
        private void EstablishCall()
        {
            // Create a new Conversation.
            Conversation conversation = new Conversation(_appEndpoint);

            // Create a new IM call.
            _imCall = new InstantMessagingCall(conversation);

            try
            {
                // Establish the IM call.
                _imCall.BeginEstablish(_destinationSipUri,
                    new CallEstablishOptions(),
                    result =>
                    {
                        try
                        {
                            // Finish the asynchronous operation.
                            _imCall.EndEstablish(result);
                        }
                        catch (RealTimeException ex)
                        {
                            // Catch and log exceptions.
                            _logger.Log("Failed establishing IM call", ex);
                        }
                    },
                    null
                );
            }
            catch (InvalidOperationException ioex)
            {
                _logger.Log("Failed establishing IM call", ioex);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Web im call.
 /// </summary>
 /// <param name="conversation">Web conversation to which this call belongs to.</param>
 internal WebImCall(InstantMessagingCall imCall, WebConversation conversation)
 {
     Debug.Assert(null != imCall, "imCall is null");
     Debug.Assert(null != conversation, "conversation is null");
     m_imCall             = imCall;
     this.WebConversation = conversation;
 }
Exemplo n.º 7
0
        private void InstantMessagingCallAcceptedCallBack(IAsyncResult ar)
        {
            InstantMessagingCall instantMessagingCall = ar.AsyncState as InstantMessagingCall;

            try
            {
                // Determine whether the call was accepted successfully.
                instantMessagingCall.EndAccept(ar);

                Message m = new Message("InstantMessagingCall Accepted. Call state: " + instantMessagingCall.State.ToString() + ". CallId: " + instantMessagingCall.CallId + ".",
                                        instantMessagingCall.RemoteEndpoint.Participant.DisplayName, instantMessagingCall.RemoteEndpoint.Participant.UserAtHost,
                                        instantMessagingCall.RemoteEndpoint.Participant.Uri,
                                        MessageType.InstantMessage, _transcriptRecorder.Conversation.Id, MessageDirection.Incoming);
                _transcriptRecorder.OnMessageReceived(m);

                _transcriptRecorder.OnRemoteParticipantAdded(null, instantMessagingCall.RemoteEndpoint);
            }
            catch (RealTimeException exception)
            {
                // RealTimeException may be thrown on media or link-layer failures.
                // A production application should catch additional exceptions, such as OperationTimeoutException,
                // OperationTimeoutException, and CallOperationTimeoutException.

                NonBlockingConsole.WriteLine(exception.ToString());
            }
            finally
            {
                // Synchronize with main thread.
                _waitForIMCallAccepted.Set();
                _state = TranscriptRecorderState.Active;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Commit Agent Dialog Complete Handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void AgentHuntCompleteHandler(object sender, DialogCompletedEventArgs e)
        {
            Dictionary <string, object> output = e.Output;
            TryCommitAgentAsyncResult   ar;
            bool agentApproval          = output.ContainsKey("QaAgentOfferApproval") ? Convert.ToBoolean(output["QaAgentOfferApproval"]) : false;
            InstantMessagingCall imCall = output.ContainsKey("Call") ? output["Call"] as InstantMessagingCall : null;

            _dictionaryOfTryCommitAsyncResults.TryGetValue((Guid)output["InstanceId"], out ar);
            _dictionaryOfTryCommitAsyncResults.Remove((Guid)output["InstanceId"]);

            if (ar == null)
            {
                Debug.Assert(false, "failed to get TryCommitAgentAsyncResult");
            }

            if (agentApproval)
            {
                ar.SetAsCompleted(imCall, false);
            }

            else
            {
                if (null != imCall)
                {
                    imCall.BeginTerminate(ter => { imCall.EndTerminate(ter); }, null);
                    ar.SetAsCompleted(null, false);
                }
                else
                {
                    ar.SetAsCompleted(new OperationFailureException("AcdAgentHunter: DialogTerminated is getting hit"), false);
                }
            }
        }
Exemplo n.º 9
0
 public static Task <CallMessageData> EstablishAsync(this InstantMessagingCall call,
                                                     string destinationUri, ToastMessage toastMessage, CallEstablishOptions options)
 {
     return(Task <CallMessageData> .Factory.FromAsync(
                call.BeginEstablish, call.EndEstablish,
                destinationUri, toastMessage, options, null));
 }
Exemplo n.º 10
0
        void On_InstantMessagingCall_Received_ByCallee(object sender, CallReceivedEventArgs <InstantMessagingCall> e)
        {
            //Type checking was done by the platform; no risk of this being any
            // type other than the type expected.
            InstantMessagingCall instantMessagingCall = e.Call;

            // Call: StateChanged: Only hooked up for logging, to show the call
            // state transitions.
            instantMessagingCall.StateChanged += new EventHandler <CallStateChangedEventArgs>(_call_StateChanged);

            // Remote Participant URI represents the far end (caller) in this
            // conversation. Toast is the message set by the caller as the 'greet'
            // message for this call. In Microsoft Lync, the toast will
            // show up in the lower-right of the screen. Conversation ID demonstrates
            // that the two calls inhabit the same conversation container on
            // both ends of the call.
            Console.WriteLine("");
            Console.WriteLine(" Call Received! From: " + e.RemoteParticipant.Uri);
            Console.WriteLine(" Toast is: " + e.ToastMessage.Message);
            Console.WriteLine(" Conversation ID is: " + e.Call.Conversation.Id);
            Console.WriteLine("");

            // Now, accept the call.
            // EndAcceptCall will be raised on the same thread.
            instantMessagingCall.BeginAccept(EndAcceptCall, instantMessagingCall);

            // When an escalation request is received on the existing call, this
            // event handler will be called.
            instantMessagingCall.Conversation.EscalateToConferenceRequested +=
                this.CalleeConversation_EscalateToConferenceRequested;
        }
Exemplo n.º 11
0
 public void Start(string initialMessage, InstantMessagingCall call)
 {
     this._initialMessage = initialMessage;
     this._call = call;
     call.InstantMessagingFlowConfigurationRequested += Call_InstantMessagingFlowConfigurationRequested;
     call.AcceptAsync();
 }
        private void OnIncomingInstantMessagingCallReceived(object sender, CallReceivedEventArgs<InstantMessagingCall> e)
        {
            _imCall = e.Call;

            try
            {
                // Accept the incoming call.
                _imCall.BeginAccept(ar =>
                {
                    try
                    {
                        _imCall.EndAccept(ar);

                        _logger.Log("Accepted incoming call.");
                    }
                    catch (RealTimeException rtex)
                    {
                        _logger.Log("Failed accepting incoming IM call.", rtex);
                    }
                },
                null);
            }
            catch (InvalidOperationException ioex)
            {
                _logger.Log("Failed accepting incoming IM call.", ioex);
            }
        }
        //Launches an instant message. Text of the message depends on the parameter value.
        public void UcmaIM(Int32 choice)
        {
            helper       = new UCMASampleHelper();
            userEndpoint = helper.CreateEstablishedUserEndpoint("SampleUser");
            Console.WriteLine("endpoint owned by " + userEndpoint.OwnerUri + " is established/registered");

            ConversationSettings conversationSettings = new ConversationSettings();

            conversationSettings.Subject = conversationSubject;
            Conversation conversation = new Conversation(userEndpoint, conversationSettings);

            ImCall = new InstantMessagingCall(conversation);
            ImCall.InstantMessagingFlowConfigurationRequested += new EventHandler <InstantMessagingFlowConfigurationRequestedEventArgs>(ImCall_InstantMessagingFlowConfigurationRequested);

            Int32 helloChoice   = 1;
            Int32 goodbyeChoice = 2;

            if (choice == helloChoice)
            {
                messageText = "hello";
            }
            else if (choice == goodbyeChoice)
            {
                messageText = "goodbye";
            }
            else
            {
                messageText = "press 1 or press 2";
            }

            string targetURI = ConfigurationManager.AppSettings["UserURI1"];

            ImCall.BeginEstablish(targetURI, null, CallEstablishCompleted, null);
            completedEvent.WaitOne();
        }
        /// <summary>
        /// Terminate Im call.
        /// </summary>
        private void TerminateInstantMessagingCall()
        {
            bool exceptionEncountered = true;

            try
            {
                InstantMessagingCall imCall    = null;
                WebImCall            webImCall = m_webConversation.WebImCall;
                if (webImCall != null)
                {
                    imCall = webImCall.ImCall;
                }
                if (imCall != null)
                {
                    imCall.BeginTerminate(this.InstantMessagingCallTerminated, imCall);
                }
                else
                {
                    //Go to next step of terminating av call.
                    this.TerminateAudioVideoCall();
                }

                exceptionEncountered = false;
            }
            finally
            {
                if (exceptionEncountered)
                {
                    OperationFault operationFault = FaultHelper.CreateServerOperationFault(FailureStrings.GenericFailures.UnexpectedException, null /*innerException*/);
                    this.CompleteTerminateConversationOperationWithException(new FaultException <OperationFault>(operationFault));
                }
            }
        }
Exemplo n.º 15
0
            internal void Process()
            {
                InstantMessagingCall imCall = _supervisorSession._initialSupervisorCall;

                if (null != _supervisorSession._tmrItem)
                {
                    _supervisorSession._tmrItem.Stop();
                }

                if (null != imCall)
                {
                    if (null != imCall.Flow)
                    {
                        try
                        {
                            imCall.Flow.BeginSendInstantMessage(_supervisorSession._matchMaker.Configuration.FinalMessageToSupervisor,
                                                                smar =>
                            {
                                try
                                {
                                    imCall.Flow.EndSendInstantMessage(smar);
                                }
                                catch (RealTimeException)
                                {
                                    // TODO: _logger.Log("Failed to send final message to supervisor.");
                                }
                            },
                                                                null);
                        }
                        catch (InvalidOperationException)
                        {
                            // TODO: _logger.Log("Unable to send final message to supervisor, because the call flow terminated.");
                        }
                    }
                }

                _supervisorSession._frontEndConversation.BeginTerminate(ter =>
                {
                    _supervisorSession._frontEndConversation.EndTerminate(ter);
                    if (_supervisorSession._monitoringSession != null)
                    {
                        _supervisorSession._monitoringSession.BeginShutDown(sd =>
                        {
                            _supervisorSession._monitoringSession.EndShutDown(sd);

                            _supervisorSession.UpdateState(SupervisorSessionState.Terminated);

                            this.SetAsCompleted(null, false);

                            _supervisorSession._listOfShutDownAsyncResults.ForEach(sdar =>
                            {
                                sdar.SetAsCompleted(null, true);
                            });
                        },
                                                                            null);
                    }
                },
                                                                        null);
            } // Process()
Exemplo n.º 16
0
 /// <summary>
 /// Overrides an abstract method to intialize parameters.
 /// </summary>
 /// <param name="inputParameters"></param>
 public override void InitializeParameters(Dictionary <string, object> inputParameters)
 {
     this.WelcomeMessage   = inputParameters["WelcomeMessage"] as string;
     this.PortalSkills     = inputParameters["PortalSkills"] as List <string>;
     this.MatchMakerSkills = inputParameters["MatchMakerSkills"] as List <Skill>;
     this.PleaseHoldPrompt = inputParameters["PleaseHoldPrompt"] as string;
     this.ImCall           = inputParameters["Call"] as InstantMessagingCall;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Initialize a new instance of SkillGatheringInstantMessagingDialog.
 /// </summary>
 /// <param name="inputParameters"></param>
 public SkillGatheringInstantMessagingDialog(Dictionary <string, object> inputParameters)
     : this()
 {
     this.WelcomeMessage   = inputParameters["WelcomeMessage"] as string;
     this.PortalSkills     = inputParameters["PortalSkills"] as List <string>;
     this.MatchMakerSkills = inputParameters["MatchMakerSkills"] as List <Skill>;
     this.PleaseHoldPrompt = inputParameters["PleaseHoldPrompt"] as string;
     this.ImCall           = inputParameters["Call"] as InstantMessagingCall;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Im call state changed event handler.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImCallStateChanged(object sender, CallStateChangedEventArgs e)
        {
            InstantMessagingCall imCall = sender as InstantMessagingCall;

            if (e.State == CallState.Terminated)
            {
                this.UnregisterIMcallEventHandlers(imCall);
            }
        }
Exemplo n.º 19
0
        private void Run()
        {
            // A helper class to take care of platform and endpoint setup and
            // cleanup. This has been abstracted from this sample to focus on
            // Call Control.
            _helper = new UCMASampleHelper();

            // Create a user endpoint, using the network credential object
            // defined above.
            UserEndpoint callerEndpoint = _helper.CreateEstablishedUserEndpoint(
                "Caller" /*endpointFriendlyName*/);

            // Create a second user endpoint, using the network credential object
            // defined above.
            UserEndpoint calleeEndpoint = _helper.CreateEstablishedUserEndpoint(
                "Callee" /*endpointFriendlyName*/);

            // Here, we are accepting an Instant Messaging call only. If the
            // incoming call is not an Instant Messaging call (for example, an
            // AudioVideo call or a custom Call, then it will not get raised to
            // the application. UCMA 3.0 handles this silently by having the call
            // types register for various modalities (as part of the extensibility
            // framework). The appropriate action (here, accepting the call) will
            // be handled in the handler assigned to the method call below.
            calleeEndpoint.RegisterForIncomingCall <InstantMessagingCall>(On_InstantMessagingCall_Received);

            // Setup the call and conversation objects for the initial call (IM)
            // and place the call (synchronously).
            _conversation = new Conversation(callerEndpoint);
            InstantMessagingCall instantMessagingCall = new InstantMessagingCall(_conversation);


            // Add registration for the AudioVideo modality, before placing the
            // second call. This could have been done at any time before placing
            // the audio video call. This handler could choose to accept, deflect
            // or drop this portion of the call entirely.
            calleeEndpoint.RegisterForIncomingCall <AudioVideoCall>(On_AudioVideoCall_Received);

            // Place the call to the remote party, without specifying any custom
            // options.
            instantMessagingCall.BeginEstablish(calleeEndpoint.OwnerUri, new ToastMessage("Sample Toast Message"),
                                                null, CallEstablishCompleted, instantMessagingCall);

            // Force synchronization to ensure that the both AVCall and IMCall
            // are now complete.
            _sampleCompleted.WaitOne();

            UCMASampleHelper.PauseBeforeContinuing("Press ENTER to shutdown and exit.");

            //And shutdown (synchronously).
            Console.WriteLine("Shutting down the sample...");
            _helper.ShutdownPlatform();
        }
Exemplo n.º 20
0
        public void InstantMessagingCall_Received(CallReceivedEventArgs <InstantMessagingCall> e)
        {
            if (_state == TranscriptRecorderState.Terminated)
            {
                NonBlockingConsole.WriteLine("Error: IMTranscriptRecorder is shutdown.");
                // TODO: Info message
                return;
            }

            if (_instantMessagingCall != null)
            {
                NonBlockingConsole.WriteLine("Warn: IMCall already exists for this Conversation. Shutting down previous call...");
                // TODO: Info message
                TerminateCall();
            }

            _state = TranscriptRecorderState.Initialized;
            _waitForIMCallTerminated.Reset();

            // Type checking was done by the platform; no risk of this being any
            // type other than the type expected.
            _instantMessagingCall = e.Call;

            // Call: StateChanged: Only hooked up for logging, to show the call
            // state transitions.
            _instantMessagingCall.StateChanged +=
                new EventHandler <CallStateChangedEventArgs>(InstantMessagingCall_StateChanged);

            _instantMessagingCall.InstantMessagingFlowConfigurationRequested +=
                new EventHandler <InstantMessagingFlowConfigurationRequestedEventArgs>(InstantMessagingCall_FlowConfigurationRequested);

            _instantMessagingCall.ConversationChanged += new EventHandler <ConversationChangedEventArgs>(InstantMessagingCall_ConversationChanged);

            // Remote Participant URI represents the far end (caller) in this
            // conversation. Toast is the message set by the caller as the
            // 'greet' message for this call. In Microsoft Lync, the
            // toast will show up in the lower-right of the screen.
            // TODO: Change to protect privacy
            // NonBlockingConsole.WriteLine("IMCall Received! From: " + e.RemoteParticipant.Uri + " Toast is: " + e.ToastMessage.Message);
            NonBlockingConsole.WriteLine("IMCall Received! From: " + e.RemoteParticipant.Uri);
            // Console.Writelin("IMCall Received!");

            Message m = new Message("InstantMessagingCall Received. Inbound call state: " + _instantMessagingCall.State.ToString(),
                                    e.RemoteParticipant.DisplayName, e.RemoteParticipant.UserAtHost, e.RemoteParticipant.Uri,
                                    MessageType.InstantMessage, _transcriptRecorder.Conversation.Id, MessageDirection.Incoming);

            _transcriptRecorder.OnMessageReceived(m);

            // Now, accept the call. EndAcceptCall will be raised on the
            // same thread.
            _instantMessagingCall.BeginAccept(InstantMessagingCallAcceptedCallBack, _instantMessagingCall);
        }
Exemplo n.º 21
0
 public async Task Init(Conversation conversation)
 {
     try
     {
         _call = new InstantMessagingCall(conversation);
         _call.InstantMessagingFlowConfigurationRequested += _call_InstantMessagingFlowConfigurationRequested;
         await _call.EstablishAsync();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error on init: " + ex.ToString());
     }
 }
Exemplo n.º 22
0
        private void EndTerminateCall(IAsyncResult ar)
        {
            InstantMessagingCall instantMessagingCall = ar.AsyncState as InstantMessagingCall;

            // End terminating the incoming call.
            instantMessagingCall.EndTerminate(ar);

            // Remove this event handler now that the call has been terminated.
            _instantMessagingCall.StateChanged -= InstantMessagingCall_StateChanged;

            //Again, just to sync the completion of the code.
            _autoResetEvent.Set();
        }
        // Callback method referred to in the call to BeginTerminate on the InstantMessagingCall instance.
        private void CallTerminateCB(IAsyncResult ar)
        {
            InstantMessagingCall instantMessagingCall = ar.AsyncState as InstantMessagingCall;

            // Finish the termination of the incoming call.
            instantMessagingCall.EndTerminate(ar);

            // The call has been terminated, so remove the handler for the StateChanged event.
            _instantMessagingCall.StateChanged -= InstantMessagingCall_StateChanged;

            // Terminate the conversation.
            _instantMessagingCall.Conversation.BeginTerminate(ConversationTerminateCB,
                                                              _instantMessagingCall.Conversation);
        }
Exemplo n.º 24
0
        public PSRunner(InstantMessagingCall call, string toast)
        {
            try
            {
                _call = call;
                _user = call.RemoteEndpoint.Participant.Uri;
                _commandString = toast;

            }
            catch (Exception ex)
            {
               log.ErrorFormat("Error instantiating PowerShell Runner: {0}",ex);
            }
        }
Exemplo n.º 25
0
        public ZMachineSession(InstantMessagingCall call) {

            _state = ZMachineSessionState.InitialMessage;
            _call = call;
            Log.Debug("CallID: " + call.CallId);

            _call.StateChanged += CallOnStateChanged;
            _call.Flow.MessageReceived += FlowOnMessageReceived;
            try {
                _gameChoices = Directory.GetFiles(Path.Combine(ZMachineSettings.AppDataFolder,"Games"), "*");
            } catch (Exception ex) {
                Log.Error("Exception in " + ex.TargetSite.Name, ex);
                _gameChoices = new string[0];
            }

        }
        // Callback method referred to in the call to BeginSendInstantMessage on the InstantMessagingFlow instance.
        private void CallSendInstantMessageCB(IAsyncResult ar)
        {
            InstantMessagingCall imCall = ar.AsyncState as InstantMessagingCall;

            try
            {
                imCall.Flow.EndSendInstantMessage(ar);
            }
            // A production application should have catch blocks for a number of
            // other exceptions, including FailureResponseException, ServerPolicyException,
            // and OperationTimeoutException.
            catch (RealTimeException exception)
            {
                Console.WriteLine(exception.ToString());
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// To create a new IM IVR.
 /// </summary>
 /// <param name="customerSession">Customer session.</param>
 /// <param name="imCall">Im call.</param>
 /// <param name="menu">Menu to use.</param>
 /// <param name="conversationContextChannel">Conversation context channel.</param>
 /// <param name="logger">Logger.</param>
 public InstantMessagingIVR(CustomerSession customerSession,
                            InstantMessagingCall imCall,
                            ConversationContextChannel conversationContextChannel,
                            Menu menu,
                            ILogger logger)
 {
     this.customerSession = customerSession;
     this.logger          = logger;
     this.imCall          = imCall;
     this.RegisterIMcallEventHandlers(imCall);
     this.menu = menu;
     if (conversationContextChannel != null)
     {
         this.channel = conversationContextChannel;
         this.RegisterContextChannelHandlers(this.channel);
     }
 }
Exemplo n.º 28
0
        private async Task SendIM(List <string> messages, string toastMessage, string destinationSip)
        {
            Conversation         conversation = new Conversation(_endpoint);
            InstantMessagingCall call         = new InstantMessagingCall(conversation);

            ToastMessage         toast   = new ToastMessage(toastMessage);
            CallEstablishOptions options = new CallEstablishOptions();

            await call.EstablishAsync(destinationSip, toast, options);

            foreach (var msg in messages)
            {
                await call.Flow.SendInstantMessageAsync(msg);
            }
            await conversation.TerminateAsync();

            Console.WriteLine("IM Sent");
        }
Exemplo n.º 29
0
        /// <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;
        }
Exemplo n.º 30
0
        internal void HandleSupervisorInitialCall(InstantMessagingCall imCall)
        {
            Debug.Assert(imCall is InstantMessagingCall);
            _logger.Log("AcdSupervisorSession receives first incoming Call from " + imCall.RemoteEndpoint.Participant.Uri);

            if (_state == SupervisorSessionState.Incoming)
            {
                // sets the initial customer call
                _initialSupervisorCall = imCall;

                // monitors the customer-facing conversation state
                this.SetFrontEndConversationProperties(imCall);

                try
                {
                    imCall.BeginAccept(ar =>
                    {
                        try
                        {
                            imCall.EndAccept(ar);

                            this.InitializeSupervisorControlChannel();
                        }
                        catch (RealTimeException rtex)
                        {
                            _logger.Log("AcdSupervisorSession failed to end accept the incoming call from Supervisor", rtex);
                            this.BeginShutDown(sdar => { this.EndShutDown(sdar); }, null);
                        }
                    },
                                       null);
                }
                catch (InvalidOperationException ivoex)
                {
                    _logger.Log("AcdSupervisorSession failed to accept the incoming call from Supervisor", ivoex);
                    this.BeginShutDown(sdar => { this.EndShutDown(sdar); }, null);
                }
            }
            else
            {
                _logger.Log("AcdSupervisorSession is not in the correct state to process the new initial call");
                this.BeginShutDown(ar => { this.EndShutDown(ar); }, null);
            }
        }
Exemplo n.º 31
0
        public void EstablishInstantMessagingCall(Conversation conversation)
        {
            if (_state == TranscriptRecorderState.Terminated)
            {
                NonBlockingConsole.WriteLine("Error: IMTranscriptRecorder is shutdown.");
                // TODO: error message
                return;
            }

            if (_instantMessagingCall != null)
            {
                NonBlockingConsole.WriteLine("Warn: IMCall already exists for this Conversation. Shutting down previous call...");
                // TODO: Info message
                TerminateCall();
            }

            _state = TranscriptRecorderState.Initialized;
            this._waitForIMCallTerminated.Reset();

            try
            {
                InstantMessagingCall imCall = new InstantMessagingCall(conversation);

                // Register for Call events
                _instantMessagingCall = imCall;

                // Call: StateChanged: Only hooked up for logging, to show the call
                // state transitions.
                _instantMessagingCall.StateChanged +=
                    new EventHandler <CallStateChangedEventArgs>(InstantMessagingCall_StateChanged);

                _instantMessagingCall.InstantMessagingFlowConfigurationRequested +=
                    new EventHandler <InstantMessagingFlowConfigurationRequestedEventArgs>(InstantMessagingCall_FlowConfigurationRequested);

                // Establish AudioVideoCall
                imCall.BeginEstablish(IMCall_EstablishCompleted, imCall);
            }
            catch (InvalidOperationException ex)
            {
                NonBlockingConsole.WriteLine("Error: imCall.BeginEstablish failed. Exception: {0}", ex.ToString());
                // TODO: Error Message
            }
        }
        void InstantMessagingCall_Received(object sender, CallReceivedEventArgs <InstantMessagingCall> e)
        {
            // Type checking was done by the platform; no risk of this being any
            // type other than the type expected.
            _instantMessagingCall = e.Call;
            _incomingConversation = _instantMessagingCall.Conversation;

            // Call: StateChanged: Hooked up for logging, to show callstate transitions.
            _instantMessagingCall.StateChanged +=
                new EventHandler <CallStateChangedEventArgs>(InstantMessagingCall_StateChanged);

            // RemoteParticipantUri is the URI of the remote caller in this
            // conversation. Toast is the message set by the caller as the
            // 'greet' message for this call.
            Console.WriteLine("Call Received! From: " + e.RemoteParticipant.Uri + " Toast is: " +
                              e.ToastMessage.Message);

            // Accept the call.
            _instantMessagingCall.BeginAccept(CallAcceptCB, _instantMessagingCall);
        }
        // Callback method referred to in the call to BeginAccept on the InstantMessagingCall instance.
        private void CallAcceptCB(IAsyncResult ar)
        {
            InstantMessagingCall instantMessagingCall = ar.AsyncState as InstantMessagingCall;

            try
            {
                // Determine whether the IM Call was accepted successfully.
                instantMessagingCall.EndAccept(ar);
            }
            catch (RealTimeException exception)
            {
                // RealTimeException can be thrown on media or link-layer failures.
                Console.WriteLine(exception.ToString());
            }
            finally
            {
                // Synchronize with main thread.
                _waitUntilIncomingCallIsAccepted.Set();
            }
        }
Exemplo n.º 34
0
        internal void HandleIncomingCall()
        {
            Console.WriteLine("Handling incoming IM call.");
            // Create a new conversation for the back-end leg of the B2B call (which will connect to the conference).
            LocalEndpoint localEndpoint = _frontEndCallLeg.Conversation.Endpoint;
            Conversation backEndConversation = new Conversation(localEndpoint);

            // Impersonate the caller so that the caller, rather than the application, will appear to be participating in the conference
            string callerSipUri = _frontEndCallLeg.RemoteEndpoint.Participant.Uri;
            backEndConversation.Impersonate(callerSipUri, null, null);

            Console.WriteLine("Caller SIP Uri: " + callerSipUri);

            try
            {
                // Join the conference
                backEndConversation.ConferenceSession.BeginJoin(
                    default(ConferenceJoinOptions),
                    joinAsyncResult =>
                    {
                        try
                        {
                            backEndConversation.ConferenceSession.EndJoin(joinAsyncResult);
                            Console.WriteLine("Joined conference.");

                            _backEndCallLeg = new InstantMessagingCall(backEndConversation);

                            CreateBackToBack();
                        }
                        catch (RealTimeException ex)
                        {
                            Console.WriteLine(ex);
                        }
                    },
                null);
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex);
            }
        }
        private void EstablishCall()
        {
            // Create a new Conversation.
            Conversation conversation = new Conversation(_appEndpoint);

            // Create a new IM call.
            _imCall = new InstantMessagingCall(conversation);

            try
            {
                // Establish the IM call.
                _imCall.BeginEstablish(_destinationSipUri,
                    new CallEstablishOptions(),
                    result =>
                    {
                        try
                        {
                            // Finish the asynchronous operation.
                            _imCall.EndEstablish(result);

                            _imCall.Flow.MessageReceived += 
                                new EventHandler<InstantMessageReceivedEventArgs>(OnMessageReceived);

                            SendMessage("Jackdaws love my big sphinx of quartz.");
                        }
                        catch (RealTimeException ex)
                        {
                            // Catch and log exceptions.
                            _logger.Log("Failed establishing IM call", ex);
                        }
                    },
                    null
                );
            }
            catch (InvalidOperationException ioex)
            {
                _logger.Log("Failed establishing IM call", ioex);
            }
        }
Exemplo n.º 36
0
        void On_InstantMessagingCall_Received(object sender, CallReceivedEventArgs <InstantMessagingCall> e)
        {
            // Type checking was done by the platform; no risk of this being any
            // type other than the type expected.
            _instantMessagingCall = e.Call;

            // Call: StateChanged: Only hooked up for logging, to show the call
            // state transitions.
            _instantMessagingCall.StateChanged +=
                new EventHandler <CallStateChangedEventArgs>(InstantMessagingCall_StateChanged);

            // Remote Participant URI represents the far end (caller) in this
            // conversation. Toast is the message set by the caller as the
            // 'greet' message for this call. In Microsoft Lync, the
            // toast will show up in the lower-right of the screen.
            Console.WriteLine("Call Received! From: " + e.RemoteParticipant.Uri + " Toast is: " +
                              e.ToastMessage.Message);

            // Now, accept the call. EndAcceptCall will be raised on the
            // same thread.
            _instantMessagingCall.BeginAccept(EndAcceptCall, _instantMessagingCall);
        }
        public void InstantMessagingCall_Received(CallReceivedEventArgs<InstantMessagingCall> e)
        {
            if (_state == TranscriptRecorderState.Terminated)
            {
                NonBlockingConsole.WriteLine("Error: IMTranscriptRecorder is shutdown.");
                // TODO: Info message
                return;
            }

            if (_instantMessagingCall != null)
            {
                NonBlockingConsole.WriteLine("Warn: IMCall already exists for this Conversation. Shutting down previous call...");
                // TODO: Info message
                TerminateCall();
            }

            _state = TranscriptRecorderState.Initialized;
            _waitForIMCallTerminated.Reset();

            // Type checking was done by the platform; no risk of this being any 
            // type other than the type expected.
            _instantMessagingCall = e.Call;

            // Call: StateChanged: Only hooked up for logging, to show the call
            // state transitions.
            _instantMessagingCall.StateChanged +=
                new EventHandler<CallStateChangedEventArgs>(InstantMessagingCall_StateChanged);

            _instantMessagingCall.InstantMessagingFlowConfigurationRequested +=
                new EventHandler<InstantMessagingFlowConfigurationRequestedEventArgs>(InstantMessagingCall_FlowConfigurationRequested);

            _instantMessagingCall.ConversationChanged += new EventHandler<ConversationChangedEventArgs>(InstantMessagingCall_ConversationChanged);

            // Remote Participant URI represents the far end (caller) in this 
            // conversation. Toast is the message set by the caller as the 
            // 'greet' message for this call. In Microsoft Lync, the 
            // toast will show up in the lower-right of the screen.
            // TODO: Change to protect privacy
            // NonBlockingConsole.WriteLine("IMCall Received! From: " + e.RemoteParticipant.Uri + " Toast is: " + e.ToastMessage.Message);
            NonBlockingConsole.WriteLine("IMCall Received! From: " + e.RemoteParticipant.Uri);
            // Console.Writelin("IMCall Received!");

            Message m = new Message("InstantMessagingCall Received. Inbound call state: " + _instantMessagingCall.State.ToString(),
                e.RemoteParticipant.DisplayName, e.RemoteParticipant.UserAtHost, e.RemoteParticipant.Uri,
                MessageType.InstantMessage, _transcriptRecorder.Conversation.Id, MessageDirection.Incoming);
            _transcriptRecorder.OnMessageReceived(m);

            // Now, accept the call. EndAcceptCall will be raised on the 
            // same thread.
            _instantMessagingCall.BeginAccept(InstantMessagingCallAcceptedCallBack, _instantMessagingCall);
        }
        public void TerminateCall()
        {
            if (_instantMessagingFlow != null)
            {
                _instantMessagingFlow.StateChanged -= this.InstantMessagingFlow_StateChanged;
                _instantMessagingFlow.MessageReceived -= this.InstantMessagingFlow_MessageReceived;
                _instantMessagingFlow = null;
            }

            if (_instantMessagingCall != null)
            {
                _instantMessagingCall.BeginTerminate(InstantMessagingCallTerminated, _instantMessagingCall);
                _instantMessagingCall.StateChanged -= this.InstantMessagingCall_StateChanged;
                _instantMessagingCall.InstantMessagingFlowConfigurationRequested -= this.InstantMessagingCall_FlowConfigurationRequested;
                _instantMessagingCall.ConversationChanged -= this.InstantMessagingCall_ConversationChanged;
                _instantMessagingCall = null;
            }
            else
            {
                _waitForIMCallTerminated.Set();
            }

            if (_subConversation != null)
            {
                _transcriptRecorder.OnSubConversationRemoved(_subConversation, this);
                _transcriptRecorder = null;
            }
            if (_subConversation != null)
            {
                _transcriptRecorder.OnSubConversationRemoved(_subConversation, this);
                _subConversation = null;
            }

            _waitForIMCallAccepted.Reset();
            _waitForIMFlowStateChangedToActiveCompleted.Reset();
        }
        public void EstablishInstantMessagingCall(Conversation conversation)
        {
            if (_state == TranscriptRecorderState.Terminated)
            {
                NonBlockingConsole.WriteLine("Error: IMTranscriptRecorder is shutdown.");
                // TODO: error message
                return;
            }

            if (_instantMessagingCall != null)
            {
                NonBlockingConsole.WriteLine("Warn: IMCall already exists for this Conversation. Shutting down previous call...");
                // TODO: Info message
                TerminateCall();
            }

            _state = TranscriptRecorderState.Initialized;
            this._waitForIMCallTerminated.Reset();

            try
            {
                InstantMessagingCall imCall = new InstantMessagingCall(conversation);

                // Register for Call events
                _instantMessagingCall = imCall;

                // Call: StateChanged: Only hooked up for logging, to show the call
                // state transitions.
                _instantMessagingCall.StateChanged +=
                    new EventHandler<CallStateChangedEventArgs>(InstantMessagingCall_StateChanged);

                _instantMessagingCall.InstantMessagingFlowConfigurationRequested +=
                    new EventHandler<InstantMessagingFlowConfigurationRequestedEventArgs>(InstantMessagingCall_FlowConfigurationRequested);

                // Establish AudioVideoCall
                imCall.BeginEstablish(IMCall_EstablishCompleted, imCall);
            }
            catch (InvalidOperationException ex)
            {
                NonBlockingConsole.WriteLine("Error: imCall.BeginEstablish failed. Exception: {0}", ex.ToString());
                // TODO: Error Message
            }
        }
Exemplo n.º 40
0
 internal IMCallHandler(InstantMessagingCall call, string recipientSipUri)
 {
     _frontEndCallLeg = call;
     _recipientSipUri = recipientSipUri;
 }
Exemplo n.º 41
0
        private async Task SendIM(List<string> messages, string toastMessage, string destinationSip)
        {

            Conversation conversation = new Conversation(_endpoint);
            InstantMessagingCall call = new InstantMessagingCall(conversation);

            ToastMessage toast = new ToastMessage(toastMessage);
            CallEstablishOptions options = new CallEstablishOptions();

            await call.EstablishAsync(destinationSip, toast, options);
            foreach (var msg in messages)
            {
                await call.Flow.SendInstantMessageAsync(msg);
            }
            await conversation.TerminateAsync();
            Console.WriteLine("IM Sent");
        }