private void CreateAndStartServerPlatform() { var certToUse = GetLocalCertificate(_certificateFriendlyName); ServerPlatformSettings serverPlatformSettings = new ServerPlatformSettings(_applicationName, _applicationHostFQDN, _applicationPort, _applicationGruu, certToUse); _serverCollabPlatform = new CollaborationPlatform(serverPlatformSettings); // Startup the platform. _serverCollabPlatform.BeginStartup(EndPlatformStartup, _serverCollabPlatform); // Sync; wait for the startup to complete. _platformStartupCompleted.WaitOne(); Console.WriteLine("Platform started..."); }
private static ApplicationEndpoint CreateEndPoint(ServerPlatformSettings settings) { CollaborationPlatform collaborationPlatform = new CollaborationPlatform(settings); collaborationPlatform.EndStartup(collaborationPlatform.BeginStartup(null, null)); ApplicationEndpoint result; try { ApplicationEndpoint applicationEndpoint = new ApplicationEndpoint(collaborationPlatform, new ApplicationEndpointSettings(BaseUMconnectivityTester.SipPlatformConnectionManager.OwnerUri)); applicationEndpoint.EndEstablish(applicationEndpoint.BeginEstablish(null, null)); result = applicationEndpoint; } catch (Exception) { collaborationPlatform.EndShutdown(collaborationPlatform.BeginShutdown(null, null)); throw; } return(result); }
public static void Start() { try { var host = Plugin.LyncPlugin.Configuration.GetString("host"); var thumbprint = Plugin.LyncPlugin.Configuration.GetString("thumbprint"); var gruu = Plugin.LyncPlugin.Configuration.GetString("gruu"); var trustPort = Plugin.LyncPlugin.Configuration.GetInt("trustedPort"); var appPort = Plugin.LyncPlugin.Configuration.GetInt("appPort"); var sip = Plugin.LyncPlugin.Configuration.GetString("accountSip"); var platformSettings = new ServerPlatformSettings(UserAgent, host, trustPort, gruu, CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, thumbprint)); Platform = new CollaborationPlatform(platformSettings); AppEndpoint = new ApplicationEndpoint(Platform, new ApplicationEndpointSettings(sip, host, appPort) { UseRegistration = true }); Log("Starting Lync platform."); Platform.EndStartup(Platform.BeginStartup(null, null)); Log("Lync platform started."); AppEndpoint.EndEstablish(AppEndpoint.BeginEstablish(null, null)); UserEndpoint = new UserEndpoint(Platform, new UserEndpointSettings(sip, host, appPort) { AutomaticPresencePublicationEnabled = true }); UserEndpoint.EndEstablish(UserEndpoint.BeginEstablish(null, null)); RemotePresence = new RemotePresenceView(UserEndpoint, new RemotePresenceViewSettings()); RemotePresence.PresenceNotificationReceived += PresenceNotificationReceived; } catch (Exception ex) { Error(ex.Message); } }
/// <summary> /// Setup Collaboration Platform /// </summary> private void StartPlatform() { try { if (!useUserEndPoint) { string localhost = Dns.GetHostEntry("localhost").HostName; // Config change: for conditional Auto Provisioning. if (this.useApplicationAutoProvisioning) { ProvisionedApplicationPlatformSettings appSettings = new ProvisionedApplicationPlatformSettings("fasthelp", this.applicationId); this.collabPlatform = new CollaborationPlatform(appSettings); this.collabPlatform.RegisterForApplicationEndpointSettings( this.Platform_ApplicationEndpointOwnerDiscovered); } else { ServerPlatformSettings platform = new ServerPlatformSettings(this.applicationName, localhost, this.port, this.gruu, CertificateHelper.GetLocalCertificate(this.certificateName)); platform.TrustedDomains.Add(new TrustedDomain(".fabrikam.com")); this.collabPlatform = new CollaborationPlatform(platform); } Console.WriteLine("Publishing Presence"); } else { // Initalize and startup the platform. ClientPlatformSettings clientPlatformSettings = new ClientPlatformSettings(this.applicationName, this.transportType); this.collabPlatform = new CollaborationPlatform(clientPlatformSettings); } this.logger.Log("Starting the platform."); Console.WriteLine("Starting the platform."); this.collabPlatform.EndStartup(this.collabPlatform.BeginStartup(null, null)); Console.WriteLine("Starting the platform complete."); // Config change: for conditional Auto Provisioning. if (!this.useApplicationAutoProvisioning) { this.StartEndpoint(); } } catch (InvalidOperationException ioe) { Console.WriteLine(ioe.ToString()); } catch (ConnectionFailureException connFailEx) { // ConnectionFailureException will be thrown when the platform cannot connect Console.WriteLine(connFailEx.ToString()); this.logger.Log("Connection Failure Exception {0}", connFailEx); } catch (ProvisioningFailureException provFailEx) { // ProvisioningFailureException will be thrown when the platform cannot find the trusted application // entry per the application ID passed in ProvisionedApplicationPlatformSettings. Console.WriteLine(provFailEx.ToString()); this.logger.Log("Provisioning Failure Exception {0}", provFailEx); } catch (RealTimeException rte) { Console.WriteLine(rte); this.logger.Log("Platform failed to start {0}", rte); } }
/// <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); } } }