예제 #1
0
        private void EndEject(IAsyncResult ar)
        {
            ConferenceSession confSession = ar.AsyncState as ConferenceSession;

            try
            {
                confSession.EndEject(ar);
            }
            catch (OperationFailureException opFailEx)
            {
                // OperationFailureException: Indicates failure to connect the
                // call to the remote party.
                // TODO (Left to the reader): Add error handling code here.
                Console.WriteLine(opFailEx.ToString());
            }
            catch (RealTimeException realTimeEx)
            {
                // RealTimeException may be thrown on media or link-layer failures,
                // or call rejection (FailureResponseException)
                // TODO (Left to the reader): Add error handling code here.
                Console.WriteLine(realTimeEx.ToString());
            }
            finally
            {
                //Again, just to sync the completion of the code.
                _waitForParticipantEject.Set();
            }
        }
 public static Task ModifyRole(this ConferenceSession session,
                               ConversationParticipant participant,
                               ConferencingRole role, ModifyRoleOptions options)
 {
     return(Task.Factory.FromAsync(session.BeginModifyRole,
                                   session.EndModifyRole, participant, role, options, null));
 }
예제 #3
0
        private void EndJoinConference(IAsyncResult ar)
        {
            ConferenceSession confSession = ar.AsyncState as ConferenceSession;

            try
            {
                confSession.EndJoin(ar);
            }
            catch (ConferenceFailureException confFailEx)
            {
                // ConferenceFailureException may be thrown on failures due to
                // MCUs being absent or unsupported, or due to malformed parameters.
                // TODO (Left to the reader): Add error handling code
                Console.WriteLine(confFailEx.ToString());
            }
            catch (RealTimeException rTEx)
            {
                // TODO (Left to the reader): Add error handling code
                Console.WriteLine(rTEx.ToString());
            }
            finally
            {
                //Again, for sync. reasons.
                _waitForConferenceJoin.Set();
            }
        }
 public static Task <ConferenceSessionExtendedProperties> GetExtendedPropertiesAsync(
     this ConferenceSession session)
 {
     return(Task <ConferenceSessionExtendedProperties> .Factory.FromAsync(
                session.BeginGetExtendedProperties,
                session.EndGetExtendedProperties, null));
 }
        //Just to record the state transitions in the console.
        void ConferenceSession_ParticipantEndpointAttendanceChanged(object sender,
                                                                    ParticipantEndpointAttendanceChangedEventArgs <ConferenceParticipantEndpointProperties> e)
        {
            ConferenceSession confSession = sender as ConferenceSession;

            // Log each participant as s/he gets added/deleted from the ConferenceSession's roster.
            foreach (KeyValuePair <ParticipantEndpoint, ConferenceParticipantEndpointProperties> pair in e.Joined)
            {
                NonBlockingConsole.WriteLine("{0} is notified of participant joining the conference: {1}",
                                             confSession.Conversation.LocalParticipant.UserAtHost,
                                             pair.Key.Participant.UserAtHost);

                Message m = new Message("Participant joined conference.", pair.Key.Participant.DisplayName, pair.Key.Participant.UserAtHost,
                                        pair.Key.Participant.Uri, MessageType.ConferenceInfo, _conversation.Id, _conference.ConferenceUri, MessageDirection.Incoming);
                _transcriptRecorder.OnMessageReceived(m);
            }

            foreach (KeyValuePair <ParticipantEndpoint, ConferenceParticipantEndpointProperties> pair in e.Left)
            {
                NonBlockingConsole.WriteLine("{0} is notified of participant leaving the conference: {1}",
                                             confSession.Conversation.LocalParticipant.UserAtHost,
                                             pair.Key.Participant.UserAtHost);

                Message m = new Message("Participant left conference.", pair.Key.Participant.DisplayName, pair.Key.Participant.UserAtHost,
                                        pair.Key.Participant.Uri, MessageType.ConferenceInfo, _conversation.Id, _conference.ConferenceUri, MessageDirection.Incoming);
                _transcriptRecorder.OnMessageReceived(m);
            }

            NonBlockingConsole.WriteLine("");
        }
        //Just to record the state transitions in the console.
        void ConferenceSession_StateChanged(object sender, StateChangedEventArgs <ConferenceSessionState> e)
        {
            ConferenceSession confSession = sender as ConferenceSession;

            //Session participants allow for disambiguation.
            NonBlockingConsole.WriteLine("The conference session with Local Participant: " +
                                         confSession.Conversation.LocalParticipant + " has changed state. " +
                                         "The previous conference state was: " + e.PreviousState +
                                         " and the current state is: " + e.State);
            NonBlockingConsole.WriteLine("");

            Message m = new Message("ConferenceSession state changed from " + e.PreviousState.ToString()
                                    + " to new value: " + e.State.ToString() + ".",
                                    confSession.Conversation.LocalParticipant.DisplayName,
                                    confSession.Conversation.LocalParticipant.UserAtHost,
                                    confSession.Conversation.LocalParticipant.Uri,
                                    DateTime.Now, confSession.Conversation.Id, confSession.ConferenceUri, MessageType.ConferenceInfo, MessageDirection.Outgoing);

            _transcriptRecorder.OnMessageReceived(m);

            if (e.State == ConferenceSessionState.Disconnecting || e.State == ConferenceSessionState.Disconnected)
            {
                this.Shutdown();
            }
        }
