Beispiel #1
0
        /// <summary>
        /// Record the endpoint state transitions to the console.
        /// </summary>
        /// <param name="sender">Endpoint that saw its state change.</param>
        /// <param name="e">Data about the endpoint state change event.</param>
        private void _endpoint_StateChanged(object sender, LocalEndpointStateChangedEventArgs e)
        {
            // Extract the endpoint that sent the state change event.
            ApplicationEndpoint endpoint = sender as ApplicationEndpoint;

            UCMASampleHelper.WriteLine("Endpoint (" + endpoint.OwnerUri
                                       + ") has changed state. The previous endpoint state was '"
                                       + e.PreviousState + "' and the current state is '" + e.State + "'.");
        }
Beispiel #2
0
        /// <summary>
        /// Callback from <code>BeginShutdown</code> method on platform.
        /// </summary>
        /// <param name="result">
        /// Status of the platform shutdown operation.
        /// </param>
        private void PlatformShutdownCompleted(IAsyncResult result)
        {
            // Extract the platform that was passed in as the state argument to
            // the BeginShutdown() method.
            CollaborationPlatform platform = result.AsyncState as CollaborationPlatform;

            if (platform == null)
            {
                UCMASampleHelper.WriteErrorLine(
                    "CollaborationPlatform not passed into BeginShutdown() method.");
                UCMASampleHelper.FinishSample();
                return;
            }

            // Determine whether the shutdown operation completed
            // successfully.
            platform.EndShutdown(result);

            UCMASampleHelper.WriteLine("The platform is now shut down.");
        }
