/// <summary>
        /// Returns the default branding if it couldn't find a matching URL
        /// </summary>
        /// <returns></returns>
        private static BrandingSettings RetrieveDefaultBranding()
        {
            var defaultBranding = (from b in Brandings._staticBrandings
                                   where b.IsDefault
                                   select b).FirstOrDefault();

            if (defaultBranding != null)
            {
                return(defaultBranding);
            }
            else
            {
                // Seems we can't find the default branding so we will compile a new one at runtime
                BrandingSettings branding = new BrandingSettings();
                branding.DisplayName     = "CloudPanel";
                branding.CopyrightNotice = "";
                branding.LoginTitle      = "Welcome to CloudPanel";
                branding.LoginMessage    = "Please login";

                // Add to the list for next time
                Brandings._staticBrandings.Add(branding);

                return(branding);
            }
        }
        public static bool HaveFilesForBranding(string fullBrandKey)
        {
            BrandingSettings.ParseBrandingKey(fullBrandKey, out var baseKey, out var flavor);

            var brandingDirectory = BloomFileLocator.GetBrowserDirectory("branding");

            return(Directory.GetDirectories(brandingDirectory)
                   .Any(brandDirectory => Path.GetFileName(brandDirectory) == baseKey));
        }
 public BrandingController(IHostingEnvironment env,
                           IOptionsSnapshot <BrandingSettings> settings,
                           BrandingContext catalogContext)
 {
     _env            = env;
     _catalogContext = catalogContext;
     _settings       = settings.Value;
     ((DbContext)catalogContext).ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
 }
Beispiel #4
0
        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));
        }
        public static string GetSummaryHtml(string branding)
        {
            BrandingSettings.ParseBrandingKey(branding, out var baseKey, out var flavor);
            var summaryFile = BloomFileLocator.GetOptionalBrandingFile(baseKey, "summary.htm");

            if (summaryFile == null)
            {
                return("");
            }

            var html = File.ReadAllText(summaryFile, Encoding.UTF8);

            return(html.Replace("{flavor}", flavor));
        }
