protected override void RunJobInternal(ProvisioningJob job) { BrandingJob brandingJob = job as BrandingJob; if (brandingJob == null) { throw new ArgumentException("Invalid job type for BrandingJobHandler."); } ApplyBranding(brandingJob); }
public ActionResult Branding(BrandingViewModel model) { AntiForgery.Validate(); if (ModelState.IsValid) { // Get the original branding settings BrandingSettings original = PnPPartnerPackUtilities.GetTenantBrandingSettings(); // If something changed in the branding settings compared with previous settings if (model.LogoImageUrl != original.LogoImageUrl || model.BackgroundImageUrl != original.BackgroundImageUrl || model.ColorFileUrl != original.ColorFileUrl || model.FontFileUrl != original.FontFileUrl || model.CSSOverrideUrl != original.CSSOverrideUrl || model.UICustomActionsUrl != original.UICustomActionsUrl) { var newBrandingSettings = new BrandingSettings { LogoImageUrl = model.LogoImageUrl, BackgroundImageUrl = model.BackgroundImageUrl, ColorFileUrl = model.ColorFileUrl, FontFileUrl = model.FontFileUrl, CSSOverrideUrl = model.CSSOverrideUrl, UICustomActionsUrl = model.UICustomActionsUrl, UpdatedOn = DateTime.Now, }; // Update the last date and time of update model.UpdatedOn = newBrandingSettings.UpdatedOn; // Get the JSON representation of the settings var jsonBranding = JsonConvert.SerializeObject(newBrandingSettings); // Store the new tenant-wide settings in the Infrastructural Site Collection PnPPartnerPackUtilities.SetPropertyBagValueToInfrastructure( PnPPartnerPackConstants.PropertyBag_Branding, jsonBranding); } if (model.RollOut) { // Create the asynchronous job var job = new BrandingJob { Owner = ClaimsPrincipal.Current.Identity.Name, Title = "Tenant Wide Branding", }; // Enqueue the job for execution model.JobId = ProvisioningRepositoryFactory.Current.EnqueueProvisioningJob(job); } } return(View(model)); }
private void ApplyBranding(BrandingJob job) { // Use the infrastructural site collection to temporary store the template with color palette and font files using (var repositoryContext = PnPPartnerPackContextProvider.GetAppOnlyClientContext( PnPPartnerPackSettings.InfrastructureSiteUrl)) { var brandingSettings = PnPPartnerPackUtilities.GetTenantBrandingSettings(); ProvisioningTemplate template = PrepareBrandingTemplate(repositoryContext, brandingSettings); // For each Site Collection in the tenant using (var adminContext = PnPPartnerPackContextProvider.GetAppOnlyTenantLevelClientContext()) { var tenant = new Tenant(adminContext); var siteCollections = tenant.GetSiteProperties(0, true); adminContext.Load(siteCollections); adminContext.ExecuteQueryRetry(); foreach (var site in siteCollections) { if (!site.Url.ToLower().Contains("/portals/") && !site.Url.ToLower().Contains("-public.sharepoint.com") && !site.Url.ToLower().Contains("-my.sharepoint.com")) { // Clean-up the template template.WebSettings.MasterPageUrl = null; using (var siteContext = PnPPartnerPackContextProvider.GetAppOnlyClientContext(site.Url)) { // Get a reference to the target web var targetWeb = siteContext.Site.RootWeb; // Update the root web of the site collection ApplyBrandingOnWeb(targetWeb, brandingSettings, template); } } } } } }
public ActionResult Branding(BrandingViewModel model) { AntiForgery.Validate(); if (ModelState.IsValid) { // Get the original branding settings BrandingSettings original = PnPPartnerPackUtilities.GetTenantBrandingSettings(); // If something changed in the branding settings compared with previous settings if (model.LogoImageUrl != original.LogoImageUrl || model.BackgroundImageUrl != original.BackgroundImageUrl || model.ColorFileUrl != original.ColorFileUrl || model.FontFileUrl != original.FontFileUrl || model.CSSOverrideUrl != original.CSSOverrideUrl || model.UICustomActionsUrl != original.UICustomActionsUrl) { var newBrandingSettings = new BrandingSettings { LogoImageUrl = model.LogoImageUrl, BackgroundImageUrl = model.BackgroundImageUrl, ColorFileUrl = model.ColorFileUrl, FontFileUrl = model.FontFileUrl, CSSOverrideUrl = model.CSSOverrideUrl, UICustomActionsUrl = model.UICustomActionsUrl, UpdatedOn = DateTime.Now, }; // Update the last date and time of update model.UpdatedOn = newBrandingSettings.UpdatedOn; // Get the JSON representation of the settings var jsonBranding = JsonConvert.SerializeObject(newBrandingSettings); // Store the new tenant-wide settings in the Infrastructural Site Collection PnPPartnerPackUtilities.SetPropertyBagValueToInfrastructure( PnPPartnerPackConstants.PropertyBag_Branding, jsonBranding); } if (model.RollOut) { // Create the asynchronous job var job = new BrandingJob { Owner = ClaimsPrincipal.Current.Identity.Name, Title = "Tenant Wide Branding", }; // Enqueue the job for execution model.JobId = ProvisioningRepositoryFactory.Current.EnqueueProvisioningJob(job); } } return View(model); }