// Method to establish an already created UserEndpoint.
        // This method returns an established UserEndpoint object. If you do not want to monitor LocalOwnerPresence, you may
        // want to call the CreateEstablishedUserEndpoint method directly. Otherwise, you may call ReadUserSettings
        // followed by CreateUserEndpoint, followed by EstablishUserEndpoint methods.
        public bool EstablishUserEndpoint(UserEndpoint userEndpoint)
        {
            // Startup the platform, if not already
            if (_isPlatformStarted == false)
            {
                userEndpoint.Platform.BeginStartup(EndPlatformStartup, userEndpoint.Platform);

                // Sync; wait for the platform startup to complete.
                _platformStartupCompleted.WaitOne();
                NonBlockingConsole.WriteLine("Platform started...");
                _isPlatformStarted = true;
            }
            // Establish the user endpoint
            userEndpoint.BeginEstablish(EndEndpointEstablish, userEndpoint);

            // Sync; wait for the registration to complete.
            _endpointInitCompletedEvent.WaitOne();
            NonBlockingConsole.WriteLine("Endpoint established...");
            return(true);
        }
Exemple #2
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());
            }
        }
Exemple #3
0
        private void ConferenceInvitation_AcceptCompleted(IAsyncResult result)
        {
            try
            {
                ConferenceInvitation invite = result.AsyncState as ConferenceInvitation;
                invite.EndAccept(result);

                if (_conversation == null)
                {
                    _conversation = invite.Conversation;

                    _conversationTranscriptRecorder = new ConversationTranscriptRecorder(this, _conversation);
                    _transcriptRecorders.Add(_conversationTranscriptRecorder);
                    _conversationToCallTranscriptMapping.Add(_conversationTranscriptRecorder, new List <MediaTranscriptRecorder>());

                    // TODO: Handle case where we're already joined into a different meeting for this conv?

                    ConferenceTranscriptRecorder conferenceTranscriptRecorder = new ConferenceTranscriptRecorder(this, _conversation);
                    _transcriptRecorders.Add(conferenceTranscriptRecorder);
                    _conversationToCallTranscriptMapping[_conversationTranscriptRecorder].Add(conferenceTranscriptRecorder);

                    conferenceTranscriptRecorder.ConferenceInviteAccepted(result);
                }
                else
                {
                    NonBlockingConsole.WriteLine("Warn: Already have a Conference/active conversation");
                    // Treat this as a sub conversation?

                    /*
                     * subConvRecorder = new ConversationTranscriptRecorder(this, subConversation, true);
                     * _transcriptRecorders.Add(subConvRecorder);
                     * _conversationToCallTranscriptMapping.Add(subConvRecorder, new List<MediaTranscriptRecorder>());
                     * _conversationToCallTranscriptMapping[subConvRecorder].Add(addingTranscriptRecorder);
                     */
                }
            }
            catch (Exception e)
            {
                NonBlockingConsole.WriteLine("Error: Exception occurred during conference invite acceptance: " + e.ToString());
            }
        }
