예제 #1
0
        protected override void ExecuteCmdlet()
        {
            ClientSidePage clientSidePage = Identity?.GetPage(ClientContext);

            if (clientSidePage == null)
            {
                // If the client side page object cannot be found
                throw new Exception($"Page {Identity?.Name} cannot be found.");
            }

            // We need to have the page name, if not found, raise an error
            string name = ClientSidePageUtilities.EnsureCorrectPageName(Name ?? Identity?.Name);

            if (name == null)
            {
                throw new Exception("Insufficient arguments to update a client side page");
            }

            clientSidePage.LayoutType = LayoutType;

            if (Title != null)
            {
                clientSidePage.PageTitle = Title;
            }

            if (ThumbnailUrl != null)
            {
                clientSidePage.ThumbnailUrl = ThumbnailUrl;
            }

            if (ParameterSpecified(nameof(HeaderType)))
            {
                switch (HeaderType)
                {
                case ClientSidePageHeaderType.Default:
                {
                    clientSidePage.SetDefaultPageHeader();
                    break;
                }

                case ClientSidePageHeaderType.Custom:
                {
                    clientSidePage.SetCustomPageHeader(customHeaderParameters.ServerRelativeImageUrl, customHeaderParameters.TranslateX, customHeaderParameters.TranslateY);
                    break;
                }

                case ClientSidePageHeaderType.None:
                {
                    clientSidePage.RemovePageHeader();
                    break;
                }
                }
            }

            if (PromoteAs == ClientSidePagePromoteType.Template)
            {
                clientSidePage.SaveAsTemplate(name);
            }
            else
            {
                clientSidePage.Save(name);
            }

            // If a specific promote type is specified, promote the page as Home or Article or ...
            switch (PromoteAs)
            {
            case ClientSidePagePromoteType.HomePage:
                clientSidePage.PromoteAsHomePage();
                break;

            case ClientSidePagePromoteType.NewsArticle:
                clientSidePage.PromoteAsNewsArticle();
                break;

            case ClientSidePagePromoteType.None:
            default:
                break;
            }

            if (ParameterSpecified(nameof(CommentsEnabled)))
            {
                if (CommentsEnabled)
                {
                    clientSidePage.EnableComments();
                }
                else
                {
                    clientSidePage.DisableComments();
                }
            }

            if (ParameterSpecified(nameof(ContentType)))
            {
                ContentType ct = null;
                if (ContentType.ContentType == null)
                {
                    if (ContentType.Id != null)
                    {
                        ct = SelectedWeb.GetContentTypeById(ContentType.Id, true);
                    }
                    else if (ContentType.Name != null)
                    {
                        ct = SelectedWeb.GetContentTypeByName(ContentType.Name, true);
                    }
                }
                else
                {
                    ct = ContentType.ContentType;
                }
                if (ct != null)
                {
                    ct.EnsureProperty(w => w.StringId);

                    clientSidePage.PageListItem["ContentTypeId"] = ct.StringId;
                    clientSidePage.PageListItem.SystemUpdate();
                    ClientContext.ExecuteQueryRetry();
                }
            }

            if (Publish)
            {
                clientSidePage.Publish();
            }

            WriteObject(clientSidePage);
        }
        protected override void ExecuteCmdlet()
        {
            ClientSidePage clientSidePage = null;

            // Check if the page exists
            string name = ClientSidePageUtilities.EnsureCorrectPageName(Name);

            bool pageExists = false;

            try
            {
                ClientSidePage.Load(ClientContext, name);
                pageExists = true;
            }
            catch { }

            if (pageExists)
            {
                throw new Exception($"Page {name} already exists");
            }

            // Create a page that persists immediately
            clientSidePage                       = SelectedWeb.AddClientSidePage(name);
            clientSidePage.LayoutType            = LayoutType;
            clientSidePage.PageHeader.LayoutType = HeaderLayoutType;

            if (PromoteAs == ClientSidePagePromoteType.Template)
            {
                clientSidePage.SaveAsTemplate(name);
            }
            else
            {
                clientSidePage.Save(name);
            }

            if (ParameterSpecified(nameof(ContentType)))
            {
                ContentType ct = null;
                if (ContentType.ContentType == null)
                {
                    if (ContentType.Id != null)
                    {
                        ct = SelectedWeb.GetContentTypeById(ContentType.Id, true);
                    }
                    else if (ContentType.Name != null)
                    {
                        ct = SelectedWeb.GetContentTypeByName(ContentType.Name, true);
                    }
                }
                else
                {
                    ct = ContentType.ContentType;
                }
                if (ct != null)
                {
                    ct.EnsureProperty(w => w.StringId);

                    clientSidePage.PageListItem["ContentTypeId"] = ct.StringId;
                    clientSidePage.PageListItem.SystemUpdate();
                    ClientContext.ExecuteQueryRetry();
                }
            }

            // If a specific promote type is specified, promote the page as Home or Article or ...
            switch (PromoteAs)
            {
            case ClientSidePagePromoteType.HomePage:
                clientSidePage.PromoteAsHomePage();
                break;

            case ClientSidePagePromoteType.NewsArticle:
                clientSidePage.PromoteAsNewsArticle();
                break;

            case ClientSidePagePromoteType.None:
            default:
                break;
            }

            if (ParameterSpecified(nameof(CommentsEnabled)))
            {
                if (CommentsEnabled)
                {
                    clientSidePage.EnableComments();
                }
                else
                {
                    clientSidePage.DisableComments();
                }
            }

            if (Publish)
            {
                clientSidePage.Publish();
            }

            WriteObject(clientSidePage);
        }