Beispiel #1
0
        // This function will get triggered/executed when a new message is written 
        // on an Azure Queue called queue.
        public static void ProcessQueueMessage(
            [QueueTrigger(SiteModificationManager.StorageQueueName)] 
            SiteModificationData request, TextWriter log)
        {
            Uri url = new Uri(request.SiteUrl);

            //Connect to the OD4B site using App Only token
            string realm = TokenHelper.GetRealmFromTargetUrl(url);
            var token = TokenHelper.GetAppOnlyAccessToken(
                TokenHelper.SharePointPrincipal, url.Authority, realm).AccessToken;

            using (var ctx = TokenHelper.GetClientContextWithAccessToken(
                url.ToString(), token))
            {
                // Set configuration object properly for setting the config
                SiteModificationConfig config = new SiteModificationConfig()
                {
                    SiteUrl = url.ToString(),
                    JSFile = Path.Combine(Environment.GetEnvironmentVariable("WEBROOT_PATH"), "Resources\\OneDriveConfiguration.js"),
                    ThemeName = "Garage",
                    ThemeColorFile = 
                        Path.Combine(Environment.GetEnvironmentVariable("WEBROOT_PATH"), "Resources\\Themes\\Garage\\garagewhite.spcolor"),
                    ThemeBGFile = 
                        Path.Combine(Environment.GetEnvironmentVariable("WEBROOT_PATH"), "Resources\\Themes\\Garage\\garagebg.jpg"),
                    ThemeFontFile = "" // Ignored in this case, but could be also set
                };

                new SiteModificationManager().ApplySiteConfiguration(ctx, config);
            }
        }
Beispiel #2
0
        private static void Apply(ClientContext ctx, Uri url)
        {
            // Set configuration object properly for setting the config
            SiteModificationConfig config = new SiteModificationConfig()
            {
                SiteUrl = url.ToString(),
                JSFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\OneDriveConfiguration.js"),
                ThemeName = "Garage",
                ThemeColorFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Themes\\Garage\\garagewhite.spcolor"),
                ThemeBGFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Themes\\Garage\\garagebg.jpg"),
                ThemeFontFile = ""
            };

            new SiteModificationManager().ApplySiteConfiguration(ctx, config);
        }
        public void ApplySiteConfiguration(ClientContext ctx,
                                           SiteModificationConfig config)
        {
            // Check current site configuration status - is it already in right version?
            if (ctx.Web.GetPropertyBagValueInt(
                    SiteModificationManager.OneDriveMarkerBagID, 0)
                < SiteModificationManager.BrandingVersion)
            {
                // Set the time out as high as possible for needed operations, just in case
                // In this case needed operations shold not take that long, so we shold be fine
                ctx.RequestTimeout = Timeout.Infinite;

                // Set JavaScript policy message, refresh if existed on site already
                UploadJSToRootSiteCollection(ctx, config.SiteUrl, config.JSFile);
                ctx.Web.DeleteJsLink("OneDriveCustomJS");
                ctx.Web.AddJsLink("OneDriveCustomJS", BuildJavaScriptUrl(config.SiteUrl));

                // Upload theme files to theme gallery
                ctx.Web.UploadThemeFile(config.ThemeColorFile);
                ctx.Web.UploadThemeFile(config.ThemeBGFile);
                // Set theme pointing to right files directly
                ctx.Load(ctx.Web, w => w.AllProperties, w => w.ServerRelativeUrl);
                ctx.ExecuteQuery();
                ctx.Web.ApplyTheme(ctx.Web.ServerRelativeUrl + "/_catalogs/theme/15/" +
                                   Path.GetFileName(config.ThemeColorFile),
                                   null,
                                   ctx.Web.ServerRelativeUrl + "/_catalogs/theme/15/" +
                                   Path.GetFileName(config.ThemeBGFile),
                                   true);
                ctx.ExecuteQuery();

                // Save current branding applied indicator to site
                ctx.Web.SetPropertyBagValue(
                    SiteModificationManager.OneDriveMarkerBagID,
                    SiteModificationManager.BrandingVersion);
            }
        }
public void ApplySiteConfiguration(ClientContext ctx, 
                                    SiteModificationConfig config)
{
    // Check current site configuration status - is it already in right version?
    if (ctx.Web.GetPropertyBagValueInt(
        SiteModificationManager.OneDriveMarkerBagID, 0) 
        < SiteModificationManager.BrandingVersion)
    {
        // Set the time out as high as possible for needed operations, just in case
        // In this case needed operations shold not take that long, so we shold be fine
        ctx.RequestTimeout = Timeout.Infinite;

        // Set JavaScript policy message, refresh if existed on site already
        UploadJSToRootSiteCollection(ctx, config.SiteUrl, config.JSFile);
        ctx.Web.DeleteJsLink("OneDriveCustomJS");
        ctx.Web.AddJsLink("OneDriveCustomJS", BuildJavaScriptUrl(config.SiteUrl));

        // Upload theme files to theme gallery
        ctx.Web.UploadThemeFile(config.ThemeColorFile);
        ctx.Web.UploadThemeFile(config.ThemeBGFile);
        // Set theme pointing to right files directly
        ctx.Load(ctx.Web, w => w.AllProperties, w => w.ServerRelativeUrl);
        ctx.ExecuteQuery();
        ctx.Web.ApplyTheme(ctx.Web.ServerRelativeUrl + "/_catalogs/theme/15/" + 
                            Path.GetFileName(config.ThemeColorFile),
                            null,
                            ctx.Web.ServerRelativeUrl + "/_catalogs/theme/15/" + 
                            Path.GetFileName(config.ThemeBGFile),
                            true);
        ctx.ExecuteQuery();

        // Save current branding applied indicator to site
        ctx.Web.SetPropertyBagValue(
                SiteModificationManager.OneDriveMarkerBagID, 
                SiteModificationManager.BrandingVersion);
    }
}