Exemple #4
0
        public void AddIMIncomingCall(CallReceivedEventArgs <InstantMessagingCall> e, CancellationTokenSource cts = null)
        {
            if (_state != TranscriptRecorderState.Active)
            {
                NonBlockingConsole.WriteLine("Warn: AddIMIncomingCall in unexpected TranscriptRecorderSession state: " + _state.ToString());
            }

            IMTranscriptRecorder    i      = new IMTranscriptRecorder(this);
            ConversationParticipant caller = e.RemoteParticipant;

            Message m = new Message("InstantMessaging Conversation Participant Added.", caller.DisplayName,
                                    caller.UserAtHost, caller.Uri, DateTime.Now,
                                    _conversation.Id, _conversation.ConferenceSession.ConferenceUri,
                                    MessageType.ConversationInfo, MessageDirection.Outgoing);

            this.OnMessageReceived(m);

            _transcriptRecorders.Add(i);
            _conversationToCallTranscriptMapping[_conversationTranscriptRecorder].Add(i);

            i.InstantMessagingCall_Received(e);
        }
        private void EndPlatformStartup(IAsyncResult ar)
        {
            CollaborationPlatform collabPlatform = ar.AsyncState as CollaborationPlatform;

            try
            {
                // The platform should now be started.
                collabPlatform.EndStartup(ar);
                // It should be noted that all the re-thrown exceptions will crash the application. This is intentional.
                // Ideal exception handling would report the error and shut down nicely. In production code, consider using
                // an IAsyncResult implementation to report the error instead of throwing or put the implementation
                // in this try block.
            }
            catch (OperationFailureException opFailEx)
            {
                // OperationFailureException will be thrown when the platform cannot establish, here, usually due to invalid data.
                NonBlockingConsole.WriteLine(opFailEx.Message);
                throw;
            }
            catch (ConnectionFailureException connFailEx)
            {
                // ConnectionFailureException will be thrown when the platform cannot connect.
                // ClientPlatforms will not throw this exception on startup.
                NonBlockingConsole.WriteLine(connFailEx.Message);
                throw;
            }
            catch (RealTimeException realTimeEx)
            {
                // RealTimeException may be thrown as a result of any UCMA operation.
                NonBlockingConsole.WriteLine(realTimeEx.Message);
                throw;
            }
            finally
            {
                // Again, just for sync. reasons.
                _platformStartupCompleted.Set();
            }
        }
