/// <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 ClubCloudService service = ClubCloudService.GetOrCreateService(); // Get or create the service proxy ClubCloudServiceProxy.GetOrCreateServiceProxy(); // Install the service instances to servers in this farm ClubCloudServiceInstance.CreateServiceInstances(service); // Create the service application ClubCloudServiceApplication application = new ClubCloudServiceApplication(this.Name, service, resolvedApplicationPool); application.Update(); application.Provision(); // Database settings if (string.Equals(this.ParameterSetName, "DB", StringComparison.OrdinalIgnoreCase)) { NetworkCredential databaseCredentials = null; if (this.DatabaseCredentials != null) { databaseCredentials = (NetworkCredential)this.DatabaseCredentials; } SPDatabaseParameters databaseParameters = SPDatabaseParameters.CreateParameters(this.DatabaseName, this.DatabaseServerName, databaseCredentials, this.DatabaseFailoverServerName, SPDatabaseParameterOptions.None); // Create the database ClubCloudDatabase database = new ClubCloudDatabase(databaseParameters); // Provision the database (runs the Create scripts) database.Provision(); // Grant the database the proper permissions database.GrantApplicationPoolAccess(resolvedApplicationPool.ProcessAccount.SecurityIdentifier); // Add the failover server instance (the base class does not do this for you) if (!string.IsNullOrEmpty(this.DatabaseFailoverServerName)) { database.AddFailoverServiceInstance(this.DatabaseFailoverServerName); } // Establish a relationship between the service application and the database application.Database = database; application.Update(); } this.WriteObject(application); } }
/// <summary> /// Creates the service application. /// </summary> private void CreateApplication() { using (SPLongOperation operation = new SPLongOperation(this)) { operation.LeadingHTML = HttpContext.GetGlobalResourceObject("ClubCloud.Service.ServiceAdminResources", "CreateOperationLeadingHtml", CultureInfo.CurrentCulture).ToString(); operation.TrailingHTML = HttpContext.GetGlobalResourceObject("ClubCloud.Service.ServiceAdminResources", "CreateOperationTrailingHtml", CultureInfo.CurrentCulture).ToString(); operation.Begin(); try { ClubCloudService service = ClubCloudService.GetOrCreateService(); ClubCloudServiceProxy serviceProxy = ClubCloudServiceProxy.GetOrCreateServiceProxy(); // Create the application pool IisWebServiceApplicationPoolSection applicationPoolSectionCasted = this.applicationPoolSection as IisWebServiceApplicationPoolSection; SPIisWebServiceApplicationPool applicationPool = applicationPoolSectionCasted.GetOrCreateApplicationPool(); // Create the service application ClubCloudServiceApplication application = new ClubCloudServiceApplication( this.textBoxServiceName.Text.Trim(), service, applicationPool); application.Update(); application.Provision(); // Create the service application proxy ClubCloudServiceApplicationProxy proxy = new ClubCloudServiceApplicationProxy( string.Format( CultureInfo.CurrentCulture, HttpContext.GetGlobalResourceObject("ClubCloud.Service.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() { SPServiceApplication resolvedApplication = null; ClubCloudServiceApplication castedApplication = null; resolvedApplication = this.Identity.Read(); if (resolvedApplication == null) { this.ThrowTerminatingError(new InvalidOperationException("No service application was found."), ErrorCategory.InvalidOperation, this); } castedApplication = resolvedApplication as ClubCloudServiceApplication; if (castedApplication == null) { this.ThrowTerminatingError(new InvalidOperationException("The service application provided was not of the correct type."), ErrorCategory.InvalidOperation, this); } if (this.ShouldProcess(castedApplication.Name)) { // Update the name if (!string.IsNullOrEmpty(this.Name) && (!string.Equals(this.Name.Trim(), castedApplication.Name, StringComparison.OrdinalIgnoreCase))) { // Get the service ClubCloudService service = SPFarm.Local.Services.GetValue <ClubCloudService>(); if (service != null) { // Check for duplicate name SPServiceApplication duplicateApplication = service.Applications[this.Name.Trim()]; if (duplicateApplication != null) { this.ThrowTerminatingError(new InvalidOperationException("A service application with that name already exists."), ErrorCategory.InvalidOperation, this); } } castedApplication.Name = this.Name.Trim(); } // Update the application pool if (this.ApplicationPool != null) { SPIisWebServiceApplicationPool resolvedApplicationPool = this.ApplicationPool.Read(); if (resolvedApplicationPool != null) { castedApplication.ApplicationPool = resolvedApplicationPool; } } if (this.DatabaseCredentials != null) { NetworkCredential databaseCredentials = (NetworkCredential)this.DatabaseCredentials; castedApplication.Database.Username = databaseCredentials.UserName; castedApplication.Database.Password = databaseCredentials.Password; } else if (!string.IsNullOrEmpty(castedApplication.Database.Username)) { castedApplication.Database.Username = null; castedApplication.Database.Password = null; } if (!string.IsNullOrEmpty(this.DatabaseFailoverServerName)) { castedApplication.Database.AddFailoverServiceInstance(this.DatabaseFailoverServerName); } else if (castedApplication.Database.FailoverServer != null) { castedApplication.Database.AddFailoverServiceInstance(null); } castedApplication.Database.Update(); castedApplication.Update(); } }