Beispiel #6
0
        public ActionResult Branding()
        {
            BrandingSettings original = PnPPartnerPackUtilities.GetTenantBrandingSettings();

            BrandingViewModel model = new BrandingViewModel {
                LogoImageUrl       = original.LogoImageUrl,
                BackgroundImageUrl = original.BackgroundImageUrl,
                ColorFileUrl       = original.ColorFileUrl,
                FontFileUrl        = original.FontFileUrl,
                CSSOverrideUrl     = original.CSSOverrideUrl,
                UICustomActionsUrl = original.UICustomActionsUrl,
            };

            return(View(model));
        }
        /// <summary>
        /// Loads the brandings from the config file
        /// </summary>
        public static void RetrieveBrandings()
        {
            try
            {
                XDocument xDoc = XDocument.Load(path);

                /* Load Brandings */
                log.Debug("Retrieving brandings from the config file");
                var brandings = from s in xDoc.Descendants("branding").Elements()
                                select s;

                // Clear our current static brandings
                Brandings._staticBrandings = new List <BrandingSettings>();

                // Everything here should be a base URL or default
                foreach (var b in brandings)
                {
                    log.DebugFormat("Found host {0} in brandings", b.Name.LocalName);

                    BrandingSettings newBranding = new BrandingSettings();
                    newBranding.DisplayName     = b.Element("DisplayName").Value;
                    newBranding.CopyrightNotice = b.Element("Copyright").Value;
                    newBranding.LoginTitle      = b.Element("LoginTitle").Value;
                    newBranding.LoginMessage    = b.Element("LoginMessage").Value;
                    newBranding.SupportNumber   = b.Element("SupportNumber").Value;
                    newBranding.BaseURL         = b.Name.LocalName;

                    if (b.Name.LocalName == "default")
                    {
                        newBranding.IsDefault = true;
                    }

                    Brandings._staticBrandings.Add(newBranding);
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Error retrieving brandings from config file. Error: {0}", ex.ToString());
            }
        }
Beispiel #8
0
        /// <summary>
        /// We configure the SettingsApi to use this method to notify this (as the manager of the whole dialog
        /// including the "need to reload" message and the Ok/Cancel buttons) of changes the user makes
        /// in the Enterprise tab.
        /// </summary>
        /// <param name="fullBrandingName"></param>
        /// <param name="subscriptionCode"></param>
        /// <returns></returns>
        public bool ChangeBranding(string fullBrandingName, string subscriptionCode)
        {
            if (BrandingProject.HaveFilesForBranding(fullBrandingName))
            {
                if (_brand != fullBrandingName || DifferentSubscriptionCodes(subscriptionCode, _subscriptionCode))
                {
                    Invoke((Action)ChangeThatRequiresRestart);
                    _brand            = fullBrandingName;
                    _subscriptionCode = subscriptionCode;

                    // if the branding.json specifies an xmatter, set the default for this collection to that.
                    var correspondingXMatterPack = BrandingSettings.GetSettings(fullBrandingName).GetXmatterToUse();
                    if (!string.IsNullOrEmpty(correspondingXMatterPack))
                    {
                        _collectionSettings.XMatterPackName = correspondingXMatterPack;
                    }
                }

                return(true);
            }
            return(false);
        }
Beispiel #9
0
        public static ProvisioningTemplate PrepareBrandingTemplate(ClientContext repositoryContext, BrandingSettings brandingSettings)
        {
            var repositoryWeb = repositoryContext.Site.RootWeb;

            repositoryContext.Load(repositoryWeb, w => w.Url);
            repositoryContext.ExecuteQueryRetry();

            var refererUri   = new Uri(repositoryWeb.Url);
            var refererValue = $"{refererUri.Scheme}://{refererUri.Host}/";

            var templateId = Guid.NewGuid();

            // Prepare an OpenXML provider
            XMLTemplateProvider provider = new XMLOpenXMLTemplateProvider($"{templateId}.pnp",
                                                                          new SharePointConnector(repositoryContext, repositoryWeb.Url,
                                                                                                  PnPPartnerPackConstants.PnPProvisioningTemplates));

            // Prepare the branding provisioning template
            var template = new ProvisioningTemplate()
            {
                Id          = $"Branding-{Guid.NewGuid()}",
                DisplayName = "Branding Template",
            };

            template.WebSettings = new WebSettings
            {
                AlternateCSS = brandingSettings.CSSOverrideUrl,
                SiteLogo     = brandingSettings.LogoImageUrl,
            };

            template.ComposedLook = new ComposedLook()
            {
                Name = "SharePointBranding",
            };

            if (!String.IsNullOrEmpty(brandingSettings.BackgroundImageUrl))
            {
                var backgroundImageFileName   = brandingSettings.BackgroundImageUrl.Substring(brandingSettings.BackgroundImageUrl.LastIndexOf("/") + 1);
                var backgroundImageFileStream = HttpHelper.MakeGetRequestForStream(brandingSettings.BackgroundImageUrl, "application/octet-stream", referer: refererValue);
                template.ComposedLook.BackgroundFile = String.Format("{{sitecollection}}/SiteAssets/{0}", backgroundImageFileName);
                provider.Connector.SaveFileStream(backgroundImageFileName, backgroundImageFileStream);

                template.Files.Add(new Core.Framework.Provisioning.Model.File
                {
                    Src       = backgroundImageFileName,
                    Folder    = "SiteAssets",
                    Overwrite = true,
                });
            }
            else
            {
                template.ComposedLook.BackgroundFile = String.Empty;
            }

            if (!String.IsNullOrEmpty(brandingSettings.FontFileUrl))
            {
                var fontFileName   = brandingSettings.FontFileUrl.Substring(brandingSettings.FontFileUrl.LastIndexOf("/") + 1);
                var fontFileStream = HttpHelper.MakeGetRequestForStream(brandingSettings.FontFileUrl, "application/octet-stream", referer: refererValue);
                template.ComposedLook.FontFile = String.Format("{{themecatalog}}/15/{0}", fontFileName);
                provider.Connector.SaveFileStream(fontFileName, fontFileStream);

                template.Files.Add(new Core.Framework.Provisioning.Model.File
                {
                    Src       = fontFileName,
                    Folder    = "{themecatalog}/15",
                    Overwrite = true,
                });
            }
            else
            {
                template.ComposedLook.FontFile = String.Empty;
            }

            if (!String.IsNullOrEmpty(brandingSettings.ColorFileUrl))
            {
                var colorFileName   = brandingSettings.ColorFileUrl.Substring(brandingSettings.ColorFileUrl.LastIndexOf("/") + 1);
                var colorFileStream = HttpHelper.MakeGetRequestForStream(brandingSettings.ColorFileUrl, "application/octet-stream", referer: refererValue);
                template.ComposedLook.ColorFile = String.Format("{{themecatalog}}/15/{0}", colorFileName);
                provider.Connector.SaveFileStream(colorFileName, colorFileStream);

                template.Files.Add(new Core.Framework.Provisioning.Model.File
                {
                    Src       = colorFileName,
                    Folder    = "{themecatalog}/15",
                    Overwrite = true,
                });
            }
            else
            {
                template.ComposedLook.ColorFile = String.Empty;
            }

            // Save the template, ready to be applied
            provider.SaveAs(template, $"{templateId}.xml");

            // Re-open the template provider just saved
            provider = new XMLOpenXMLTemplateProvider($"{templateId}.pnp",
                                                      new SharePointConnector(repositoryContext, repositoryWeb.Url,
                                                                              PnPPartnerPackConstants.PnPProvisioningTemplates));

            // Set the connector of the template, in order to being able to retrieve support files
            template.Connector = provider.Connector;

            return(template);
        }
Beispiel #10
0
        public static void ApplyBrandingOnWeb(Web targetWeb, BrandingSettings brandingSettings, ProvisioningTemplate template)
        {
            targetWeb.EnsureProperties(w => w.MasterUrl, w => w.Url);

            // Configure proper settings for the provisioning engine
            ProvisioningTemplateApplyingInformation ptai =
                new ProvisioningTemplateApplyingInformation();

            // Write provisioning steps on console log
            ptai.MessagesDelegate += delegate(string message, ProvisioningMessageType messageType) {
                Console.WriteLine("{0} - {1}", messageType, messageType);
            };
            ptai.ProgressDelegate += delegate(string message, int step, int total) {
                Console.WriteLine("{0:00}/{1:00} - {2}", step, total, message);
            };

            // Include only required handlers
            ptai.HandlersToProcess = Core.Framework.Provisioning.Model.Handlers.ComposedLook |
                                     Core.Framework.Provisioning.Model.Handlers.Files |
                                     Core.Framework.Provisioning.Model.Handlers.WebSettings;

            // Check if we really need to apply/update the branding
            var siteBrandingUpdatedOn = targetWeb.GetPropertyBagValueString(
                PnPPartnerPackConstants.PropertyBag_Branding_AppliedOn, null);

            // If the branding updated on date and time are missing
            // or older than the branding update date and time
            if (String.IsNullOrEmpty(siteBrandingUpdatedOn) ||
                DateTime.Parse(siteBrandingUpdatedOn) < brandingSettings.UpdatedOn.Value.ToUniversalTime())
            {
                Console.WriteLine($"Appling branding to site: {targetWeb.Url}");

                // Confirm the master page URL
                template.WebSettings.MasterPageUrl = targetWeb.MasterUrl;

                // Apply the template
                targetWeb.ApplyProvisioningTemplate(template, ptai);

                // Apply a custom JSLink, if any
                if (!String.IsNullOrEmpty(brandingSettings.UICustomActionsUrl))
                {
                    targetWeb.AddJsLink(
                        PnPPartnerPackConstants.BRANDING_SCRIPT_LINK_KEY,
                        brandingSettings.UICustomActionsUrl);
                }

                // Store Property Bag to set the last date and time when we applied the branding
                targetWeb.SetPropertyBagValue(
                    PnPPartnerPackConstants.PropertyBag_Branding_AppliedOn,
                    DateTime.Now.ToUniversalTime().ToString());

                Console.WriteLine($"Applied branding to site: {targetWeb.Url}");
            }

            // Apply branding (recursively) on all the subwebs of the current web
            targetWeb.EnsureProperty(w => w.Webs);

            foreach (var subweb in targetWeb.Webs)
            {
                ApplyBrandingOnWeb(subweb, brandingSettings, template);
            }
        }
Beispiel #11
0
 public static string GetBrandingFolder(string fullBrandingName)
 {
     BrandingSettings.ParseBrandingKey(fullBrandingName, out var brandingFolderName, out var flavor);
     return(BloomFileLocator.GetBrowserDirectory("branding", brandingFolderName));
 }
Beispiel #12
0
 public string GetBrandingFolderName()
 {
     BrandingSettings.ParseBrandingKey(BrandingProjectKey, out var folderName, out var flavor);
     return(folderName);
 }
Beispiel #13
0
 public string GetBrandingFlavor()
 {
     BrandingSettings.ParseBrandingKey(BrandingProjectKey, out var baseKey, out var flavor);
     return(flavor);
 }
        public static ProvisioningTemplate PrepareBrandingTemplate(ClientContext repositoryContext, BrandingSettings brandingSettings)
        {
            var repositoryWeb = repositoryContext.Site.RootWeb;
            repositoryContext.Load(repositoryWeb, w => w.Url);
            repositoryContext.ExecuteQueryRetry();

            var refererUri = new Uri(repositoryWeb.Url);
            var refererValue = $"{refererUri.Scheme}://{refererUri.Host}/";

            var templateId = Guid.NewGuid();

            // Prepare an OpenXML provider
            XMLTemplateProvider provider = new XMLOpenXMLTemplateProvider($"{templateId}.pnp",
                new SharePointConnector(repositoryContext, repositoryWeb.Url,
                        PnPPartnerPackConstants.PnPProvisioningTemplates));

            // Prepare the branding provisioning template
            var template = new ProvisioningTemplate()
            {
                Id = $"Branding-{Guid.NewGuid()}",
                DisplayName = "Branding Template",
            };

            template.WebSettings = new WebSettings
            {
                AlternateCSS = brandingSettings.CSSOverrideUrl,
                SiteLogo = brandingSettings.LogoImageUrl,
            };

            template.ComposedLook = new ComposedLook()
            {
                Name = "SharePointBranding",
            };

            if (!String.IsNullOrEmpty(brandingSettings.BackgroundImageUrl))
            {
                var backgroundImageFileName = brandingSettings.BackgroundImageUrl.Substring(brandingSettings.BackgroundImageUrl.LastIndexOf("/") + 1);
                var backgroundImageFileStream = HttpHelper.MakeGetRequestForStream(brandingSettings.BackgroundImageUrl, "application/octet-stream", referer: refererValue);
                template.ComposedLook.BackgroundFile = String.Format("{{sitecollection}}/SiteAssets/{0}", backgroundImageFileName);
                provider.Connector.SaveFileStream(backgroundImageFileName, backgroundImageFileStream);

                template.Files.Add(new Core.Framework.Provisioning.Model.File
                {
                    Src = backgroundImageFileName,
                    Folder = "SiteAssets",
                    Overwrite = true,
                });
            }
            else
            {
                template.ComposedLook.BackgroundFile = String.Empty;
            }

            if (!String.IsNullOrEmpty(brandingSettings.FontFileUrl))
            {
                var fontFileName = brandingSettings.FontFileUrl.Substring(brandingSettings.FontFileUrl.LastIndexOf("/") + 1);
                var fontFileStream = HttpHelper.MakeGetRequestForStream(brandingSettings.FontFileUrl, "application/octet-stream", referer: refererValue);
                template.ComposedLook.FontFile = String.Format("{{themecatalog}}/15/{0}", fontFileName);
                provider.Connector.SaveFileStream(fontFileName, fontFileStream);

                template.Files.Add(new Core.Framework.Provisioning.Model.File
                {
                    Src = fontFileName,
                    Folder = "{themecatalog}/15",
                    Overwrite = true,
                });
            }
            else
            {
                template.ComposedLook.FontFile = String.Empty;
            }

            if (!String.IsNullOrEmpty(brandingSettings.ColorFileUrl))
            {
                var colorFileName = brandingSettings.ColorFileUrl.Substring(brandingSettings.ColorFileUrl.LastIndexOf("/") + 1);
                var colorFileStream = HttpHelper.MakeGetRequestForStream(brandingSettings.ColorFileUrl, "application/octet-stream", referer: refererValue);
                template.ComposedLook.ColorFile = String.Format("{{themecatalog}}/15/{0}", colorFileName);
                provider.Connector.SaveFileStream(colorFileName, colorFileStream);

                template.Files.Add(new Core.Framework.Provisioning.Model.File
                {
                    Src = colorFileName,
                    Folder = "{themecatalog}/15",
                    Overwrite = true,
                });
            }
            else
            {
                template.ComposedLook.ColorFile = String.Empty;
            }

            // Save the template, ready to be applied
            provider.SaveAs(template, $"{templateId}.xml");

            // Re-open the template provider just saved
            provider = new XMLOpenXMLTemplateProvider($"{templateId}.pnp",
                new SharePointConnector(repositoryContext, repositoryWeb.Url,
                        PnPPartnerPackConstants.PnPProvisioningTemplates));

            // Set the connector of the template, in order to being able to retrieve support files
            template.Connector = provider.Connector;

            return template;
        }
        public static void ApplyBrandingOnWeb(Web targetWeb, BrandingSettings brandingSettings, ProvisioningTemplate template)
        {
            targetWeb.EnsureProperties(w => w.MasterUrl, w => w.Url);

            // Configure proper settings for the provisioning engine
            ProvisioningTemplateApplyingInformation ptai =
                new ProvisioningTemplateApplyingInformation();

            // Write provisioning steps on console log
            ptai.MessagesDelegate += delegate (string message, ProvisioningMessageType messageType) {
                Console.WriteLine("{0} - {1}", messageType, messageType);
            };
            ptai.ProgressDelegate += delegate (string message, int step, int total) {
                Console.WriteLine("{0:00}/{1:00} - {2}", step, total, message);
            };

            // Include only required handlers
            ptai.HandlersToProcess = Core.Framework.Provisioning.Model.Handlers.ComposedLook |
                Core.Framework.Provisioning.Model.Handlers.Files |
                Core.Framework.Provisioning.Model.Handlers.WebSettings;

            // Check if we really need to apply/update the branding
            var siteBrandingUpdatedOn = targetWeb.GetPropertyBagValueString(
                PnPPartnerPackConstants.PropertyBag_Branding_AppliedOn, null);

            // If the branding updated on date and time are missing
            // or older than the branding update date and time
            if (String.IsNullOrEmpty(siteBrandingUpdatedOn) ||
                DateTime.Parse(siteBrandingUpdatedOn) < brandingSettings.UpdatedOn.Value.ToUniversalTime())
            {
                Console.WriteLine($"Appling branding to site: {targetWeb.Url}");

                // Confirm the master page URL
                template.WebSettings.MasterPageUrl = targetWeb.MasterUrl;

                // Apply the template
                targetWeb.ApplyProvisioningTemplate(template, ptai);

                // Apply a custom JSLink, if any
                if (!String.IsNullOrEmpty(brandingSettings.UICustomActionsUrl))
                {
                    targetWeb.AddJsLink(
                        PnPPartnerPackConstants.BRANDING_SCRIPT_LINK_KEY,
                        brandingSettings.UICustomActionsUrl);
                }

                // Store Property Bag to set the last date and time when we applied the branding
                targetWeb.SetPropertyBagValue(
                    PnPPartnerPackConstants.PropertyBag_Branding_AppliedOn,
                    DateTime.Now.ToUniversalTime().ToString());

                Console.WriteLine($"Applied branding to site: {targetWeb.Url}");
            }

            // Apply branding (recursively) on all the subwebs of the current web
            targetWeb.EnsureProperty(w => w.Webs);

            foreach (var subweb in targetWeb.Webs)
            {
                ApplyBrandingOnWeb(subweb, brandingSettings, template);
            }
        }