Exemple #6
0
        void TranscriptRecorder_OnTranscriptRecorderSessionChanged(object sender, TranscriptRecorderSessionChangedEventArgs e)
        {
            NonBlockingConsole.WriteLine("TranscriptRecorder_OnTranscriptRecorderSessionChanged event. SessionId: {0}. ConversationId: {1}. ConferenceId: {2}",
                                         e.SessionId.ToString(),
                                         (e.Conversation == null) ? "null" : e.Conversation.Id,
                                         (e.Conference == null) ? "null" : e.Conference.ConferenceUri);

            TranscriptRecorderSession session = null;

            if ((e.Conversation != null) && (e.Conference != null) &&
                _activeConversationSessions.TryGetValue(e.Conversation, out session))
            {
                // Add TranscriptRecorderSession to conference table (if no entry for this Conference already exists)
                lock (s_lock)
                {
                    if (!_activeConferenceSessions.ContainsKey(e.Conference))
                    {
                        NonBlockingConsole.WriteLine("TranscriptRecorder_OnTranscriptRecorderSessionChanged: Adding TranscriptRecorderSession for Conference entry: {0}.",
                                                     e.Conference.ConferenceUri);
                        _activeConferenceSessions.Add(e.Conference, session);

                        // If successfully added TranscriptRecorderSession to conference table, remove from conversation table
                        if (_activeConversationSessions.ContainsKey(e.Conversation))
                        {
                            NonBlockingConsole.WriteLine("TranscriptRecorder_OnTranscriptRecorderSessionChanged: Removing TranscriptRecorderSession for Conversation entry: {0}.",
                                                         e.Conversation.Id);

                            _activeConversationSessions.Remove(e.Conversation);
                        }
                    }
                } // lock
            }
            else
            {
                NonBlockingConsole.WriteLine("[Warn] TranscriptRecorder_OnTranscriptRecorderSessionChanged called on invalid Conversation or Conference. Ignoring event.");
            }
        }
        // Method to create an established UserEndpoint.
        // This method returns an established UserEndpoint object. If you do not want to monitor LocalOwnerPresence, you may
        // want to call this CreateEstablishedUserEndpoint method directly. Otherwise, you may call ReadUserSettings
        // followed by CreateUserEndpoint, followed by EstablishUserEndpoint methods.
        public UserEndpoint CreateEstablishedUserEndpoint(string endpointFriendlyName)
        {
            UserEndpointSettings userEndpointSettings;
            UserEndpoint         userEndpoint = null;

            try
            {
                // Read user settings
                userEndpointSettings = ReadUserSettings(endpointFriendlyName);

                // Create User Endpoint
                userEndpoint = CreateUserEndpoint(userEndpointSettings);

                // Establish the user endpoint
                EstablishUserEndpoint(userEndpoint);
            }
            catch (InvalidOperationException iOpEx)
            {
                // Invalid Operation Exception should only be thrown on poorly-entered input.
                NonBlockingConsole.WriteLine("Invalid Operation Exception: " + iOpEx.ToString());
            }

            return(userEndpoint);
        }
        // Method to read user settings from app.config file or from the console prompts
        // This method returns a UserEndpointSettings object. If you do not want to monitor LocalOwnerPresence, you may
        // want to call the CreateEstablishedUserEndpoint method directly. Otherwise, you may call ReadUserSettings
        // followed by CreateUserEndpoint, followed by EstablishUserEndpoint methods.
        public UserEndpointSettings ReadUserSettings(string userFriendlyName)
        {
            UserEndpointSettings userEndpointSettings = null;
            string prompt = string.Empty;

            if (string.IsNullOrEmpty(userFriendlyName))
            {
                userFriendlyName = "Default User";
            }

            try
            {
                NonBlockingConsole.WriteLine(string.Empty);
                NonBlockingConsole.WriteLine("Creating User Endpoint for {0}...", userFriendlyName);
                NonBlockingConsole.WriteLine("");

                if (ConfigurationManager.AppSettings[_serverFQDNPrompt + _userCount] != null)
                {
                    _serverFqdn = ConfigurationManager.AppSettings[_serverFQDNPrompt + _userCount];
                    NonBlockingConsole.WriteLine("Using {0} as Microsoft Lync Server", _serverFqdn);
                }
                else
                {
                    // Prompt user for server FQDN. If server FQDN was entered before, then let the user use the saved value.
                    string        localServer;
                    StringBuilder promptBuilder = new StringBuilder();
                    if (!string.IsNullOrEmpty(_serverFqdn))
                    {
                        promptBuilder.Append("Current Microsoft Lync Server = ");
                        promptBuilder.Append(_serverFqdn);
                        promptBuilder.AppendLine(". Please hit ENTER to retain this setting - OR - ");
                    }

                    promptBuilder.Append("Please enter the FQDN of the Microsoft Lync Server that the ");
                    promptBuilder.Append(userFriendlyName);
                    promptBuilder.Append(" endpoint is homed on => ");
                    localServer = PromptUser(promptBuilder.ToString(), null);

                    if (!String.IsNullOrEmpty(localServer))
                    {
                        _serverFqdn = localServer;
                    }
                }

                // Prompt user for user name
                prompt = String.Concat("Please enter the User Name for ",
                                       userFriendlyName,
                                       " (or hit the ENTER key to use current credentials)\r\n" +
                                       "Please enter the User Name => ");
                _userName = PromptUser(prompt, _userNamePrompt + _userCount);

                // If user name is empty, use current credentials
                if (string.IsNullOrEmpty(_userName))
                {
                    NonBlockingConsole.WriteLine("Username was empty - using current credentials...");
                    _useSuppliedCredentials = true;
                }
                else
                {
                    // Prompt for password
                    prompt        = String.Concat("Enter the User Password for ", userFriendlyName, " => ");
                    _userPassword = PromptUser(prompt, null);

                    prompt      = String.Concat("Please enter the User Domain for ", userFriendlyName, " => ");
                    _userDomain = PromptUser(prompt, _userDomainPrompt + _userCount);
                }

                // Prompt user for user URI
                prompt   = String.Concat("Please enter the User URI for ", userFriendlyName, " in the User@Host format => ");
                _userURI = PromptUser(prompt, _userURIPrompt + _userCount);
                if (!(_userURI.ToLower().StartsWith("sip:") || _userURI.ToLower().StartsWith("tel:")))
                {
                    _userURI = "sip:" + _userURI;
                }

                // Increment the last user number
                _userCount++;

                // Initalize and register the endpoint, using the credentials of the user the application will be acting as.
                // NOTE: the _userURI should always be of the form "sip:user@host"
                userEndpointSettings = new UserEndpointSettings(_userURI, _serverFqdn);

                if (!_useSuppliedCredentials)
                {
                    _credential = new System.Net.NetworkCredential(_userName, _userPassword, _userDomain);
                    userEndpointSettings.Credential = _credential;
                }
                else
                {
                    userEndpointSettings.Credential = System.Net.CredentialCache.DefaultNetworkCredentials;
                }
            }
            catch (InvalidOperationException iOpEx)
            {
                // Invalid Operation Exception should only be thrown on poorly-entered input.
                NonBlockingConsole.WriteLine("Invalid Operation Exception: " + iOpEx.ToString());
            }

            return(userEndpointSettings);
        }
 /// <summary>
 /// Prompts the user to press a key, unblocking any waiting calls to the
 /// <code>WaitForSampleFinish</code> method
 /// </summary>
 public static void FinishSample()
 {
     NonBlockingConsole.WriteLine("Please hit any key to end the sample.");
     Console.ReadKey();
     _sampleFinished.Set();
 }
 public static void WriteErrorLine(string line)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     NonBlockingConsole.WriteLine(line);
     Console.ResetColor();
 }
 public static void WriteLine(string line)
 {
     NonBlockingConsole.WriteLine(line);
 }
