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;
            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 (MyInvocation.BoundParameters.ContainsKey("CommentsEnabled"))
            {
                if (CommentsEnabled)
                {
                    clientSidePage.EnableComments();
                }
                else
                {
                    clientSidePage.DisableComments();
                }
            }

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

            WriteObject(clientSidePage);
        }
Esempio n. 2
0
        protected override void ExecuteCmdlet()
        {
            var clientSidePage = Identity.GetPage((Microsoft.SharePoint.Client.ClientContext)SelectedWeb.Context);

            if (clientSidePage == null)
            {
                throw new Exception($"Page '{Identity?.Name}' does not exist");
            }

            WriteObject(clientSidePage);
        }
        protected override void ExecuteCmdlet()
        {
            if (Force || ShouldContinue(Resources.RemoveClientSidePage, Resources.Confirm))
            {
                var clientSidePage = Identity.GetPage(ClientContext);
                if (clientSidePage == null)
                {
                    throw new Exception($"Page '{Identity?.Name}' does not exist");
                }

                clientSidePage.Delete();
            }
        }
Esempio n. 4
0
        protected override void ExecuteCmdlet()
        {
            var clientSidePage = Page.GetPage(ClientContext);

            if (Component == null)
            {
                var allComponents = clientSidePage.AvailableClientSideComponents().Where(c => c.ComponentType == 1);
                WriteObject(allComponents, true);
            }
            else
            {
                WriteObject(Component.GetComponent(clientSidePage));
            }
        }
        protected override void ExecuteCmdlet()
        {
            var clientSidePage = Page?.GetPage(ClientContext);

            if (clientSidePage != null)
            {
                clientSidePage.AddSection(SectionTemplate, Order);
                clientSidePage.Save();
            }
            else
            {
                // If the client side page object cannot be found
                throw new Exception($"Page {Page} cannot be found.");
            }
        }
Esempio n. 6
0
        protected override void ExecuteCmdlet()
        {
            if (ParameterSpecified(nameof(Section)) && Section == 0)
            {
                throw new Exception("Section value should be at least 1 or higher");
            }

            if (ParameterSpecified(nameof(Column)) && Column == 0)
            {
                throw new Exception("Column value should be at least 1 or higher");
            }

            var clientSidePage = Page.GetPage(ClientContext);

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

            var textControl = new ClientSideText()
            {
                Text = Text
            };

            if (ParameterSpecified(nameof(Section)))
            {
                if (ParameterSpecified(nameof(Section)))
                {
                    clientSidePage.AddControl(textControl,
                                              clientSidePage.Sections[Section - 1].Columns[Column - 1], Order);
                }
                else
                {
                    clientSidePage.AddControl(textControl, clientSidePage.Sections[Section - 1], Order);
                }
            }
            else
            {
                clientSidePage.AddControl(textControl, Order);
            }

            // Save the page
            clientSidePage.Save();

            WriteObject(textControl);
        }
        protected override void ExecuteCmdlet()
        {
            if (MyInvocation.BoundParameters.ContainsKey("Section") && Section == 0)
            {
                throw new Exception("Section value should be at least 1 or higher");
            }

            if (MyInvocation.BoundParameters.ContainsKey("Column") && Column == 0)
            {
                throw new Exception("Column value should be at least 1 or higher");
            }

            var clientSidePage = Page.GetPage(ClientContext);

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

            var text = new ClientSideText()
            {
                Text = Text
            };

            if (MyInvocation.BoundParameters.ContainsKey("Section"))
            {
                if (MyInvocation.BoundParameters.ContainsKey("Section"))
                {
                    clientSidePage.AddControl(text,
                                              clientSidePage.Sections[Section - 1].Columns[Column - 1], Order);
                }
                else
                {
                    clientSidePage.AddControl(text, clientSidePage.Sections[Section - 1], Order);
                }
            }
            else
            {
                clientSidePage.AddControl(text, Order);
            }

            // Save the page
            clientSidePage.Save();
        }
Esempio n. 8
0
        protected override void ExecuteCmdlet()
        {
            var clientSidePage = Page.GetPage(ClientContext);

            if (clientSidePage == null)
            {
                throw new Exception($"Page '{Page?.Name}' does not exist");
            }

            if (!ParameterSpecified(nameof(InstanceId)))
            {
                WriteObject(clientSidePage.Controls, true);
            }
            else
            {
                WriteObject(clientSidePage.Controls.FirstOrDefault(c => c.InstanceId == InstanceId.Id));
            }
        }
        protected override void ExecuteCmdlet()
        {
            var clientSidePage = Page.GetPage(ClientContext);

            if (clientSidePage == null)
            {
                throw new Exception($"Page '{Page?.Name}' does not exist");
            }

            if (!MyInvocation.BoundParameters.ContainsKey("InstanceId"))
            {
                WriteObject(clientSidePage.Controls, true);
            }
            else
            {
                WriteObject(clientSidePage.Controls.FirstOrDefault(c => c.InstanceId == InstanceId.Id));
            }
        }