예제 #7
0
        private void EndCalleeJoinConference(IAsyncResult ar)
        {
            ConferenceSession confSession = ar.AsyncState as ConferenceSession;

            try
            {
                confSession.EndJoin(ar);
            }
            catch (OperationFailureException opFailEx)
            {
                // OperationFailureException: Indicates failure to connect the
                // call to the remote party.
                // TODO (Left to the reader): Add error handling code here.
                Console.WriteLine(opFailEx.ToString());
            }
            catch (RealTimeException realTimeEx)
            {
                // RealTimeException may be thrown on media or link-layer failures,
                // or call rejection (FailureResponseException)
                // TODO (Left to the reader): Add error handling code here.
                Console.WriteLine(realTimeEx.ToString());
            }

            // As mentioned before, if this is the first party to escalate, the
            // remote party will receive an escalation request, via the event on
            // the far end conversation, EscalateToConferenceRequested. Also, the
            // existing calls will be shifted to the MCUs.
            confSession.Conversation.BeginEscalateToConference(EndCalleeEscalateConference,
                                                               confSession.Conversation);
        }
 public TranscriptRecorderSessionShutdownEventArgs(TranscriptRecorderSession trs)
 {
     _conference = trs.Conference;
     _conversation = trs.Conversation;
     _transcriptRecorderSession = trs;
     _sessionId = trs.SessionId;
     _messages = trs.Messages;
 }
예제 #9
0
 public TranscriptRecorderSessionShutdownEventArgs(TranscriptRecorderSession trs)
 {
     _conference   = trs.Conference;
     _conversation = trs.Conversation;
     _transcriptRecorderSession = trs;
     _sessionId = trs.SessionId;
     _messages  = trs.Messages;
 }
예제 #10
0
        public async Task <IActionResult> Delete(int id)
        {
            ConferenceSession session = await _sessionRepository.Get(id);

            await _sessionRepository.Delete(id);

            return(Ok());
        }
 public static Task ModifyConferenceConfigurationAsync(this ConferenceSession session,
                                                       ConferenceAccessLevel accessLevel, LobbyBypass lobbyBypass,
                                                       AutomaticLeaderAssignment automaticLeaderAssignment)
 {
     return(Task.Factory.FromAsync(session.BeginModifyConferenceConfiguration,
                                   session.EndModifyConferenceConfiguration, accessLevel, lobbyBypass,
                                   automaticLeaderAssignment, null));
 }