Exemple #12
0
 internal void Print()
 {
     NonBlockingConsole.WriteLine(this.ToString());
 }
Exemple #13
0
        private async Task StopTranscriptRecorderSessionAsync(Guid sessionId, bool shutdownSession = true)
        {
            NonBlockingConsole.WriteLine("StopTranscriptRecorderSession - Entry. SessionId: {0}.", sessionId.ToString());
            TranscriptRecorderSession sessionToStop = null;
            bool shutdownManager = false;

            lock (s_lock)
            {
                if (_state == TranscriptSessionManagerState.Active)
                {
                    foreach (TranscriptRecorderSession trs in _activeConversationSessions.Values)
                    {
                        if (trs.SessionId.Equals(sessionId))
                        {
                            sessionToStop = trs;
                            break;
                        }
                    }

                    if (sessionToStop != null)
                    {
                        _activeConversationSessions.Remove(sessionToStop.Conversation);

                        if ((sessionToStop.Conference != null) && _activeConferenceSessions.ContainsKey(sessionToStop.Conference))
                        {
                            _activeConferenceSessions.Remove(sessionToStop.Conference);
                        }
                    }
                    else
                    {
                        foreach (TranscriptRecorderSession trs in _activeConferenceSessions.Values)
                        {
                            if (trs.SessionId.Equals(sessionId))
                            {
                                sessionToStop = trs;
                                break;
                            }
                        }

                        if (sessionToStop != null)
                        {
                            _activeConferenceSessions.Remove(sessionToStop.Conference);
                        }
                    }

                    if ((_activeConferenceSessions.Count + _activeConversationSessions.Count) == 0)
                    {
                        shutdownManager = true;
                    }
                } // (_state == TranscriptSessionManagerState.Active)
            }     // lock

            // Only need to shutdown TranscriptRecorderSession once (if found)
            if (sessionToStop != null)
            {
                Task task = new Task(() =>
                {
                    SaveTranscript(sessionToStop);
                    SendTranscript(sessionToStop);

                    if (shutdownSession)
                    {
                        sessionToStop.Shutdown();
                    }
                });

                List <Task> tasks = new List <Task>()
                {
                    task
                };
                task.Start();
                await Task.WhenAll(tasks);

                if (shutdownManager)
                {
                    await this.ShutdownAsync();
                }
            }
            else
            {
                NonBlockingConsole.WriteLine("StopTranscriptRecorderSession: TranscriptRecorderSession {0} doesn't exist or was already shutdown",
                                             sessionId.ToString());
            }

            NonBlockingConsole.WriteLine("StopTranscriptRecorderSession - Exit. SessionId: {0}.", sessionId.ToString());
        }
