コード例 #1
0
        protected override void ExecuteCmdlet()
        {
            if (CurrentWeb.IsNoScriptSite())
            {
                ThrowTerminatingError(new ErrorRecord(new Exception("Site has NoScript enabled, and setting custom master pages is not supported."), "NoScriptEnabled", ErrorCategory.InvalidOperation, this));
                return;
            }

            if (ParameterSetName == ParameterSet_SERVER)
            {
                if (!string.IsNullOrEmpty(MasterPageServerRelativeUrl))
                {
                    CurrentWeb.SetMasterPageByUrl(MasterPageServerRelativeUrl);
                }

                if (!string.IsNullOrEmpty(CustomMasterPageServerRelativeUrl))
                {
                    CurrentWeb.SetCustomMasterPageByUrl(CustomMasterPageServerRelativeUrl);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(MasterPageSiteRelativeUrl))
                {
                    CurrentWeb.SetMasterPageByUrl(GetServerRelativeUrl(MasterPageSiteRelativeUrl));
                }
                if (!string.IsNullOrEmpty(CustomMasterPageSiteRelativeUrl))
                {
                    CurrentWeb.SetCustomMasterPageByUrl(GetServerRelativeUrl(CustomMasterPageSiteRelativeUrl));
                }
            }
        }
コード例 #2
0
ファイル: SetTheme.cs プロジェクト: robgarrett/powershell-1
        protected override void ExecuteCmdlet()
        {
            var rootWebServerRelativeUrl = (CurrentWeb.Context as ClientContext).Site.RootWeb.EnsureProperty(r => r.ServerRelativeUrl);
            var serverRelativeUrl        = CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl);

            if (ColorPaletteUrl == null)
            {
                ColorPaletteUrl = "/_catalogs/theme/15/palette001.spcolor";
            }

            if (!ColorPaletteUrl.ToLower().StartsWith(rootWebServerRelativeUrl.ToLower()))
            {
                ColorPaletteUrl = UrlUtility.Combine(rootWebServerRelativeUrl, ColorPaletteUrl);
            }

            if (!string.IsNullOrEmpty(FontSchemeUrl) && !FontSchemeUrl.ToLower().StartsWith(rootWebServerRelativeUrl.ToLower()))
            {
                FontSchemeUrl = UrlUtility.Combine(rootWebServerRelativeUrl, FontSchemeUrl);
            }

            if (!string.IsNullOrEmpty(BackgroundImageUrl) && BackgroundImageUrl.ToLower().StartsWith(rootWebServerRelativeUrl.ToLower()))
            {
                BackgroundImageUrl = UrlUtility.Combine(rootWebServerRelativeUrl, BackgroundImageUrl);
            }

            CurrentWeb.SetThemeByUrl(ColorPaletteUrl, FontSchemeUrl, BackgroundImageUrl, ResetSubwebsToInherit, UpdateRootWebOnly);

            ClientContext.ExecuteQueryRetry();

            if (!CurrentWeb.IsNoScriptSite())
            {
                ComposedLook composedLook;
                // Set the corresponding property bag value which is used by the provisioning engine
                if (CurrentWeb.PropertyBagContainsKey(PROPBAGKEY))
                {
                    composedLook =
                        JsonSerializer.Deserialize <ComposedLook>(CurrentWeb.GetPropertyBagValueString(PROPBAGKEY, ""));
                }
                else
                {
                    composedLook = new ComposedLook {
                        BackgroundFile = ""
                    };
                    CurrentWeb.EnsureProperty(w => w.AlternateCssUrl);
                    composedLook.ColorFile = "";
                    CurrentWeb.EnsureProperty(w => w.MasterUrl);
                    composedLook.FontFile = "";
                    CurrentWeb.EnsureProperty(w => w.SiteLogoUrl);
                }

                composedLook.Name           = composedLook.Name ?? "Custom by PnP PowerShell";
                composedLook.ColorFile      = ColorPaletteUrl ?? composedLook.ColorFile;
                composedLook.FontFile       = FontSchemeUrl ?? composedLook.FontFile;
                composedLook.BackgroundFile = BackgroundImageUrl ?? composedLook.BackgroundFile;
                var composedLookJson = JsonSerializer.Serialize(composedLook);

                CurrentWeb.SetPropertyBagValue(PROPBAGKEY, composedLookJson);
            }
        }
コード例 #3
0
        protected override void ExecuteCmdlet()
        {
            try
            {
                if (!ParameterSpecified(nameof(Folder)))
                {
                    if (!Indexed)
                    {
                        // If it is already an indexed property we still have to add it back to the indexed properties
                        Indexed = !string.IsNullOrEmpty(CurrentWeb.GetIndexedPropertyBagKeys().FirstOrDefault(k => k == Key));
                    }

                    CurrentWeb.SetPropertyBagValue(Key, Value);
                    if (Indexed)
                    {
                        CurrentWeb.AddIndexedPropertyBagKey(Key);
                    }
                    else
                    {
                        CurrentWeb.RemoveIndexedPropertyBagKey(Key);
                    }
                }
                else
                {
                    CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl);

                    var folderUrl = UrlUtility.Combine(CurrentWeb.ServerRelativeUrl, Folder);
                    var folder    = CurrentWeb.GetFolderByServerRelativePath(ResourcePath.FromDecodedUrl(folderUrl));

                    folder.EnsureProperty(f => f.Properties);

                    folder.Properties[Key] = Value;
                    folder.Update();
                    ClientContext.ExecuteQueryRetry();
                }
            }
            catch (Exception ex)
            {
                if (ex is ServerUnauthorizedAccessException)
                {
                    if (CurrentWeb.IsNoScriptSite())
                    {
                        ThrowTerminatingError(new ErrorRecord(new Exception($"{ex.Message} Site might have NoScript enabled, this prevents setting some property bag values.", ex), "NoScriptEnabled", ErrorCategory.InvalidOperation, this));
                        return;
                    }
                    throw;
                }
                else
                {
                    throw;
                }
            }
        }