/// <summary> /// Creates the service application. /// </summary> private void CreateApplication() { using (SPLongOperation operation = new SPLongOperation(this)) { operation.LeadingHTML = HttpContext.GetGlobalResourceObject("NVRConfigService.ServiceAdminResources", "CreateOperationLeadingHtml", CultureInfo.CurrentCulture).ToString(); operation.TrailingHTML = HttpContext.GetGlobalResourceObject("NVRConfigService.ServiceAdminResources", "CreateOperationTrailingHtml", CultureInfo.CurrentCulture).ToString(); operation.Begin(); try { NVRConfigService service = NVRConfigService.GetOrCreateService(); ConfigServiceProxy serviceProxy = ConfigServiceProxy.GetOrCreateServiceProxy(); // Create the application pool IisWebServiceApplicationPoolSection applicationPoolSectionCasted = this.applicationPoolSection as IisWebServiceApplicationPoolSection; SPIisWebServiceApplicationPool applicationPool = applicationPoolSectionCasted.GetOrCreateApplicationPool(); // Create the service application ConfigServiceApplication application = new ConfigServiceApplication( this.textBoxServiceName.Text.Trim(), service, applicationPool); application.Update(); application.Provision(); // Create the service application proxy ConfigServiceApplicationProxy proxy = new ConfigServiceApplicationProxy( string.Format( CultureInfo.CurrentCulture, HttpContext.GetGlobalResourceObject("NVRConfigService.ServiceAdminResources", "ServiceApplicationProxyNameTemplate", CultureInfo.CurrentCulture).ToString(), this.textBoxServiceName.Text.Trim()), serviceProxy, application.Uri); proxy.Update(); proxy.Provision(); if (this.checkBoxIncludeInDefaultProxy.Checked) { SPServiceApplicationProxyGroup group = SPServiceApplicationProxyGroup.Default; group.Add(proxy); group.Update(); } operation.EndScript("window.frameElement.commitPopup();"); } catch (Exception ex) { SPUtility.TransferToErrorPage(ex.ToString()); } } }
/// <summary> /// This method gets invoked when the command is called /// </summary> protected override void InternalProcessRecord() { SPIisWebServiceApplicationPool resolvedApplicationPool = this.ApplicationPool.Read(); if (resolvedApplicationPool == null) { this.ThrowTerminatingError(new InvalidOperationException("Could not find the specified application pool."), ErrorCategory.InvalidOperation, this); } if (this.ShouldProcess(this.Name)) { // Get or create the service NVRConfigService service = NVRConfigService.GetOrCreateService(); // Get or create the service proxy ConfigServiceProxy.GetOrCreateServiceProxy(); // Install the service instances to servers in this farm ConfigServiceInstance.CreateServiceInstances(service); // Create the service application ConfigServiceApplication application = new ConfigServiceApplication(this.Name, service, resolvedApplicationPool); application.Update(); application.Provision(); this.WriteObject(application); } }