Example #1
0
        protected override void ExecuteCmdlet()
        {
            var theme = new SPOTheme(Identity.Name, Palette.ThemePalette, IsInverted);

            var themes = Tenant.GetAllTenantThemes();

            ClientContext.Load(themes);
            ClientContext.ExecuteQueryRetry();
            if (themes.FirstOrDefault(t => t.Name == Identity.Name) != null)
            {
                if (Overwrite.ToBool())
                {
                    Tenant.UpdateTenantTheme(Identity.Name, JsonSerializer.Serialize(theme));
                    ClientContext.ExecuteQueryRetry();
                }
                else
                {
                    WriteError(new ErrorRecord(new Exception($"Theme exists"), "THEMEEXISTS", ErrorCategory.ResourceExists, Identity.Name));
                }
            }
            else
            {
                Tenant.AddTenantTheme(Identity.Name, JsonSerializer.Serialize(theme));
                ClientContext.ExecuteQueryRetry();
            }
        }
Example #2
0
        public static TokenParser ProcessThemes(Tenant tenant, ProvisioningTenant provisioningTenant, TokenParser parser, PnPMonitoredScope scope, ProvisioningMessagesDelegate messagesDelegate)
        {
            if (provisioningTenant.Themes != null && provisioningTenant.Themes.Any())
            {
                var themes = tenant.GetAllTenantThemes();
                tenant.Context.Load(themes);
                tenant.Context.ExecuteQueryRetry();

                foreach (var theme in provisioningTenant.Themes)
                {
                    var parsedName = parser.ParseString(theme.Name);
                    if (themes.FirstOrDefault(t => t.Name == parsedName) != null)
                    {
                        if (theme.Overwrite)
                        {
                            var parsedPalette = parser.ParseString(theme.Palette);

                            messagesDelegate?.Invoke($"Overwriting existing theme {parsedName}", ProvisioningMessageType.Progress);

                            var palette     = JsonConvert.DeserializeObject <Dictionary <string, string> >(parsedPalette);
                            var tenantTheme = new TenantTheme()
                            {
                                Name = parsedName, Palette = palette, IsInverted = theme.IsInverted
                            };
                            tenant.UpdateTenantTheme(parsedName, JsonConvert.SerializeObject(tenantTheme));
                            tenant.Context.ExecuteQueryRetry();
                        }
                        else
                        {
                            messagesDelegate?.Invoke($"Skipped processing theme {parsedName} as it already exists and Overwrite is set to false", ProvisioningMessageType.Progress);
                        }
                    }
                    else
                    {
                        var parsedPalette = parser.ParseString(theme.Palette);

                        messagesDelegate?.Invoke($"Processing theme {parsedName}", ProvisioningMessageType.Progress);

                        var palette     = JsonConvert.DeserializeObject <Dictionary <string, string> >(parsedPalette);
                        var tenantTheme = new TenantTheme()
                        {
                            Name = parsedName, Palette = palette, IsInverted = theme.IsInverted
                        };
                        tenant.AddTenantTheme(parsedName, JsonConvert.SerializeObject(tenantTheme));
                        tenant.Context.ExecuteQueryRetry();
                    }
                }
            }
            return(parser);
        }