Esempio n. 10
0
        protected override void ExecuteCmdlet()
        {
            var clientSidePage = Page.GetPage(ClientContext);

            if (clientSidePage == null)
            {
                throw new PSArgumentException($"Page '{Page}' does not exist", "List");
            }

            if (Component == null)
            {
                var allComponents = clientSidePage.AvailableClientSideComponents().Where(c => c.ComponentType == 1);
                WriteObject(allComponents, true);
            }
            else
            {
                WriteObject(Component.GetComponent(clientSidePage));
            }
        }
Esempio n. 11
0
        protected override void ExecuteCmdlet()
        {
            var clientSidePage = Page.GetPage(ClientContext);

            if (clientSidePage == null)
            {
                throw new Exception($"Page '{Page?.Name}' does not exist");
            }

            var controls = Identity.GetWebPart(clientSidePage);

            if (controls.Any())
            {
                if (controls.Count > 1)
                {
                    throw new Exception("Found multiple webparts with the same name. Please use the InstanceId to retrieve the cmdlet.");
                }
                var  webpart = controls.First();
                bool updated = false;

                if (ParameterSpecified(nameof(PropertiesJson)))
                {
                    webpart.PropertiesJson = PropertiesJson;
                    updated = true;
                }
                if (ParameterSpecified(nameof(Title)))
                {
                    webpart.Title = Title;
                    updated       = true;
                }

                if (updated)
                {
                    clientSidePage.Save();
                }
            }
            else
            {
                throw new Exception($"Web part does not exist");
            }
        }
Esempio n. 12
0
        protected override void ExecuteCmdlet()
        {
            var clientSidePage = Page.GetPage(ClientContext);

            if (clientSidePage == null)
            {
                throw new Exception($"Page '{Page?.Name}' does not exist");
            }

            var control = clientSidePage.Controls.FirstOrDefault(c => c.InstanceId == InstanceId);

            if (control != null)
            {
                var textControl = control as ClientSideText;
                textControl.Text = Text;
                clientSidePage.Save();
            }
            else
            {
                throw new Exception($"Component does not exist");
            }
        }
Esempio n. 13
0
        protected override void ExecuteCmdlet()
        {
            var clientSidePage = Page.GetPage(ClientContext);

            if (clientSidePage == null)
            {
                throw new Exception($"Page '{Page?.Name}' does not exist");
            }

            var control = clientSidePage.Controls.FirstOrDefault(c => c.InstanceId == InstanceId.Id);

            if (control != null)
            {
                if (Force || ShouldContinue(string.Format(Properties.Resources.RemoveComponentWithInstanceId0, control.InstanceId), Properties.Resources.Confirm))
                {
                    control.Delete();
                    clientSidePage.Save();
                }
            }
            else
            {
                throw new Exception($"Component with id {InstanceId.Id} does not exist on this page");
            }
        }
