/// <summary> /// ValidateDatabase event. /// </summary> /// <param name="sender">The Sender.</param> /// <param name="e">The EventArgs.</param> protected void ValidateDatabase(object sender, ServerValidateEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } ContentDatabaseSection databaseSection = this.databaseSection as ContentDatabaseSection; this.databaseParameters = SPDatabaseParameters.CreateParameters( databaseSection.DatabaseName, databaseSection.DatabaseServer, databaseSection.UseWindowsAuthentication ? null : databaseSection.DatabaseUserName, databaseSection.UseWindowsAuthentication ? null : databaseSection.DatabasePassword, databaseSection.FailoverDatabaseServer, SPDatabaseParameterOptions.None); // Validate the database - There are several options: // SPDatabaseValidation.None = Don't do any validation. Useful if you want to allow a user to specify a database that already exists. // SPDatabaseValidation.CreateNew = Throws an exception if a database with the same name already exists. Useful if you don't want to allow specifiying an existing database. // SPDatabaseValidation.AttachExisting = Throws an exception if a database with the given name does not exist. Useful on screens where you edit the db credentials and want to ensure the db exists first. if (databaseSection.DisplayMode == ContentDatabaseSectionMode.Default) { this.databaseParameters.Validate(SPDatabaseValidation.None); } else { this.databaseParameters.Validate(SPDatabaseValidation.AttachExisting); } // If the code did not throw above, then everything should be valid. e.IsValid = true; }
/// <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> /// CreateApplication method override /// </summary> public SPServiceApplication CreateApplication(string name, Type serviceApplicationType, SPServiceProvisioningContext provisioningContext) { if (null == provisioningContext) { throw new ArgumentNullException("provisioningContext"); } if (serviceApplicationType != typeof(IdentityServiceApplication)) { throw new NotSupportedException(); } IdentityServiceApplication application = this.Farm.GetObject(name, this.Id, serviceApplicationType) as IdentityServiceApplication; if (null == application) { SPDatabaseParameters databaseParameters = SPDatabaseParameters.CreateParameters(name, SPDatabaseParameterOptions.None); databaseParameters.Validate(SPDatabaseValidation.CreateNew); application = IdentityServiceApplication.Create(name, this, provisioningContext.IisWebServiceApplicationPool, databaseParameters); } return(application); }
/// <summary> /// ValidateUniqueName method implementation /// </summary> /* protected void ValidateUniqueClaimName(object sender, ServerValidateEventArgs e) * { * ArgumentValidator.IsNotNull(e, "e"); * string name = this.txtInputFormTextClaimName.Text.Trim(); * e.IsValid = Utilities.DoesClaimProviderIsValid(name, this.InputClaimProviderDropBox.SelectedValue); * } */ /// <summary> /// DatabaseSubmitted method implementation /// </summary> protected void DatabaseSubmitted(object source, ServerValidateEventArgs args) { string currentdb = ""; if (this.ServiceApplicationId != Guid.Empty) { if (ServiceApplication.Database == null) { args.IsValid = true; return; } currentdb = ServiceApplication.Database.Name; if (currentdb.ToLowerInvariant().Trim().Equals(args.Value.ToLowerInvariant().Trim())) { args.IsValid = true; return; } } SPDatabaseParameters databaseParameters = null; NetworkCredential cred = null; if (this.DatabaseSection.UseWindowsAuthentication) { cred = CredentialCache.DefaultNetworkCredentials; } else { cred = new NetworkCredential(this.DatabaseSection.DatabaseUserName, this.DatabaseSection.DatabasePassword); } if (this.DatabaseSection.IncludeFailoverDatabaseServer) { databaseParameters = SPDatabaseParameters.CreateParameters(args.Value, this.DatabaseSection.DatabaseServer, cred, this.DatabaseSection.FailoverDatabaseServer, SPDatabaseParameterOptions.None); } else { databaseParameters = SPDatabaseParameters.CreateParameters(args.Value, this.DatabaseSection.DatabaseServer, cred, null, SPDatabaseParameterOptions.None); } ActiveDirectoryIdentityServiceDatabase db = new ActiveDirectoryIdentityServiceDatabase(databaseParameters); args.IsValid = !db.Exists || this.CBReplaceDB.Checked; }