Beispiel #3
0
        /// <summary>
        /// Callback from <code>BeginStartup</code> method on platform.
        /// </summary>
        /// <param name="result">
        /// Status of the platform startup operation.
        /// </param>
        private void PlatformStartupCompleted(IAsyncResult result)
        {
            // Extract the platform that was passed in as the state argument to
            // the BeginStartup() method.
            CollaborationPlatform platform = result.AsyncState as CollaborationPlatform;

            if (platform == null)
            {
                UCMASampleHelper.WriteErrorLine("CollaborationPlatform not passed into BeginStartup() method.");
                UCMASampleHelper.FinishSample();
                return;
            }

            try
            {
                // Determine whether the startup operation completed
                // successfully.
                platform.EndStartup(result);

                UCMASampleHelper.WriteLine("Platform has been started.");
            }
            catch (TlsFailureException tlsFailureException)
            {
                // TlsFailureException will be thrown if the certificate used to
                // startup the platform is invalid or otherwise unusable.
                // TODO (Left to the reader): Error handling code to either
                // retry the platform startup operation with a different
                // certificate, log the error for debugging, or gracefully exit
                // the program.
                UCMASampleHelper.WriteException(tlsFailureException);
                UCMASampleHelper.FinishSample();
            }
            catch (ConnectionFailureException connectionFailureException)
            {
                // ConnectionFailureException will be thrown when the platform
                // could not listen on any of the configured IP/port
                // combinations.
                // TODO (Left to the reader): Error handling code to notify user
                // the configured IP address cannot be used or some other
                // process is already using the port, log the error for
                // debugging, or gracefully exit the program.
                UCMASampleHelper.WriteException(connectionFailureException);
                UCMASampleHelper.FinishSample();
            }
            catch (RealTimeException realTimeException)
            {
                // RealTimeException will be thrown when the platform startup
                // operation failed for some other reason.
                // TODO (Left to the reader): Error handling code to notify user
                // the configured IP address cannot be used or some other
                // process is already using the port, log the error for
                // debugging, or gracefully exit the program.
                UCMASampleHelper.WriteException(realTimeException);
                UCMASampleHelper.FinishSample();
            }
            try
            {
                // Create the ApplicationEndpointSettings.
                _endpointSettings = new ApplicationEndpointSettings(_endpointOwnerURI,
                                                                    _registrarFQDN,
                                                                    _registrarPort);

                // Create the ApplicationEndpoint from the
                // ApplicationEndpointSettings and bind it to the platform.
                _endpoint = new ApplicationEndpoint(platform, _endpointSettings);

                // Bind an event handler to notify when the endpoint changes
                // state.
                _endpoint.StateChanged += new EventHandler <LocalEndpointStateChangedEventArgs>(
                    _endpoint_StateChanged);

                // Establish the endpoint so that it can receive incoming calls
                // and conference invitations. EndEndpointEstablish()  will be
                // called when the endpoint finishes establishment.
                _endpoint.BeginEstablish(EndpointEstablishmentCompleted, _endpoint);

                UCMASampleHelper.WriteLine("Endpoint has been established.");
            }
            catch (ArgumentNullException argumentNullException)
            {
                // ArgumentNullException will be thrown if the parameters used to
                // construct ApplicationEndpointSettings or ApplicationEndpoint
                // are null.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the endpoint with non-null parameters, log the
                // error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(argumentNullException);
                UCMASampleHelper.FinishSample();
            }
            catch (ArgumentException argumentException)
            {
                // ArgumentException will be thrown if the parameters used to
                // construct ApplicationEndpointSettings or ApplicationEndpoint
                // are invalid.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the endpoint with corrected parameters, log
                // the error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(argumentException);
                UCMASampleHelper.FinishSample();
            }
            catch (InvalidOperationException invalidOperationException)
            {
                // InvalidOperationException will be thrown if the platform is
                // already shutdown, an endpoint with the same SIP URI already
                // exists, or the endpoint has already been established or
                // terminated.
                // TODO (Left to the reader): Error handling code to log the
                // error for debugging.
                UCMASampleHelper.WriteException(invalidOperationException);
                UCMASampleHelper.FinishSample();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Retrieves the application configuration and begins starting up the
        /// platform.
        /// </summary>
        private void Run()
        {
            // Prompt for the settings necessary to initialize the
            // CollaborationPlatform and the ApplicationEndpoint if they are
            // not declared in App.config.
            // TODO (Left to the reader): Input sanitization on the
            // collected parameters.
            _applicationHostFQDN = UCMASampleHelper.PromptUser(
                "Please enter the FQDN assigned to this computer in the trusted application pool => ",
                "TrustedAppComputerFQDN");
            if (string.IsNullOrEmpty(_applicationHostFQDN))
            {
                UCMASampleHelper.WriteErrorLine(
                    "No FQDN was found in App.config or input by the user.");
            }
            string inputPort = UCMASampleHelper.PromptUser(
                "Please enter the port assigned to this trusted application => ",
                "TrustedAppPort");

            if (!int.TryParse(inputPort, out _applicationHostPort))
            {
                UCMASampleHelper.WriteErrorLine(
                    "Port could not be parsed from App.config or from input by the user.");
            }
            _computerGRUU = UCMASampleHelper.PromptUser(
                "Please enter the GRUU assigned to this computer for this trusted application => ",
                "TrustedAppComputerGRUU");
            if (string.IsNullOrEmpty(_computerGRUU))
            {
                UCMASampleHelper.WriteErrorLine("No GRUU was found in App.config or input by the user.");
            }
            _certificateFriendlyName = UCMASampleHelper.PromptUser(
                "Please enter the friendly name of the certificate identifying this computer => ",
                "CertificateFriendlyName");
            if (string.IsNullOrEmpty(_certificateFriendlyName))
            {
                UCMASampleHelper.WriteErrorLine(
                    "No certificate friendly name was found in App.config or input by the user.");
            }
            _certificate = UCMASampleHelper.GetLocalCertificate(_certificateFriendlyName);
            if (_certificate == null)
            {
                UCMASampleHelper.WriteErrorLine("Certificate with friendly name '" + _certificateFriendlyName
                                                + "' could not be found in computer account Personal certificate store.");
            }
            _endpointOwnerURI = UCMASampleHelper.PromptUser(
                "Please enter the SIP URI assigned to this trusted application endpoint => ",
                "TrustedAppEpOwnerURI");
            if (string.IsNullOrEmpty(_endpointOwnerURI))
            {
                UCMASampleHelper.WriteErrorLine("No SIP URI was found in App.config or input by the user.");
            }
            _registrarFQDN = UCMASampleHelper.PromptUser(
                "Please enter the FQDN of the registrar pool  to which this endpoint is assigned => ",
                "RegistrarFQDN");
            if (string.IsNullOrEmpty(_registrarFQDN))
            {
                UCMASampleHelper.WriteErrorLine(
                    "No registrar pool FQDN was found in App.config or input by the user.");
            }
            string inputRegistrarPort = UCMASampleHelper.PromptUser(
                "Please enter the port used by the registrar pool to which this endpoint is assigned => ",
                "RegistrarPort");

            if (!int.TryParse(inputRegistrarPort, out _registrarPort))
            {
                UCMASampleHelper.WriteErrorLine(
                    "Registrar port could not be parsed from App.config or from input by the user.");
            }

            try
            {
                // Create the CollaborationPlatform using the
                // ServerPlatformSettings.
                _platformSettings = new ServerPlatformSettings(_applicationUserAgent,
                                                               _applicationHostFQDN,
                                                               _applicationHostPort,
                                                               _computerGRUU,
                                                               _certificate);
                _platform = new CollaborationPlatform(_platformSettings);

                // Initialize and startup the platform. EndPlatformStartup()
                // will be called when the platform finishes starting up.
                UCMASampleHelper.WriteLine("Starting platform...");
                _platform.BeginStartup(PlatformStartupCompleted, _platform);
            }
            catch (ArgumentNullException argumentNullException)
            {
                // ArgumentNullException will be thrown if the parameters used
                // to construct ServerPlatformSettings or CollaborationPlatform
                // are null.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the platform with non-null parameters, log the
                // error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(argumentNullException);
                UCMASampleHelper.FinishSample();
            }
            catch (ArgumentOutOfRangeException argumentOutOfRangeException)
            {
                // ArgumentOutOfRangeException will be thrown if the port
                // parameter used to construct ServerPlatformSettings is greater
                // than 65536 or less than 0.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the platform with a valid port, log the error
                // for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(argumentOutOfRangeException);
                UCMASampleHelper.FinishSample();
            }
            catch (ArgumentException argumentException)
            {
                // ArgumentException will be thrown if the parameters used to
                // construct ServerPlatformSettings or CollaborationPlatform are
                // invalid.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the platform with corrected parameters, log
                // the error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(argumentException);
                UCMASampleHelper.FinishSample();
            }
            catch (TlsFailureException tlsFailureException)
            {
                // TlsFailureException will be thrown if the certificate used to
                // construct CollaborationPlatform is invalid or otherwise
                // unusable.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the platform with a valid certificate, log the
                // error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(tlsFailureException);
                UCMASampleHelper.FinishSample();
            }
            catch (CryptographicException cryptographicException)
            {
                // CryptographicException will be thrown if the certificate used
                // to construct ServerPlatformSettings is invalid.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the platform with a valid certificate, log the
                // error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(cryptographicException);
                UCMASampleHelper.FinishSample();
            }
            catch (InvalidOperationException invalidOperationException)
            {
                // InvalidOperationException will be thrown if the platform has
                // already been started or shutdown.
                // TODO (Left to the reader): Error handling code to log the
                // error for debugging.
                UCMASampleHelper.WriteException(invalidOperationException);
                UCMASampleHelper.FinishSample();
            }
            finally
            {
                // Wait for the sample to finish before shutting down the
                // platform and returning from the main thread.
                UCMASampleHelper.WaitForSampleFinish();

                // It is possible the platform was never created due to issues
                // collecting configuration parameters.
                if (_platform != null)
                {
                    // Shutdown the platform, thereby terminating any attached
                    // endpoints.
                    UCMASampleHelper.WriteLine("Shutting down the platform...");
                    _platform.BeginShutdown(PlatformShutdownCompleted, _platform);
                }
            }
        }