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
            });
        }
        private void DeployDefinition(WebApplicationModelHost modelHost, SPWebApplication webApp, WebConfigModificationDefinition definition)
        {
            var existingWebConfig = GetCurrentSPWebConfigModification(webApp, definition);

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

            if (existingWebConfig != null)
                webApp.WebConfigModifications.Remove(existingWebConfig);

            existingWebConfig = new SPWebConfigModification();

            MapConfig(existingWebConfig, definition);

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

            webApp.WebConfigModifications.Add(existingWebConfig);
            webApp.Update();

            //webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
            webApp.WebService.ApplyWebConfigModifications();
        }
Esempio n. 3
0
        private void DeploySite(WebApplicationModelHost webAppModelHost, Microsoft.SharePoint.Administration.SPWebApplication webApp, SiteDefinition siteModel)
        {
            var existingSite = GetExistingSite(webApp, siteModel);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = existingSite,
                ObjectType = typeof(SPSite),
                ObjectDefinition = siteModel,
                ModelHost = webAppModelHost
            });

            // while crating new site collection, a fall back for the secondlogin to mainowner
            // SecondaryContact setup is also checked on null and ignored is empty
            // https://github.com/SubPointSolutions/spmeta2/issues/835

            if (existingSite == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new site");

                var siteCollectionUrl = SPUrlUtility.CombineUrl(siteModel.PrefixName, siteModel.Url);
                siteCollectionUrl = siteCollectionUrl.TrimEnd('/');

                SPSite newSite = null;

                if (string.IsNullOrEmpty(siteModel.DatabaseName))
                {
                    newSite = webApp.Sites.Add(siteCollectionUrl,
                        siteModel.Name,
                        siteModel.Description ?? string.Empty,
                        siteModel.LCID,
                        siteModel.SiteTemplate,

                        siteModel.OwnerLogin,
                        siteModel.OwnerName,
                        siteModel.OwnerEmail,

                        siteModel.SecondaryContactLogin,
                        siteModel.SecondaryContactName,
                        siteModel.SecondaryContactEmail);
                }
                else
                {
                    // TODO, should be reimplemented later to handle more complicatd content DB provision
                    var dbServerName = webApp.ContentDatabases[0].Server;

                    newSite = webApp.Sites.Add(siteCollectionUrl,
                        siteModel.Name,
                        siteModel.Description,
                        siteModel.LCID,
                        siteModel.SiteTemplate,

                        siteModel.OwnerLogin,
                        siteModel.OwnerName,
                        siteModel.OwnerEmail,

                        siteModel.SecondaryContactLogin,
                        siteModel.SecondaryContactName,
                        siteModel.SecondaryContactEmail,

                        dbServerName,
                        siteModel.DatabaseName,

                        null,
                        null);
                }

                // weird issue with second admin, needs to be setup manually
                if (!string.IsNullOrEmpty(siteModel.SecondaryContactLogin))
                {
                    newSite.SecondaryContact = newSite.RootWeb.EnsureUser(siteModel.SecondaryContactLogin);
                }

                existingSite = GetExistingSite(webApp, siteModel);
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing XXX");
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = existingSite,
                ObjectType = typeof(SPSite),
                ObjectDefinition = siteModel,
                ModelHost = webAppModelHost
            });
        }
Esempio n. 4
0
        private void DeploySite(WebApplicationModelHost webAppModelHost, Microsoft.SharePoint.Administration.SPWebApplication webApp, SiteDefinition siteModel)
        {
            var existingSite = GetExistingSite(webApp, siteModel);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = existingSite,
                ObjectType = typeof(SPSite),
                ObjectDefinition = siteModel,
                ModelHost = webAppModelHost
            });

            if (existingSite == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new site");

                var siteCollectionUrl = SPUrlUtility.CombineUrl(siteModel.PrefixName, siteModel.Url);

                if (string.IsNullOrEmpty(siteModel.DatabaseName))
                {
                    var newSite = webApp.Sites.Add(siteCollectionUrl,
                        siteModel.Name,
                        siteModel.Description,
                        siteModel.LCID,
                        siteModel.SiteTemplate,

                        siteModel.OwnerLogin,
                        siteModel.OwnerName,
                        siteModel.OwnerEmail,

                        siteModel.SecondaryContactLogin,
                        siteModel.SecondaryContactName,
                        siteModel.SecondaryContactEmail);

                    // weird issue with second admin, needs to be setup manually
                    newSite.SecondaryContact = newSite.RootWeb.EnsureUser(siteModel.SecondaryContactLogin);
                }
                else
                {
                    // TODO, should be reimplemented later.
                    var dbServerName = webApp.ContentDatabases[0].Server;

                    var newSite = webApp.Sites.Add(siteCollectionUrl,
                        siteModel.Name,
                        siteModel.Description,
                        siteModel.LCID,
                        siteModel.SiteTemplate,

                        siteModel.OwnerLogin,
                        siteModel.OwnerName,
                        siteModel.OwnerEmail,

                        siteModel.SecondaryContactLogin,
                        siteModel.SecondaryContactName,
                        siteModel.SecondaryContactEmail,

                        dbServerName,
                        siteModel.DatabaseName,
                        null,
                        null);

                    // weird issue with second admin, needs to be setup manually
                    newSite.SecondaryContact = newSite.RootWeb.EnsureUser(siteModel.SecondaryContactLogin);
                }

                existingSite = GetExistingSite(webApp, siteModel);
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing XXX");
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = existingSite,
                ObjectType = typeof(SPSite),
                ObjectDefinition = siteModel,
                ModelHost = webAppModelHost
            });


        }