// Registered event handler for the ApplicationEndpointOwnerDiscovered // event on the // CollaborationPlatform for the provisioned application. private void Platform_ApplicationEndpointOwnerDiscovered(object sender, ApplicationEndpointSettingsDiscoveredEventArgs e) { UCMASampleHelper.WriteLine("ApplicationEndpointOwnerDiscovered event was raised during startup of" + " the CollaborationPlatform."); UCMASampleHelper.WriteLine("The ApplicationEndpointOwnerConfiguration that corresponds to the" + " provisioned application with ID " + _applicationId + " are: "); UCMASampleHelper.WriteLine("Owner display name is: " + e.ApplicationEndpointSettings.OwnerDisplayName); UCMASampleHelper.WriteLine("Owner URI is: " + e.ApplicationEndpointSettings.OwnerUri); UCMASampleHelper.WriteLine("Now retrieving the ApplicationEndpointSettings from the " + "ApplicationEndpointSettingsDiscoveredEventArgs."); ApplicationEndpointSettings settings = e.ApplicationEndpointSettings; settings.SupportedMimePartContentTypes = new System.Net.Mime.ContentType[] { new System.Net.Mime.ContentType("text/plain") }; UCMASampleHelper.WriteLine("Initializing the ApplicationEndpoint that corresponds to the provisioned " + "application with ID " + _applicationId); // Initalize the endpoint using the settings retrieved above. _applicationEndpoint = new ApplicationEndpoint(_collabPlatform, settings); // Wire up the StateChanged event if necessary // Wire up the ApplicationEndpointOwnerPropertiesChanged event if necessary try { // Establish the endpoint. _applicationEndpoint.BeginEstablish(EndEndpointEstablish, _applicationEndpoint); } catch (InvalidOperationException iOpEx) { // Invalid Operation Exception may be thrown if the data provided // to the BeginXXX methods was invalid/malformed. // TODO (Left to the reader): Error handling code. UCMASampleHelper.WriteLine("Invalid Operation Exception: " + iOpEx.ToString()); } }
/// <summary> /// Returns an application endpoint that is provisioned on a platform /// as specified by the ApplicationID which could be provided by config /// file or be prompted to the user; if the platform discovers multiple /// application endpoints the first one discovered and established will be /// returned. If no application endpoints are discovered this method /// returns null. /// </summary> /// <returns></returns> public ApplicationEndpoint CreateAutoProvisionedApplicationEndpoint() { _applicationId = null; try { // Attempt to retrieve the application ID of the provisioned // application from the config file. _applicationId = System.Configuration.ConfigurationManager.AppSettings["ApplicationID"]; if (string.IsNullOrEmpty(_applicationId)) { // The application ID wasn't retrieved from the config file // so prompt for the application ID for the application that // has been provisioned. string prompt = "Please enter the unique ID of the application that is provisioned in " + "the topology => "; _applicationId = UCMASampleHelper.PromptUser(prompt, null); } if (!string.IsNullOrEmpty(_applicationId)) { UCMASampleHelper.WriteLine("Creating CollaborationPlatform for the provisioned application" + " with ID \'" + _applicationId + "\' using ProvisionedApplicationPlatformSettings."); ProvisionedApplicationPlatformSettings settings = new ProvisionedApplicationPlatformSettings("UCMASampleApp", _applicationId); // Reuse platform instance so that all endpoints share the // same platform. if (_collabPlatform == null) { // Initalize and startup the platform. _collabPlatform = new CollaborationPlatform(settings); // Wire up a handler for the // ApplicationEndpointOwnerDiscovered event. _collabPlatform.RegisterForApplicationEndpointSettings( this.Platform_ApplicationEndpointOwnerDiscovered); // Initalize and startup the platform. _collabPlatform.BeginStartup(EndPlatformStartup, _collabPlatform); if (_endpointInitCompletedEvent.WaitOne()) { UCMASampleHelper.WriteLine("Found an application EP the Owner Uri is: " + _applicationEndpoint.OwnerUri); } else { Console.WriteLine("Application endpoint was not established within the given time," + " ending Sample."); UCMASampleHelper.FinishSample(); } } else { Console.WriteLine("Collaboration platform already exists, ending Sample."); UCMASampleHelper.FinishSample(); } } else { Console.WriteLine("No application ID was specified by the user. Unable to create an" + " ApplicationEndpoint to use in the sample."); UCMASampleHelper.FinishSample(); } return(_applicationEndpoint); } catch (InvalidOperationException iOpEx) { // Invalid Operation Exception may be thrown if the data provided // to the BeginStartUp is called when the platform has already been // started or terminated. // TODO (Left to the reader): Error handling code. UCMASampleHelper.WriteException(iOpEx); return(_applicationEndpoint); } }