Esempio n. 14
0
        protected override void ExecuteCmdlet()
        {
            string tempPath = null;

            try
            {
                //Fix loading of modernization framework
                FixAssemblyResolving();

                // Load the page to transform
                var page = Identity.GetPage(this.ClientContext.Web);

                if (page == null)
                {
                    throw new Exception($"Page '{Identity?.Name}' does not exist");
                }

                if (string.IsNullOrEmpty(this.WebPartMappingFile))
                {
                    // Load the default one from resources
                    string webpartMappingFileContents = WebPartMappingLoader.LoadFile("SharePointPnP.PowerShell.Commands.ClientSidePages.webpartmapping.xml");

                    // Save the file to a temp location
                    tempPath = System.IO.Path.GetTempFileName();
                    System.IO.File.WriteAllText(tempPath, webpartMappingFileContents);
                    this.WebPartMappingFile = tempPath;

                    this.WriteVerbose("Using embedded webpartmapping file (https://github.com/SharePoint/PnP-PowerShell/blob/master/Commands/ClientSidePages/webpartmapping.xml)");
                }

                // Validate webpartmappingfile
                if (!string.IsNullOrEmpty(this.WebPartMappingFile))
                {
                    if (!System.IO.File.Exists(this.WebPartMappingFile))
                    {
                        throw new Exception($"Provided webpartmapping file {this.WebPartMappingFile} does not exist");
                    }
                }

                // Create transformator instance
                PageTransformator pageTransformator = new PageTransformator(this.ClientContext, this.WebPartMappingFile);

                // Setup Transformation information
                PageTransformationInformation pti = new PageTransformationInformation(page)
                {
                    Overwrite = this.Overwrite,
                    TargetPageTakesSourcePageName      = this.TakeSourcePageName,
                    ReplaceHomePageWithDefaultHomePage = this.ReplaceHomePageWithDefault,
                    ModernizationCenterInformation     = new ModernizationCenterInformation()
                    {
                        AddPageAcceptBanner = this.AddPageAcceptBanner
                    },
                };

                string serverRelativeClientPageUrl = pageTransformator.Transform(pti);

                ClientSidePagePipeBind cpb = new ClientSidePagePipeBind(System.IO.Path.GetFileName(serverRelativeClientPageUrl));
                var clientSidePage         = cpb.GetPage(this.ClientContext);

                if (clientSidePage != null)
                {
                    WriteObject(clientSidePage);
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(tempPath) && System.IO.File.Exists(tempPath))
                {
                    System.IO.File.Delete(tempPath);
                }
            }
        }
        protected override void ExecuteCmdlet()
        {
            var clientSidePage = Page.GetPage(ClientContext);

            if (clientSidePage == null)
            {
                throw new Exception($"Page '{Page?.Name}' does not exist");
            }

            var control = clientSidePage.Controls.FirstOrDefault(c => c.InstanceId == InstanceId.Id);

            if (control != null)
            {
                bool updated = false;

                switch (ParameterSetName)
                {
                case ParameterSet_COLUMN:
                {
                    var column = control.Section.Columns[Column - 1];
                    if (column != control.Column)
                    {
                        if (MyInvocation.BoundParameters.ContainsKey(nameof(Position)))
                        {
                            control.MovePosition(column, Position);
                        }
                        else
                        {
                            control.Move(column);
                        }
                        updated = true;
                    }
                    break;
                }

                case ParameterSet_SECTION:
                {
                    var section = clientSidePage.Sections[Section - 1];
                    if (section != control.Section)
                    {
                        if (MyInvocation.BoundParameters.ContainsKey(nameof(Position)))
                        {
                            control.MovePosition(section, Position);
                        }
                        else
                        {
                            control.Move(section);
                        }
                        updated = true;
                    }
                    break;
                }

                case ParameterSet_SECTIONCOLUMN:
                {
                    var section = clientSidePage.Sections[Section - 1];
                    if (section != control.Section)
                    {
                        control.Move(section);
                        updated = true;
                    }
                    var column = section.Columns[Column - 1];
                    if (column != control.Column)
                    {
                        if (MyInvocation.BoundParameters.ContainsKey(nameof(Position)))
                        {
                            control.MovePosition(column, Position);
                        }
                        else
                        {
                            control.Move(column);
                        }
                        updated = true;
                    }
                    break;
                }

                case ParameterSet_POSITION:
                {
                    control.MovePosition(control.Column, Position);
                    updated = true;
                    break;
                }
                }


                if (updated)
                {
                    clientSidePage.Save();
                }
            }
            else
            {
                throw new Exception($"Webpart does not exist");
            }
        }
Esempio n. 16
0
        protected override void ExecuteCmdlet()
        {
            if (MyInvocation.BoundParameters.ContainsKey("Section") && Section == 0)
            {
                throw new Exception("Section value should be at least 1 or higher");
            }

            if (MyInvocation.BoundParameters.ContainsKey("Column") && Column == 0)
            {
                throw new Exception("Column value should be at least 1 or higher");
            }

            var clientSidePage = Page.GetPage(ClientContext);

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

            ClientSideWebPart webpart = null;

            if (MyInvocation.BoundParameters.ContainsKey("DefaultWebPartType"))
            {
                webpart = clientSidePage.InstantiateDefaultWebPart(DefaultWebPartType);
            }
            else
            {
                webpart = new ClientSideWebPart(Component.GetComponent(clientSidePage));
            }

            if (WebPartProperties != null)
            {
                if (WebPartProperties.Properties != null)
                {
                    webpart.Properties.Merge(WebPartProperties.JsonObject);
                }
                else if (!string.IsNullOrEmpty(WebPartProperties.Json))
                {
                    webpart.PropertiesJson = WebPartProperties.Json;
                }
            }

            if (MyInvocation.BoundParameters.ContainsKey("Section"))
            {
                if (MyInvocation.BoundParameters.ContainsKey("Column"))
                {
                    clientSidePage.AddControl(webpart,
                                              clientSidePage.Sections[Section - 1].Columns[Column - 1], Order);
                }
                else
                {
                    clientSidePage.AddControl(webpart, clientSidePage.Sections[Section - 1], Order);
                }
            }
            else
            {
                clientSidePage.AddControl(webpart, Order);
            }

            clientSidePage.Save();
        }