예제 #12
0
        public async Task <bool> AddSession(ConferenceSession model)
        {
            var clientObject = _cosmosSession.GetSession();
            var container    = clientObject.Client.GetContainer(clientObject.DBName, typeof(ConferenceSession).Name);
            var response     = await container.CreateItemAsync(model, new PartitionKey(model.Id));

            _log.Info($"Added new location: {response.RequestCharge} RUs");
            return(true);
        }
        // Record the ConferenceSession state transitions in the console.
        void ConferenceSession_StateChanged(object sender, StateChangedEventArgs <ConferenceSessionState> e)
        {
            ConferenceSession confSession = sender as ConferenceSession;

            Console.WriteLine("The conference session with Local Participant: " +
                              confSession.Conversation.LocalParticipant +
                              " has changed state. The previous conference state was: " + e.PreviousState +
                              " and the current state is: " + e.State);
        }
예제 #14
0
        public async Task <IActionResult> Put(int id, [FromBody] ConferenceSession updated)
        {
            ConferenceSession session = await _sessionRepository.Get(id);

            // Map the database session object with the updated properties
            Mapper.Initialize(cfg => cfg.CreateMap <ConferenceSession, ConferenceSession>());
            Mapper.Map(updated, session);

            await _sessionRepository.Update(session);

            return(Ok());
        }
 public async Task Update(ConferenceSession session)
 {
     _context.Sessions.Update(session);
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public async Task <ConferenceSession> Insert(ConferenceSession session)
        {
            _context.Sessions.Add(session);
            try
            {
                await _context.SaveChangesAsync();

                return(session);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        /// <summary>
        /// Occurs when bot joined the conference.
        /// </summary>
        /// <param name="argument">The argument.</param>
        /// <remarks></remarks>
        public void EndJoinEscalatedConference(IAsyncResult argument)
        {
            ConferenceSession conferenceSession = argument.AsyncState as ConferenceSession;
            Exception         exception         = null;

            try
            {
                NonBlockingConsole.WriteLine("Joined the conference");
                conferenceSession.EndJoin(argument);
                NonBlockingConsole.WriteLine(string.Format(
                                                 "Conference Url: conf:{0}%3Fconversation-id={1}",
                                                 conferenceSession.ConferenceUri,
                                                 conferenceSession.Conversation.Id));

                _conference = conferenceSession;

                RegisterConferenceEvents();

                // Raise event on TranscriptRecorderSession
                _transcriptRecorder.RaiseTranscriptRecorderSessionChanged(_conference);

                // In case Bot was dragged into existing conversation or someone was dragged into existing conversation with Bot;
                // it will create ad-hoc conference and here is the place where we need to escalate current call into conference.
                conferenceSession.Conversation.BeginEscalateToConference(EndEscalateConversation, conferenceSession.Conversation);
            }
            catch (ConferenceFailureException conferenceFailureException)
            {
                // ConferenceFailureException may be thrown on failures due to MCUs being absent or unsupported, or due to malformed parameters.
                // It is left to the application to perform real error handling here.
                NonBlockingConsole.WriteLine(conferenceFailureException.ToString());
                exception = conferenceFailureException;
            }
            catch (RealTimeException realTimeException)
            {
                // It is left to the application to perform real error handling here.
                NonBlockingConsole.WriteLine(realTimeException.ToString());
                exception = realTimeException;
            }
            finally
            {
                if (exception != null)
                {
                    string originator = string.Format("Error when joining the escalated conference.");
                    NonBlockingConsole.WriteLine(originator);
                }

                _waitForEscalatedConferenceJoined.Set();
            }
        }
        public ConferenceTranscriptRecorder(TranscriptRecorderSession transcriptRecorder, Conversation conversation)
        {
            _transcriptRecorder = transcriptRecorder;
            _conversation       = conversation;

            // TODO: TranscriptRecorderSession should check if new conversation is joined to a conference and do full
            // Begin/EndJoin with an End async method in ConferenceTranscriptRecorder (as is done for Invite or Escalate)
            if (_conversation.ConferenceSession != null)
            {
                _conference = _conversation.ConferenceSession;
                _state      = TranscriptRecorderState.Active;
                _waitForInvitedConferenceJoined.Set();
                RegisterConferenceEvents();
            }
        }
        public ConferenceTranscriptRecorder(TranscriptRecorderSession transcriptRecorder, Conversation conversation)
        {
            _transcriptRecorder = transcriptRecorder;
            _conversation = conversation;

            // TODO: TranscriptRecorderSession should check if new conversation is joined to a conference and do full
            // Begin/EndJoin with an End async method in ConferenceTranscriptRecorder (as is done for Invite or Escalate)
            if (_conversation.ConferenceSession != null)
            {
                _conference = _conversation.ConferenceSession;
                _state = TranscriptRecorderState.Active;
                _waitForInvitedConferenceJoined.Set();
                RegisterConferenceEvents();
            }
        }
예제 #20
0
        public async Task <bool> UpdateSession(ConferenceSession model)
        {
            try
            {
                var clientObject = _cosmosSession.GetSession();
                var container    = clientObject.Client.GetContainer(clientObject.DBName, typeof(ConferenceSession).Name);
                var response     = await container.ReplaceItemAsync <dynamic>(model, model.Id.ToString(), partitionKey : new PartitionKey(model.Id));

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #21
0
        /// <summary>
        /// Callback for conference termination.
        /// </summary>
        /// <param name="asyncResult"></param>
        private void ConferenceTerminated(IAsyncResult asyncResult)
        {
            Exception caughtException           = null;
            bool      unhandledExceptionOccured = true;

            try
            {
                ConferenceSession confSession = asyncResult.AsyncState as ConferenceSession;
                confSession.EndTerminateConference(asyncResult);

                this.trustedConversation.BeginTerminate(this.ConversationTerminationCompleted, this.trustedConversation);
                unhandledExceptionOccured = false;
            }
            catch (InvalidOperationException ioe)
            {
                caughtException = ioe;
                Console.WriteLine("Exception during termination {0}", ioe);
                this.logger.Log("Exception during termination {0}", ioe);
                unhandledExceptionOccured = false;
            }
            catch (RealTimeException rte)
            {
                caughtException = rte;
                Console.WriteLine("Exception during termination {0}", rte);
                this.logger.Log("Exception during termination {0}", rte);
                unhandledExceptionOccured = false;
            }
            finally
            {
                if (unhandledExceptionOccured)
                {
                    caughtException = new OperationFailureException();
                    Console.WriteLine("Unhandled Exception during termination");
                    this.logger.Log("Unhandled Exception during termination");
                }

                if (caughtException != null)
                {
                    this.CompleteTermination();
                }
            }
        }
예제 #22
0
        internal void RaiseTranscriptRecorderSessionChanged(ConferenceSession conference)
        {
            NonBlockingConsole.WriteLine("Raising TranscriptRecorderSessionShutdown event. SessionId: {0}. ConferenceUri: {1}",
                                         this.SessionId.ToString(), (conference == null) ? "null" : conference.ConferenceUri);

            try
            {
                if (this.TranscriptRecorderSessionChanged != null)
                {
                    TranscriptRecorderSessionChangedEventArgs args = new TranscriptRecorderSessionChangedEventArgs(this);
                    this.TranscriptRecorderSessionChanged.Invoke(this, args);
                }
            }
            catch (Exception e)
            {
                NonBlockingConsole.WriteLine("Error: Exception occured in TranscriptRecorderSessionChanged(). Conference: {0}. {1}.",
                                             conference.ConferenceUri,
                                             e.ToString());
            }
        }
        // Callback method referred to in the call to BeginJoin on the ConferenceSession instance.
        private void ConferenceJoinCB(IAsyncResult ar)
        {
            ConferenceSession conferenceSession = ar.AsyncState as ConferenceSession;

            try
            {
                conferenceSession.EndJoin(ar);
                Console.WriteLine("Conversation state: " + _incomingConversation.State.ToString());
                Console.WriteLine("Conference session state: " + _conferenceSession.State.ToString());
                _incomingConversation.BeginEscalateToConference(ConferenceEscalateCB, _incomingConversation);
                int ThreadID = Thread.CurrentThread.ManagedThreadId;
                Console.WriteLine("Conf join callback thread: ID " + ThreadID);
            }

            // A production application should have catch blocks for a number
            // of other exceptions, including ConferenceFailureException, FailureRequestException,
            // and OperationFailureException.
            catch (RealTimeException exception)
            {
                Console.WriteLine(exception.ToString());
            }
        }
        // Just to record the state transitions in the console.
        void ConferenceSession_ParticipantEndpointPropertiesChanged(object sender,
                                                                    ParticipantEndpointPropertiesChangedEventArgs <ConferenceParticipantEndpointProperties> e)
        {
            ConferenceSession confSession = sender as ConferenceSession;

            NonBlockingConsole.WriteLine(
                "{0} is notified of ConferenceSession participant property change for user: {1}. Role:{2}, CanManageLobby:{3}, InLobby:{4}",
                confSession.Conversation.LocalParticipant.UserAtHost,
                e.ParticipantEndpoint.Participant.UserAtHost,
                e.Properties.Role.ToString(),
                e.Properties.CanManageLobby.ToString(),
                e.Properties.IsInLobby.ToString());

            NonBlockingConsole.WriteLine("");

            Message m = new Message("Conference participant properties changed. Changed properties: " + e.ChangedPropertyNames.ToString() + ". New property values: " + e.Properties.ToString() + ".",
                                    e.ParticipantEndpoint.Participant.DisplayName,
                                    e.ParticipantEndpoint.Participant.UserAtHost,
                                    e.ParticipantEndpoint.Participant.Uri, MessageType.ConferenceInfo, _conversation.Id,
                                    confSession.ConferenceUri, MessageDirection.Incoming);

            _transcriptRecorder.OnMessageReceived(m);
        }
 public static Task LockConferenceAsync(this ConferenceSession session,
                                        LockConferenceOptions options)
 {
     return(Task.Factory.FromAsync(session.BeginLockConference,
                                   session.EndLockConference, options, null));
 }
 public static Task JoinAsync(this ConferenceSession session,
                              string conferenceUri, ConferenceJoinOptions options)
 {
     return(Task.Factory.FromAsync(session.BeginJoin,
                                   session.EndJoin, conferenceUri, options, null));
 }
 public static Task JoinAsync(this ConferenceSession session,
                              MeetNowOptions options)
 {
     return(Task.Factory.FromAsync(session.BeginJoin,
                                   session.EndJoin, options, null));
 }
 public static Task UnlockConferenceAsync(this ConferenceSession session)
 {
     return(Task.Factory.FromAsync(session.BeginUnlockConference,
                                   session.EndUnlockConference, null));
 }
        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();
        }
 public TranscriptRecorderSessionChangedEventArgs(TranscriptRecorderSession trs)
 {
     _conference = trs.Conference;
     _conversation = trs.Conversation;
     _sessionId = trs.SessionId;
 }
        internal void RaiseTranscriptRecorderSessionChanged(ConferenceSession conference)
        {
            NonBlockingConsole.WriteLine("Raising TranscriptRecorderSessionShutdown event. SessionId: {0}. ConferenceUri: {1}",
                this.SessionId.ToString(), (conference == null) ? "null" : conference.ConferenceUri);

            try
            {
                if (this.TranscriptRecorderSessionChanged != null)
                {
                    TranscriptRecorderSessionChangedEventArgs args = new TranscriptRecorderSessionChangedEventArgs(this);
                    this.TranscriptRecorderSessionChanged.Invoke(this, args);
                }
            }
            catch (Exception e)
            {
                NonBlockingConsole.WriteLine("Error: Exception occured in TranscriptRecorderSessionChanged(). Conference: {0}. {1}.",
                    conference.ConferenceUri,
                    e.ToString());
            }
        }
예제 #32
0
            internal void Process()
            {
                if (_anchor._conversation.State != ConversationState.Idle)
                {
                    if (null != _anchor._conference)
                    {
                        _anchor._conversation.ConferenceSession.BeginTerminateConference(ar =>
                        {
                            ConferenceSession confSession = ar.AsyncState as ConferenceSession;
                            confSession.EndTerminateConference(ar);

                            confSession.Conversation.Endpoint.ConferenceServices.BeginCancelConference(_anchor._conference.ConferenceId,
                                                                                                       cac =>
                            {
                                ConferenceServices confServices = cac.AsyncState as ConferenceServices;
                                try
                                {
                                    confServices.EndCancelConference(cac);
                                }
                                catch (RealTimeException)
                                {
                                    //TODO: trace statement
                                }
                                finally
                                {
                                    this.SetAsCompleted(null, false);
                                    _anchor.UpdateState(ConferenceServicesAnchorState.Terminated);
                                    foreach (ShutDownAsyncResult sar in _anchor._listOfShutDownAsyncResults)
                                    {
                                        sar.SetAsCompleted(null, false);
                                    }
                                }
                            },
                                                                                                       confSession.Conversation.Endpoint.ConferenceServices);
                        },
                                                                                         _anchor._conversation.ConferenceSession);
                    }
                    else
                    {
                        _anchor.Conversation.BeginTerminate(ter =>
                        {
                            _anchor.Conversation.EndTerminate(ter);

                            _anchor.UpdateState(ConferenceServicesAnchorState.Terminated);

                            foreach (ShutDownAsyncResult sar in _anchor._listOfShutDownAsyncResults)
                            {
                                sar.SetAsCompleted(null, false);
                            }

                            this.SetAsCompleted(null, false);
                        },
                                                            null);
                    }
                }
                else
                {
                    _anchor.Conversation.BeginTerminate(ter =>
                    {
                        _anchor.Conversation.EndTerminate(ter);

                        _anchor.UpdateState(ConferenceServicesAnchorState.Terminated);

                        foreach (ShutDownAsyncResult sar in _anchor._listOfShutDownAsyncResults)
                        {
                            sar.SetAsCompleted(null, false);
                        }

                        this.SetAsCompleted(null, false);
                    },
                                                        null);
                }
            }
 public static Task EjectAsync(this ConferenceSession session,
                               ConversationParticipant participant)
 {
     return(Task.Factory.FromAsync(session.BeginEject,
                                   session.EndEject, participant, null));
 }
        /// <summary>
        /// Occurs when bot joined the conference.
        /// </summary>
        /// <param name="result">The argument.</param>
        /// <remarks></remarks>
        public void EndJoinInvitedConference(IAsyncResult result)
        {
            ConferenceInvitation invite = result.AsyncState as ConferenceInvitation;
            Exception exception = null;
            List<String> activeMediaTypes = new List<string>();
            try
            {
                NonBlockingConsole.WriteLine("Joined the invited conference");
                activeMediaTypes = invite.AvailableMediaTypes.ToList();

                _conversation.ConferenceSession.EndJoin(result);
                _conference = _conversation.ConferenceSession;

                NonBlockingConsole.WriteLine(string.Format(
                                              "Conference Url: conf:{0}%3Fconversation-id={1}",
                                              _conversation.ConferenceSession.ConferenceUri,
                                              _conversation.ConferenceSession.Conversation.Id));

                RegisterConferenceEvents();

                // Raise event on TranscriptRecorderSession
                _transcriptRecorder.RaiseTranscriptRecorderSessionChanged(_conference);

                // Establish Calls for Conference's supported modalities
                if (activeMediaTypes.Contains(MediaType.Audio))
                {
                    _transcriptRecorder.OnActiveMediaTypeCallToEstablish(_conversation, TranscriptRecorderType.AudioVideo);
                }
                if (activeMediaTypes.Contains(MediaType.Message))
                {
                    _transcriptRecorder.OnActiveMediaTypeCallToEstablish(_conversation, TranscriptRecorderType.InstantMessage);
                }

                _waitForInvitedConferenceActiveMediaTypeCallEstablished.Set();
            }
            catch (ConferenceFailureException conferenceFailureException)
            {
                // ConferenceFailureException may be thrown on failures due to MCUs being absent or unsupported, or due to malformed parameters.
                // It is left to the application to perform real error handling here.
                NonBlockingConsole.WriteLine(conferenceFailureException.ToString());
                exception = conferenceFailureException;
            }
            catch (RealTimeException realTimeException)
            {
                // It is left to the application to perform real error handling here.
                NonBlockingConsole.WriteLine(realTimeException.ToString());
                exception = realTimeException;
            }
            finally
            {
                // Again, for sync. reasons.
                _state = TranscriptRecorderState.Active;
                _waitForInvitedConferenceJoined.Set();

                if (exception != null)
                {
                    string originator = string.Format("Error when joining the invited conference: {0}", exception.ToString());
                    NonBlockingConsole.WriteLine(originator);
                }
            }
        }
 public static Task TerminateConferenceAsync(this ConferenceSession session)
 {
     return(Task.Factory.FromAsync(session.BeginTerminateConference,
                                   session.EndTerminateConference, null));
 }
        /// <summary>
        /// Occurs when bot joined the conference.
        /// </summary>
        /// <param name="argument">The argument.</param>
        /// <remarks></remarks>
        public void EndJoinEscalatedConference(IAsyncResult argument)
        {
            ConferenceSession conferenceSession = argument.AsyncState as ConferenceSession;
            Exception exception = null;
            try
            {
                NonBlockingConsole.WriteLine("Joined the conference");
                conferenceSession.EndJoin(argument);
                NonBlockingConsole.WriteLine(string.Format(
                                              "Conference Url: conf:{0}%3Fconversation-id={1}",
                                              conferenceSession.ConferenceUri,
                                              conferenceSession.Conversation.Id));

                _conference = conferenceSession;

                RegisterConferenceEvents();

                // Raise event on TranscriptRecorderSession
                _transcriptRecorder.RaiseTranscriptRecorderSessionChanged(_conference);

                // In case Bot was dragged into existing conversation or someone was dragged into existing conversation with Bot; 
                // it will create ad-hoc conference and here is the place where we need to escalate current call into conference.
                conferenceSession.Conversation.BeginEscalateToConference(EndEscalateConversation, conferenceSession.Conversation);

            }
            catch (ConferenceFailureException conferenceFailureException)
            {
                // ConferenceFailureException may be thrown on failures due to MCUs being absent or unsupported, or due to malformed parameters.
                // It is left to the application to perform real error handling here.
                NonBlockingConsole.WriteLine(conferenceFailureException.ToString());
                exception = conferenceFailureException;
            }
            catch (RealTimeException realTimeException)
            {
                // It is left to the application to perform real error handling here.
                NonBlockingConsole.WriteLine(realTimeException.ToString());
                exception = realTimeException;
            }
            finally
            {
                if (exception != null)
                {
                    string originator = string.Format("Error when joining the escalated conference.");
                    NonBlockingConsole.WriteLine(originator);
                }

                _waitForEscalatedConferenceJoined.Set();
            }
        }