public override bool Execute() { bool processed = false; string generalSiteDirectoryUrl = GetConfiguration("General.SiteDirectoryUrl"); string generalSiteDirectoryListName = GetConfiguration("General.SiteDirectoryListName"); string generalSiteCollectionUrl = GetConfiguration("General.SiteCollectionUrl"); string generalMailSMTPServer = GetConfiguration("General.MailSMTPServer"); string generalMailUser = GetConfiguration("General.MailUser"); string generalMailUserPassword = GetConfiguration("General.MailUserPassword"); string generalMailSiteAvailable = GetConfiguration("General.MailSiteAvailable"); string generalEncryptionThumbPrint = GetConfiguration("General.EncryptionThumbPrint"); //Decrypt mail password generalMailUserPassword = EncryptionUtility.Decrypt(generalMailUserPassword, generalEncryptionThumbPrint); string contosoCollaborationPromotedSiteName = GetConfiguration("ContosoCollaboration.PromotedSiteName"); string contosoCollaborationPromotedSiteUrl = GetConfiguration("ContosoCollaboration.PromotedSiteUrl"); string contosoCollaborationThemeName = GetConfiguration("ContosoCollaboration.ThemeName"); //On-Prem settings string generalOnPremWebApplication = GetConfiguration("General.OnPremWebApplication"); try { SiteDirectoryManager siteDirectoryManager = new SiteDirectoryManager(); //FeatureManager featureManager = new FeatureManager(); //ListManager listManager = new ListManager(); //PageManager pageManager = new PageManager(); //SecurityManager securityManager = new SecurityManager(); //NavigationManager navigationManager = new NavigationManager(); //BrandingManager brandingManager = new BrandingManager(); string tempSharePointUrl = this.SharePointProvisioningData.Url; string siteCollectionUrl = this.CreateOnPremises ? generalOnPremWebApplication : generalSiteCollectionUrl; // issue the final SharePoint url SharePointProvisioningData.Url = this.GetNextSiteCollectionUrl(generalSiteDirectoryUrl, generalSiteDirectoryListName, siteCollectionUrl); //update site directory status siteDirectoryManager.UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, tempSharePointUrl, this.SharePointProvisioningData.Url, "Provisioning"); //complete the site data this.SharePointProvisioningData.Template = "STS#0"; this.SharePointProvisioningData.SiteOwner = this.SharePointProvisioningData.Owners[0]; this.SharePointProvisioningData.Lcid = 1033; this.SharePointProvisioningData.TimeZoneId = 3; this.SharePointProvisioningData.StorageMaximumLevel = 100; this.SharePointProvisioningData.StorageWarningLevel = 80; //create the site collection this.AddSiteCollection(this.SharePointProvisioningData); //enable features // Document ID Service (DocID) site collection feature this.CreatedSiteContext.Site.ActivateFeature(new Guid("b50e3104-6812-424f-a011-cc90e6327318")); // Search Server Web Parts and Templates (SearchMaster) site collection feature this.CreatedSiteContext.Site.ActivateFeature(new Guid("9c0834e1-ba47-4d49-812b-7d4fb6fea211")); // Workflows (Workflows) site collection feature this.CreatedSiteContext.Site.ActivateFeature(new Guid("0af5989a-3aea-4519-8ab0-85d91abe39ff")); // Metadata Navigation and Filtering (MetaDataNav) site feature this.CreatedSiteContext.Web.ActivateFeature(new Guid("7201d6a4-a5d3-49a1-8c19-19c4bac6e668")); // Community Site Feature (CommunitySite) site feature this.CreatedSiteContext.Web.ActivateFeature(new Guid("961d6a9c-4388-4cf2-9733-38ee8c89afd4")); // Project Functionality (ProjectFunctionality) site feature this.CreatedSiteContext.Web.ActivateFeature(new Guid("e2f2bb18-891d-4812-97df-c265afdba297")); // Picture library called Media this.CreatedSiteContext.Web.AddList(Microsoft.SharePoint.Client.ListTemplateType.PictureLibrary, "Media", false); // Promoted Links library called Links this.CreatedSiteContext.Web.AddList(170, new Guid("192efa95-e50c-475e-87ab-361cede5dd7f"), "Links", false); // Update existing list settings for the documents library and the blog post library this.CreatedSiteContext.Web.UpdateListVersioning("Documents", true); //Remove the "Project Summary" web part this.CreatedSiteContext.Web.DeleteWebPart("SitePages", "Project Summary", "home.aspx"); //Remove the "Get started with your site" web part this.CreatedSiteContext.Web.DeleteWebPart("SitePages", "Get started with your site", "home.aspx"); //Remove the "Documents" web part this.CreatedSiteContext.Web.DeleteWebPart("SitePages", "Documents", "home.aspx"); //Add links web part to the home page Guid linksID = this.CreatedSiteContext.Web.GetListID("Links"); WebPartEntity promotedLinksWP = new WebPartEntity(); promotedLinksWP.WebPartXml = WpPromotedLinks(linksID, string.Format("{0}{1}/Lists/{2}", this.SharePointProvisioningData.Url, this.SharePointProvisioningData.Name, "Links"), string.Format("{0}{1}/SitePages/{2}", this.SharePointProvisioningData.Url, this.SharePointProvisioningData.Name, "home.aspx"), "$Resources:core,linksList"); promotedLinksWP.WebPartIndex = 2; promotedLinksWP.WebPartTitle = "Links"; this.CreatedSiteContext.Web.AddWebPartToWikiPage("SitePages", promotedLinksWP, "home.aspx", 2, 2, false); //Add html to the home page wiki this.CreatedSiteContext.Web.AddHtmlToWikiPage("SitePages", "Hello <strong>SharePoint Conference</strong> from spc403<br/><br/><br/>", "home.aspx", 1, 1); //add additional pages string siteMembersPage = "site members.aspx"; string siteMembersUrl = this.CreatedSiteContext.Web.AddWikiPage("Site Pages", siteMembersPage); this.CreatedSiteContext.Web.AddLayoutToWikiPage("SitePages", WikiPageLayout.TwoColumns, siteMembersPage); //Add site members web parts WebPartEntity wpSiteUsers = new WebPartEntity(); wpSiteUsers.WebPartXml = WpSiteUsers("Site owners", this.CreatedSiteContext.Web.GetGroupID(new Uri(this.SharePointProvisioningData.Url), String.Format("{0} {1}", this.SharePointProvisioningData.Title, "Owners"))); wpSiteUsers.WebPartIndex = 0; wpSiteUsers.WebPartTitle = "Site owners"; this.CreatedSiteContext.Web.AddWebPartToWikiPage("SitePages", wpSiteUsers, siteMembersPage, 1, 1, false); wpSiteUsers.WebPartXml = WpSiteUsers("Site visitors", this.CreatedSiteContext.Web.GetGroupID(new Uri(this.SharePointProvisioningData.Url), String.Format("{0} {1}", this.SharePointProvisioningData.Title, "Visitors"))); wpSiteUsers.WebPartIndex = 1; wpSiteUsers.WebPartTitle = "Site visitors"; this.CreatedSiteContext.Web.AddWebPartToWikiPage("SitePages", wpSiteUsers, siteMembersPage, 1, 1, true); wpSiteUsers.WebPartXml = WpSiteUsers("Site members", this.CreatedSiteContext.Web.GetGroupID(new Uri(this.SharePointProvisioningData.Url), String.Format("{0} {1}", this.SharePointProvisioningData.Title, "Members"))); wpSiteUsers.WebPartIndex = 0; wpSiteUsers.WebPartTitle = "Site members"; this.CreatedSiteContext.Web.AddWebPartToWikiPage("SitePages", wpSiteUsers, siteMembersPage, 1, 2, false); //Update the quick launch navigation //First delete all quicklaunch entries this.CreatedSiteContext.Web.DeleteAllQuickLaunchNodes(); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,nav_Home", null, "", true); //csomService.AddNavigationNode(this.SiteToProvision, "$Resources:core,BlogQuickLaunchTitle", new Uri(this.BlogSite.Url), "News & Trending", true); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:spscore,DiscussionsTab", new Uri(string.Format("{0}/Lists/Community%20Discussion/AllItems.aspx", this.SharePointProvisioningData.Url)), "", true); string notebookPath = string.Format("{0}/SiteAssets/{1} Notebook", this.SharePointProvisioningData.Url, this.SharePointProvisioningData.Title); notebookPath = HttpUtility.UrlPathEncode(notebookPath, false).Replace("/", "%2F"); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,SiteNotebookLink", new Uri(string.Format("{0}/_layouts/15/WopiFrame.aspx?sourcedoc={1}&action=editnew", this.SharePointProvisioningData.Url, notebookPath)), "", true); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,taskList", new Uri(string.Format("{0}/Lists/Tasks/AllItems.aspx", this.SharePointProvisioningData.Url)), "", true); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,calendarList", new Uri(string.Format("{0}/Lists/Calendar/calendar.aspx", this.SharePointProvisioningData.Url)), "", true); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,shareddocuments_Title_15", new Uri(string.Format("{0}/Shared Documents/Forms/AllItems.aspx", this.SharePointProvisioningData.Url)), "", true); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,linksList", new Uri(string.Format("{0}/Lists/Links/Tiles.aspx", this.SharePointProvisioningData.Url)), "", true); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,GrpMedia", new Uri(string.Format("{0}/Media/Forms/Thumbnails.aspx", this.SharePointProvisioningData.Url)), "", true); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:spscore,Members_QuickLaunch", new Uri(string.Format("{0}/{1}", this.SharePointProvisioningData.Url, siteMembersUrl)), "", true); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,category_SiteContents", new Uri(string.Format("{0}/_layouts/15/viewlsts.aspx", this.SharePointProvisioningData.Url)), "", true); // Insert demo promoted links list item if (contosoCollaborationPromotedSiteName.Length > 0 || contosoCollaborationPromotedSiteUrl.Length > 0) { AddPromotedSiteLink(this.CreatedSiteContext, this.CreatedSiteContext.Web, "Links", contosoCollaborationPromotedSiteName, contosoCollaborationPromotedSiteUrl); } if (!this.CreateOnPremises) { // add owners to site collection administrators string[] ownerLogins = new string[this.SharePointProvisioningData.Owners.Length]; int i = 0; foreach (SharePointUser owner in this.SharePointProvisioningData.Owners) { ownerLogins[i] = owner.Login; i++; } this.AppOnlyClientContext.Web.AddAdministratorsTenant(ownerLogins, new Uri(this.SharePointProvisioningData.Url)); // Everyone reader this.CreatedSiteContext.Web.AddReaderAccess(); } // Apply themes string themeRoot = Path.Combine(this.AppRootPath, String.Format(@"Themes\{0}", contosoCollaborationThemeName)); string spColorFile = Path.Combine(themeRoot, string.Format("{0}.spcolor", contosoCollaborationThemeName)); string spFontFile = Path.Combine(themeRoot, string.Format("{0}.spfont", contosoCollaborationThemeName)); string backgroundFile = Path.Combine(themeRoot, string.Format("{0}bg.jpg", contosoCollaborationThemeName)); string logoFile = Path.Combine(themeRoot, string.Format("{0}logo.png", contosoCollaborationThemeName)); this.CreatedSiteContext.Web.DeployThemeToWeb(contosoCollaborationThemeName, spColorFile, spFontFile, backgroundFile, ""); this.CreatedSiteContext.Web.SetThemeToWeb(contosoCollaborationThemeName); //Seems to be broken at the moment...to be investigated //brandingManager.SetSiteLogo(this.CreatedSiteContext, this.CreatedSiteContext.Web, logoFile); // Update status siteDirectoryManager.UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, this.SharePointProvisioningData.Url, "Available"); // Send mail to owners List<String> mailTo = new List<string>(); string ownerNames = ""; string ownerAccounts = ""; foreach (SharePointUser owner in this.SharePointProvisioningData.Owners) { mailTo.Add(owner.Email); if (ownerNames.Length > 0) { ownerNames = ownerNames + ", "; ownerAccounts = ownerAccounts + ", "; } ownerNames = ownerNames + owner.Name; ownerAccounts = ownerAccounts + owner.Login; } // send email to notify the use of successful provisioning string mailBody = String.Format(generalMailSiteAvailable, this.SharePointProvisioningData.Title, this.SharePointProvisioningData.Url, ownerNames, ownerAccounts); MailUtility.SendEmail(generalMailSMTPServer, generalMailUser, generalMailUserPassword, mailTo, null, "Your SharePoint site is ready to be used", mailBody); } catch (Exception ex) { //log error new SiteDirectoryManager().UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, this.SharePointProvisioningData.Url, "Error during provisioning", ex); } return processed; }
public override bool Execute() { bool processed = false; string generalSiteDirectoryUrl = RoleEnvironment.GetConfigurationSettingValue("General.SiteDirectoryUrl"); string generalSiteDirectoryListName = RoleEnvironment.GetConfigurationSettingValue("General.SiteDirectoryListName"); string generalSiteCollectionUrl = RoleEnvironment.GetConfigurationSettingValue("General.SiteCollectionUrl"); string generalMailSMTPServer = RoleEnvironment.GetConfigurationSettingValue("General.MailSMTPServer"); string generalMailUser = RoleEnvironment.GetConfigurationSettingValue("General.MailUser"); string generalMailUserPassword = RoleEnvironment.GetConfigurationSettingValue("General.MailUserPassword"); string generalMailSiteAvailable = RoleEnvironment.GetConfigurationSettingValue("General.MailSiteAvailable"); string generalEncryptionThumbPrint = RoleEnvironment.GetConfigurationSettingValue("General.EncryptionThumbPrint"); //Decrypt mail password generalMailUserPassword = EncryptionUtility.Decrypt(generalMailUserPassword, generalEncryptionThumbPrint); //On-Prem settings string generalOnPremWebApplication = GetConfiguration("General.OnPremWebApplication"); try { SiteDirectoryManager siteDirectoryManager = new SiteDirectoryManager(); string tempSharePointUrl = this.SharePointProvisioningData.Url; string siteCollectionUrl = this.CreateOnPremises ? generalOnPremWebApplication : generalSiteCollectionUrl; // issue the final SharePoint url SharePointProvisioningData.Url = this.GetNextSiteCollectionUrl(generalSiteDirectoryUrl, generalSiteDirectoryListName, siteCollectionUrl); //update site directory status siteDirectoryManager.UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, tempSharePointUrl, this.SharePointProvisioningData.Url, "Provisioning"); //complete the site data this.SharePointProvisioningData.Template = "PROJECTSITE#0"; this.SharePointProvisioningData.SiteOwner = this.SharePointProvisioningData.Owners[0]; this.SharePointProvisioningData.Lcid = 1033; this.SharePointProvisioningData.TimeZoneId = 3; this.SharePointProvisioningData.StorageMaximumLevel = 100; this.SharePointProvisioningData.StorageWarningLevel = 80; //create the site collection this.AddSiteCollection(this.SharePointProvisioningData); // Update status siteDirectoryManager.UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, this.SharePointProvisioningData.Url, "Available"); // Send mail to owners List<String> mailTo = new List<string>(); string ownerNames = ""; string ownerAccounts = ""; foreach (SharePointUser owner in this.SharePointProvisioningData.Owners) { mailTo.Add(owner.Email); if (ownerNames.Length > 0) { ownerNames = ownerNames + ", "; ownerAccounts = ownerAccounts + ", "; } ownerNames = ownerNames + owner.Name; ownerAccounts = ownerAccounts + owner.Login; } // send email to notify the use of successful provisioning string mailBody = String.Format(generalMailSiteAvailable, this.SharePointProvisioningData.Title, this.SharePointProvisioningData.Url, ownerNames, ownerAccounts); MailUtility.SendEmail(generalMailSMTPServer, generalMailUser, generalMailUserPassword, mailTo, null, "Your SharePoint site is ready to be used", mailBody); } catch (Exception ex) { new SiteDirectoryManager().UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, this.SharePointProvisioningData.Url, "Error during provisioning", ex); } return processed; }
public override bool Execute() { bool processed = false; string generalSiteDirectoryUrl = GetConfiguration("General.SiteDirectoryUrl"); string generalSiteDirectoryListName = GetConfiguration("General.SiteDirectoryListName"); string generalSiteCollectionUrl = GetConfiguration("General.SiteCollectionUrl"); string generalMailSMTPServer = GetConfiguration("General.MailSMTPServer"); string generalMailUser = GetConfiguration("General.MailUser"); string generalMailUserPassword = GetConfiguration("General.MailUserPassword"); string generalMailSiteAvailable = GetConfiguration("General.MailSiteAvailable"); string generalEncryptionThumbPrint = GetConfiguration("General.EncryptionThumbPrint"); //Decrypt mail password generalMailUserPassword = EncryptionUtility.Decrypt(generalMailUserPassword, generalEncryptionThumbPrint); string contosoCollaborationPromotedSiteName = GetConfiguration("ContosoCollaboration.PromotedSiteName"); string contosoCollaborationPromotedSiteUrl = GetConfiguration("ContosoCollaboration.PromotedSiteUrl"); string contosoCollaborationThemeName = GetConfiguration("ContosoCollaboration.ThemeName"); //On-Prem settings string generalOnPremWebApplication = GetConfiguration("General.OnPremWebApplication"); try { SiteDirectoryManager siteDirectoryManager = new SiteDirectoryManager(); //FeatureManager featureManager = new FeatureManager(); //ListManager listManager = new ListManager(); //PageManager pageManager = new PageManager(); //SecurityManager securityManager = new SecurityManager(); //NavigationManager navigationManager = new NavigationManager(); //BrandingManager brandingManager = new BrandingManager(); string tempSharePointUrl = this.SharePointProvisioningData.Url; string siteCollectionUrl = this.CreateOnPremises ? generalOnPremWebApplication : generalSiteCollectionUrl; // issue the final SharePoint url SharePointProvisioningData.Url = this.GetNextSiteCollectionUrl(generalSiteDirectoryUrl, generalSiteDirectoryListName, siteCollectionUrl); //update site directory status siteDirectoryManager.UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, tempSharePointUrl, this.SharePointProvisioningData.Url, "Provisioning"); //complete the site data this.SharePointProvisioningData.Template = "STS#0"; this.SharePointProvisioningData.SiteOwner = this.SharePointProvisioningData.Owners[0]; this.SharePointProvisioningData.Lcid = 1033; this.SharePointProvisioningData.TimeZoneId = 3; this.SharePointProvisioningData.StorageMaximumLevel = 100; this.SharePointProvisioningData.StorageWarningLevel = 80; //create the site collection this.AddSiteCollection(this.SharePointProvisioningData); //enable features // Document ID Service (DocID) site collection feature this.CreatedSiteContext.Site.ActivateFeature(new Guid("b50e3104-6812-424f-a011-cc90e6327318")); // Search Server Web Parts and Templates (SearchMaster) site collection feature this.CreatedSiteContext.Site.ActivateFeature(new Guid("9c0834e1-ba47-4d49-812b-7d4fb6fea211")); // Workflows (Workflows) site collection feature this.CreatedSiteContext.Site.ActivateFeature(new Guid("0af5989a-3aea-4519-8ab0-85d91abe39ff")); // Metadata Navigation and Filtering (MetaDataNav) site feature this.CreatedSiteContext.Web.ActivateFeature(new Guid("7201d6a4-a5d3-49a1-8c19-19c4bac6e668")); // Community Site Feature (CommunitySite) site feature this.CreatedSiteContext.Web.ActivateFeature(new Guid("961d6a9c-4388-4cf2-9733-38ee8c89afd4")); // Project Functionality (ProjectFunctionality) site feature this.CreatedSiteContext.Web.ActivateFeature(new Guid("e2f2bb18-891d-4812-97df-c265afdba297")); // Picture library called Media this.CreatedSiteContext.Web.CreateList(Microsoft.SharePoint.Client.ListTemplateType.PictureLibrary, "Media", false); // Promoted Links library called Links this.CreatedSiteContext.Web.CreateList(new Guid("192efa95-e50c-475e-87ab-361cede5dd7f"), 170, "Links", false); // Update existing list settings for the documents library and the blog post library this.CreatedSiteContext.Web.UpdateListVersioning("Documents", true); //Remove the "Project Summary" web part this.CreatedSiteContext.Web.DeleteWebPart("SitePages", "Project Summary", "home.aspx"); //Remove the "Get started with your site" web part this.CreatedSiteContext.Web.DeleteWebPart("SitePages", "Get started with your site", "home.aspx"); //Remove the "Documents" web part this.CreatedSiteContext.Web.DeleteWebPart("SitePages", "Documents", "home.aspx"); //Add links web part to the home page Guid linksID = this.CreatedSiteContext.Web.GetListID("Links"); WebPartEntity promotedLinksWP = new WebPartEntity(); promotedLinksWP.WebPartXml = WpPromotedLinks(linksID, string.Format("{0}{1}/Lists/{2}", this.SharePointProvisioningData.Url, this.SharePointProvisioningData.Name, "Links"), string.Format("{0}{1}/SitePages/{2}", this.SharePointProvisioningData.Url, this.SharePointProvisioningData.Name, "home.aspx"), "$Resources:core,linksList"); promotedLinksWP.WebPartIndex = 2; promotedLinksWP.WebPartTitle = "Links"; this.CreatedSiteContext.Web.AddWebPartToWikiPage("SitePages", promotedLinksWP, "home.aspx", 2, 2, false); //Add html to the home page wiki this.CreatedSiteContext.Web.AddHtmlToWikiPage("SitePages", "Hello <strong>SharePoint Conference</strong> from spc403<br/><br/><br/>", "home.aspx", 1, 1); //add additional pages string siteMembersPage = "site members.aspx"; string siteMembersUrl = this.CreatedSiteContext.Web.AddWikiPage("Site Pages", siteMembersPage); this.CreatedSiteContext.Web.AddLayoutToWikiPage("SitePages", WikiPageLayout.TwoColumns, siteMembersPage); //Add site members web parts WebPartEntity wpSiteUsers = new WebPartEntity(); wpSiteUsers.WebPartXml = WpSiteUsers("Site owners", this.CreatedSiteContext.Web.GetGroupID(String.Format("{0} {1}", this.SharePointProvisioningData.Title, "Owners"))); wpSiteUsers.WebPartIndex = 0; wpSiteUsers.WebPartTitle = "Site owners"; this.CreatedSiteContext.Web.AddWebPartToWikiPage("SitePages", wpSiteUsers, siteMembersPage, 1, 1, false); wpSiteUsers.WebPartXml = WpSiteUsers("Site visitors", this.CreatedSiteContext.Web.GetGroupID(String.Format("{0} {1}", this.SharePointProvisioningData.Title, "Visitors"))); wpSiteUsers.WebPartIndex = 1; wpSiteUsers.WebPartTitle = "Site visitors"; this.CreatedSiteContext.Web.AddWebPartToWikiPage("SitePages", wpSiteUsers, siteMembersPage, 1, 1, true); wpSiteUsers.WebPartXml = WpSiteUsers("Site members", this.CreatedSiteContext.Web.GetGroupID(String.Format("{0} {1}", this.SharePointProvisioningData.Title, "Members"))); wpSiteUsers.WebPartIndex = 0; wpSiteUsers.WebPartTitle = "Site members"; this.CreatedSiteContext.Web.AddWebPartToWikiPage("SitePages", wpSiteUsers, siteMembersPage, 1, 2, false); //Update the quick launch navigation //First delete all quicklaunch entries this.CreatedSiteContext.Web.DeleteAllQuickLaunchNodes(); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,nav_Home", null, "", NavigationType.QuickLaunch); //csomService.AddNavigationNode(this.SiteToProvision, "$Resources:core,BlogQuickLaunchTitle", new Uri(this.BlogSite.Url), "News & Trending", true); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:spscore,DiscussionsTab", new Uri(string.Format("{0}/Lists/Community%20Discussion/AllItems.aspx", this.SharePointProvisioningData.Url)), "", NavigationType.QuickLaunch); string notebookPath = string.Format("{0}/SiteAssets/{1} Notebook", this.SharePointProvisioningData.Url, this.SharePointProvisioningData.Title); notebookPath = HttpUtility.UrlPathEncode(notebookPath, false).Replace("/", "%2F"); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,SiteNotebookLink", new Uri(string.Format("{0}/_layouts/15/WopiFrame.aspx?sourcedoc={1}&action=editnew", this.SharePointProvisioningData.Url, notebookPath)), "", NavigationType.QuickLaunch); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,taskList", new Uri(string.Format("{0}/Lists/Tasks/AllItems.aspx", this.SharePointProvisioningData.Url)), "", NavigationType.QuickLaunch); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,calendarList", new Uri(string.Format("{0}/Lists/Calendar/calendar.aspx", this.SharePointProvisioningData.Url)), "", NavigationType.QuickLaunch); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,shareddocuments_Title_15", new Uri(string.Format("{0}/Shared Documents/Forms/AllItems.aspx", this.SharePointProvisioningData.Url)), "", NavigationType.QuickLaunch); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,linksList", new Uri(string.Format("{0}/Lists/Links/Tiles.aspx", this.SharePointProvisioningData.Url)), "", NavigationType.QuickLaunch); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,GrpMedia", new Uri(string.Format("{0}/Media/Forms/Thumbnails.aspx", this.SharePointProvisioningData.Url)), "", NavigationType.QuickLaunch); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:spscore,Members_QuickLaunch", new Uri(string.Format("{0}/{1}", this.SharePointProvisioningData.Url, siteMembersUrl)), "", NavigationType.QuickLaunch); this.CreatedSiteContext.Web.AddNavigationNode("$Resources:core,category_SiteContents", new Uri(string.Format("{0}/_layouts/15/viewlsts.aspx", this.SharePointProvisioningData.Url)), "", NavigationType.QuickLaunch); // Insert demo promoted links list item if (contosoCollaborationPromotedSiteName.Length > 0 || contosoCollaborationPromotedSiteUrl.Length > 0) { AddPromotedSiteLink(this.CreatedSiteContext, this.CreatedSiteContext.Web, "Links", contosoCollaborationPromotedSiteName, contosoCollaborationPromotedSiteUrl); } if (!this.CreateOnPremises) { // add owners to site collection administrators List <UserEntity> adminLogins = new List <UserEntity>(); int i = 0; foreach (SharePointUser owner in this.SharePointProvisioningData.Owners) { adminLogins.Add(new UserEntity() { Email = owner.Email, LoginName = owner.Login, Title = owner.Name, }); i++; } Tenant tenant = new Tenant(this.AppOnlyClientContext); tenant.AddAdministrators(adminLogins, new Uri(this.SharePointProvisioningData.Url), true); // Everyone reader this.CreatedSiteContext.Web.AddReaderAccess(); } // Apply themes string themeRoot = Path.Combine(this.AppRootPath, String.Format(@"Themes\{0}", contosoCollaborationThemeName)); string spColorFile = Path.Combine(themeRoot, string.Format("{0}.spcolor", contosoCollaborationThemeName)); string spFontFile = Path.Combine(themeRoot, string.Format("{0}.spfont", contosoCollaborationThemeName)); string backgroundFile = Path.Combine(themeRoot, string.Format("{0}bg.jpg", contosoCollaborationThemeName)); string logoFile = Path.Combine(themeRoot, string.Format("{0}logo.png", contosoCollaborationThemeName)); // Deploy theme files to root web, if they are not there and set it as active theme for the site string themeColorFileString = ""; string themeFontFileString = ""; string themeBackgroundImageString = ""; if (!String.IsNullOrEmpty(themeRoot)) { themeColorFileString = this.CreatedSiteContext.Web.UploadThemeFile(themeRoot).ServerRelativeUrl; } if (!String.IsNullOrEmpty(spColorFile)) { themeFontFileString = this.CreatedSiteContext.Web.UploadThemeFile(spColorFile).ServerRelativeUrl; } if (!String.IsNullOrWhiteSpace(backgroundFile)) { themeBackgroundImageString = this.CreatedSiteContext.Web.UploadThemeFile(backgroundFile).ServerRelativeUrl; } this.CreatedSiteContext.Web.CreateComposedLookByUrl(contosoCollaborationThemeName, themeColorFileString, themeFontFileString, themeBackgroundImageString, String.Empty); this.CreatedSiteContext.Web.SetComposedLookByUrl(contosoCollaborationThemeName); //Seems to be broken at the moment...to be investigated //brandingManager.SetSiteLogo(this.CreatedSiteContext, this.CreatedSiteContext.Web, logoFile); // Update status siteDirectoryManager.UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, this.SharePointProvisioningData.Url, "Available"); // Send mail to owners List <String> mailTo = new List <string>(); string ownerNames = ""; string ownerAccounts = ""; foreach (SharePointUser owner in this.SharePointProvisioningData.Owners) { mailTo.Add(owner.Email); if (ownerNames.Length > 0) { ownerNames = ownerNames + ", "; ownerAccounts = ownerAccounts + ", "; } ownerNames = ownerNames + owner.Name; ownerAccounts = ownerAccounts + owner.Login; } // send email to notify the use of successful provisioning string mailBody = String.Format(generalMailSiteAvailable, this.SharePointProvisioningData.Title, this.SharePointProvisioningData.Url, ownerNames, ownerAccounts); MailUtility.SendEmail(generalMailSMTPServer, generalMailUser, generalMailUserPassword, mailTo, null, "Your SharePoint site is ready to be used", mailBody); } catch (Exception ex) { //log error new SiteDirectoryManager().UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, this.SharePointProvisioningData.Url, "Error during provisioning", ex); } return(processed); }
public override bool Execute() { bool processed = false; string generalSiteDirectoryUrl = RoleEnvironment.GetConfigurationSettingValue("General.SiteDirectoryUrl"); string generalSiteDirectoryListName = RoleEnvironment.GetConfigurationSettingValue("General.SiteDirectoryListName"); string generalSiteCollectionUrl = RoleEnvironment.GetConfigurationSettingValue("General.SiteCollectionUrl"); string generalMailSMTPServer = RoleEnvironment.GetConfigurationSettingValue("General.MailSMTPServer"); string generalMailUser = RoleEnvironment.GetConfigurationSettingValue("General.MailUser"); string generalMailUserPassword = RoleEnvironment.GetConfigurationSettingValue("General.MailUserPassword"); string generalMailSiteAvailable = RoleEnvironment.GetConfigurationSettingValue("General.MailSiteAvailable"); string generalEncryptionThumbPrint = RoleEnvironment.GetConfigurationSettingValue("General.EncryptionThumbPrint"); //Decrypt mail password generalMailUserPassword = EncryptionUtility.Decrypt(generalMailUserPassword, generalEncryptionThumbPrint); //On-Prem settings string generalOnPremWebApplication = GetConfiguration("General.OnPremWebApplication"); try { SiteDirectoryManager siteDirectoryManager = new SiteDirectoryManager(); string tempSharePointUrl = this.SharePointProvisioningData.Url; string siteCollectionUrl = this.CreateOnPremises ? generalOnPremWebApplication : generalSiteCollectionUrl; // issue the final SharePoint url SharePointProvisioningData.Url = this.GetNextSiteCollectionUrl(generalSiteDirectoryUrl, generalSiteDirectoryListName, siteCollectionUrl); //update site directory status siteDirectoryManager.UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, tempSharePointUrl, this.SharePointProvisioningData.Url, "Provisioning"); //complete the site data this.SharePointProvisioningData.Template = "PROJECTSITE#0"; this.SharePointProvisioningData.SiteOwner = this.SharePointProvisioningData.Owners[0]; this.SharePointProvisioningData.Lcid = 1033; this.SharePointProvisioningData.TimeZoneId = 3; this.SharePointProvisioningData.StorageMaximumLevel = 100; this.SharePointProvisioningData.StorageWarningLevel = 80; //create the site collection this.AddSiteCollection(this.SharePointProvisioningData); // Update status siteDirectoryManager.UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, this.SharePointProvisioningData.Url, "Available"); // Send mail to owners List <String> mailTo = new List <string>(); string ownerNames = ""; string ownerAccounts = ""; foreach (SharePointUser owner in this.SharePointProvisioningData.Owners) { mailTo.Add(owner.Email); if (ownerNames.Length > 0) { ownerNames = ownerNames + ", "; ownerAccounts = ownerAccounts + ", "; } ownerNames = ownerNames + owner.Name; ownerAccounts = ownerAccounts + owner.Login; } // send email to notify the use of successful provisioning string mailBody = String.Format(generalMailSiteAvailable, this.SharePointProvisioningData.Title, this.SharePointProvisioningData.Url, ownerNames, ownerAccounts); MailUtility.SendEmail(generalMailSMTPServer, generalMailUser, generalMailUserPassword, mailTo, null, "Your SharePoint site is ready to be used", mailBody); } catch (Exception ex) { new SiteDirectoryManager().UpdateSiteDirectoryStatus(this.SiteDirectorySiteContext, this.SiteDirectorySiteContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryListName, this.SharePointProvisioningData.Url, "Error during provisioning", ex); } return(processed); }