Exemple #14
0
 private void SendTranscripts()
 {
     // TODO
     NonBlockingConsole.WriteLine("SendTranscripts - Entry");
     NonBlockingConsole.WriteLine("SendTranscripts - Exit");
 }
Exemple #15
0
 private void SendTranscript(TranscriptRecorderSession trs)
 {
     // TODO
     NonBlockingConsole.WriteLine("SendTranscript - Entry");
     NonBlockingConsole.WriteLine("SendTranscript - Exit");
 }
Exemple #16
0
        public async Task ShutdownAsync(bool runSync = false)
        {
            NonBlockingConsole.WriteLine("ShutdownAsync - Entry");
            bool        startTask        = true;
            List <Task> preShutdownTasks = new List <Task>();
            List <Task> shutdownTasks    = new List <Task>();

            lock (s_lock)
            {
                if (_state == TranscriptSessionManagerState.Terminating || _state == TranscriptSessionManagerState.Terminated)
                {
                    NonBlockingConsole.WriteLine("Warn: Already shutdown or shutting down.");
                    startTask = false;
                    if (_shutdownTask != null)
                    {
                        shutdownTasks.Add(_shutdownTask);
                    }
                }
                else
                {
                    _state = TranscriptSessionManagerState.Terminating;
                    this.UnregisterEndpointEvents();

                    List <TranscriptRecorderSession> sessionsToShutdown = new List <TranscriptRecorderSession>();
                    // Add all active conversation transcript sessions to shutdown list
                    foreach (TranscriptRecorderSession t in _activeConversationSessions.Values)
                    {
                        sessionsToShutdown.Add(t);
                    }
                    // Add all active conference transcript sessions to shutdown list
                    foreach (TranscriptRecorderSession t in _activeConferenceSessions.Values)
                    {
                        sessionsToShutdown.Add(t);
                    }
                    _shutdownTask = new Task(() =>
                    {
                        SaveTranscripts();
                        SendTranscripts();

                        _activeConversationSessions.Clear();
                        _activeConferenceSessions.Clear();
                        foreach (TranscriptRecorderSession t in sessionsToShutdown)
                        {
                            Task task = new Task(() =>
                            {
                                t.TranscriptRecorderSessionChanged  -= this.TranscriptRecorder_OnTranscriptRecorderSessionChanged;
                                t.TranscriptRecorderSessionShutdown -= this.TranscriptRecorder_OnTranscriptRecorderSessionShutdown;
                                t.Shutdown();
                            });
                            task.Wait();
                        }

                        // Terminate user endpoint
                        if (_userEndpoint != null)
                        {
                            _userEndpoint.BeginTerminate(EndTerminateUserEndpoint, _userEndpoint);
                            _waitForUserEndpointTerminated.WaitOne();
                        }

                        // Clean up by shutting down the platform.
                        if (_helper != null)
                        {
                            _helper.ShutdownPlatform();
                        }

                        _state = TranscriptSessionManagerState.Terminated;
                    });
                    shutdownTasks.Add(_shutdownTask);
                }
            } // lock

            if (startTask)
            {
                _shutdownTask.Start();
            }

            if (runSync)
            {
                Task.WhenAll(shutdownTasks.ToArray()).Wait();
            }
            else
            {
                await Task.WhenAll(shutdownTasks.ToArray());
            }

            NonBlockingConsole.WriteLine("ShutdownAsync - Exit");
        }