protected SPContentDatabase GetCurrentContentDatabase(SPWebApplication webApp, ContentDatabaseDefinition definition)
        {
            var dbName = definition.DbName.ToUpper();

            return webApp.ContentDatabases.OfType<SPContentDatabase>()
                                          .FirstOrDefault(d => !string.IsNullOrEmpty(d.Name) && d.Name.ToUpper() == dbName);
        }
        private void DeployContentDatabase(WebApplicationModelHost modelHost, SPWebApplication webApp, ContentDatabaseDefinition definition)
        {
            var existringDb = GetCurrentContentDatabase(webApp, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = existringDb,
                ObjectType = typeof(SPContentDatabase),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            if (existringDb == null)
            {
                existringDb = webApp.ContentDatabases.Add(
                    definition.ServerName,
                    definition.DbName,
                    definition.UserName,
                    definition.UserPassword,
                    definition.WarningSiteCollectionNumber,
                    definition.MaximumSiteCollectionNumber,
                    definition.Status);

                existringDb.Update(true);
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = existringDb,
                ObjectType = typeof(SPContentDatabase),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });
        }
 public static ModelNode AddContentDatabase(this ModelNode model, ContentDatabaseDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
 public static ModelNode AddContentDatabase(this ModelNode model, ContentDatabaseDefinition definition)
 {
     return AddContentDatabase(model, definition, null);
 }