示例#1
0
            private Dictionary <object, object> GetQueryParams()
            {
                var qp = new Dictionary <object, object>();

                // all sets
                qp.Add("pretty", Pretty.ToString());

                switch (ParameterSetName)
                {
                //named
                case "named-exact":
                case "named-fuzzy":
                case "named-exact-image":
                case "named-fuzzy-image":
                    var name_param = ParameterSetName.Contains("exact") ? "exact" : "fuzzy";
                    qp.Add(name_param, Named);
                    qp.Add("format", Image ? "image" : "json");
                    qp.Add("set", Set);
                    qp.Add("face", Back ? "back" : null);
                    qp.Add("version", Version);
                    break;

                //search
                case "search":
                    qp.Add("q", Query);
                    qp.Add("unique", Unique);
                    qp.Add("order", OrderBy);
                    qp.Add("dir", Direction);
                    qp.Add("include_extras", Extras);
                    qp.Add("include_multilingual", Multilingual);
                    qp.Add("include_variations", Variations);
                    qp.Add("page", Page);
                    break;
                }

                return(qp);
            }
示例#2
0
        protected override void ExecuteCmdlet()
        {
            //Fix loading of modernization framework
            FixLocalAssemblyResolving();

            // Load the page to transform
            Identity.Library       = this.Library;
            Identity.Folder        = this.Folder;
            Identity.BlogPage      = this.BlogPage;
            Identity.DelveBlogPage = this.DelveBlogPage;

            if ((this.PublishingPage && this.BlogPage) ||
                (this.PublishingPage && this.DelveBlogPage) ||
                (this.BlogPage && this.DelveBlogPage))
            {
                throw new Exception($"The page is either a blog page, a publishing page or a Delve blog page. Setting PublishingPage, BlogPage and DelveBlogPage to true is not valid.");
            }

            ListItem page = null;

            if (this.PublishingPage)
            {
                page = Identity.GetPage(this.ClientContext.Web, CacheManager.Instance.GetPublishingPagesLibraryName(this.ClientContext));
            }
            else if (this.BlogPage)
            {
                // Blogs don't live in other libraries or sub folders
                Identity.Library = null;
                Identity.Folder  = null;
                page             = Identity.GetPage(this.ClientContext.Web, CacheManager.Instance.GetBlogListName(this.ClientContext));
            }
            else if (this.DelveBlogPage)
            {
                // Blogs don't live in other libraries or sub folders
                Identity.Library = null;
                Identity.Folder  = null;
                page             = Identity.GetPage(this.ClientContext.Web, "pPg");
            }
            else
            {
                if (this.Folder == null || !this.Folder.Equals(rootFolder, StringComparison.InvariantCultureIgnoreCase))
                {
                    page = Identity.GetPage(this.ClientContext.Web, "sitepages");
                }
            }

            if (page == null && (Folder == null || !this.Folder.Equals(rootFolder, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new Exception($"Page '{Identity?.Name}' does not exist");
            }

            // Publishing specific validation
            if (this.PublishingPage && string.IsNullOrEmpty(this.TargetWebUrl) && TargetConnection == null)
            {
                throw new Exception($"Publishing page transformation is only supported when transformating into another site collection. Use the -TargetWebUrl to specify a modern target site.");
            }

            // Blog specific validation
            if ((this.BlogPage || this.DelveBlogPage) && string.IsNullOrEmpty(this.TargetWebUrl) && TargetConnection == null)
            {
                throw new Exception($"Blog and Delve blog page transformation is only supported when transformating into another site collection. Use the -TargetWebUrl to specify a modern target site.");
            }

            // Load transformation models
            PageTransformation webPartMappingModel = null;

            if (string.IsNullOrEmpty(this.WebPartMappingFile))
            {
                webPartMappingModel = PageTransformator.LoadDefaultWebPartMapping();
                this.WriteVerbose("Using embedded webpartmapping file. Use Export-PnPClientSidePageMapping to get that file in case you want to base your version of the embedded version.");
            }

            // 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");
                }
            }

            if (this.PublishingPage && !string.IsNullOrEmpty(this.PageLayoutMapping) && !System.IO.File.Exists(this.PageLayoutMapping))
            {
                throw new Exception($"Provided pagelayout mapping file {this.PageLayoutMapping} does not exist");
            }

            bool crossSiteTransformation = TargetConnection != null || !string.IsNullOrEmpty(TargetWebUrl);

            // Create target client context (when needed)
            ClientContext targetContext = null;

            if (TargetConnection == null)
            {
                if (!string.IsNullOrEmpty(TargetWebUrl))
                {
                    targetContext = this.ClientContext.Clone(TargetWebUrl);
                }
            }
            else
            {
                targetContext = TargetConnection.Context;
            }


            // Create transformator instance
            PageTransformator           pageTransformator           = null;
            PublishingPageTransformator publishingPageTransformator = null;
            DelvePageTransformator      delvePageTransformator      = null;

            if (!string.IsNullOrEmpty(this.WebPartMappingFile))
            {
                // Using custom web part mapping file
                if (this.PublishingPage)
                {
                    if (!string.IsNullOrEmpty(this.PageLayoutMapping))
                    {
                        // Using custom page layout mapping file + default one (they're merged together)
                        publishingPageTransformator = new PublishingPageTransformator(this.ClientContext, targetContext, this.WebPartMappingFile, this.PageLayoutMapping);
                    }
                    else
                    {
                        // Using default page layout mapping file
                        publishingPageTransformator = new PublishingPageTransformator(this.ClientContext, targetContext, this.WebPartMappingFile, null);
                    }
                }
                else if (this.DelveBlogPage)
                {
                    delvePageTransformator = new DelvePageTransformator(this.ClientContext, targetContext, this.WebPartMappingFile);
                }
                else
                {
                    // Use web part mapping file
                    pageTransformator = new PageTransformator(this.ClientContext, targetContext, this.WebPartMappingFile);
                }
            }
            else
            {
                // Using default web part mapping file
                if (this.PublishingPage)
                {
                    if (!string.IsNullOrEmpty(this.PageLayoutMapping))
                    {
                        // Load and validate the custom mapping file
                        PageLayoutManager pageLayoutManager = new PageLayoutManager();
                        var pageLayoutMappingModel          = pageLayoutManager.LoadPageLayoutMappingFile(this.PageLayoutMapping);

                        // Using custom page layout mapping file + default one (they're merged together)
                        publishingPageTransformator = new PublishingPageTransformator(this.ClientContext, targetContext, webPartMappingModel, pageLayoutMappingModel);
                    }
                    else
                    {
                        // Using default page layout mapping file
                        publishingPageTransformator = new PublishingPageTransformator(this.ClientContext, targetContext, webPartMappingModel, null);
                    }
                }
                else if (this.DelveBlogPage)
                {
                    delvePageTransformator = new DelvePageTransformator(this.ClientContext, targetContext, webPartMappingModel);
                }
                else
                {
                    // Use web part mapping model loaded from embedded mapping file
                    pageTransformator = new PageTransformator(this.ClientContext, targetContext, webPartMappingModel);
                }
            }

            // Setup logging
            if (this.LogType == ClientSidePageTransformatorLogType.File)
            {
                if (this.PublishingPage)
                {
                    publishingPageTransformator.RegisterObserver(new MarkdownObserver(folder: this.LogFolder, includeVerbose: this.LogVerbose, includeDebugEntries: this.LogVerbose));
                }
                else if (this.DelveBlogPage)
                {
                    delvePageTransformator.RegisterObserver(new MarkdownObserver(folder: this.LogFolder, includeVerbose: this.LogVerbose, includeDebugEntries: this.LogVerbose));
                }
                else
                {
                    pageTransformator.RegisterObserver(new MarkdownObserver(folder: this.LogFolder, includeVerbose: this.LogVerbose, includeDebugEntries: this.LogVerbose));
                }
            }
            else if (this.LogType == ClientSidePageTransformatorLogType.SharePoint)
            {
                if (this.PublishingPage)
                {
                    publishingPageTransformator.RegisterObserver(new MarkdownToSharePointObserver(targetContext ?? this.ClientContext, includeVerbose: this.LogVerbose, includeDebugEntries: this.LogVerbose));
                }
                else if (this.DelveBlogPage)
                {
                    delvePageTransformator.RegisterObserver(new MarkdownToSharePointObserver(targetContext ?? this.ClientContext, includeVerbose: this.LogVerbose, includeDebugEntries: this.LogVerbose));
                }
                else
                {
                    pageTransformator.RegisterObserver(new MarkdownToSharePointObserver(targetContext ?? this.ClientContext, includeVerbose: this.LogVerbose, includeDebugEntries: this.LogVerbose));
                }
            }
            else if (this.LogType == ClientSidePageTransformatorLogType.Console)
            {
                if (this.PublishingPage)
                {
                    publishingPageTransformator.RegisterObserver(new ConsoleObserver(includeDebugEntries: this.LogVerbose));
                }
                else if (this.DelveBlogPage)
                {
                    delvePageTransformator.RegisterObserver(new ConsoleObserver(includeDebugEntries: this.LogVerbose));
                }
                else
                {
                    pageTransformator.RegisterObserver(new ConsoleObserver(includeDebugEntries: this.LogVerbose));
                }
            }

            // Clear the client side component cache
            if (this.ClearCache)
            {
                CacheManager.Instance.ClearAllCaches();
            }

            string serverRelativeClientPageUrl = "";

            if (this.PublishingPage)
            {
                // Setup Transformation information
                PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page)
                {
                    Overwrite = this.Overwrite,
                    KeepPageSpecificPermissions             = !this.SkipItemLevelPermissionCopyToClientSidePage,
                    PublishCreatedPage                      = !this.DontPublish,
                    KeepPageCreationModificationInformation = this.KeepPageCreationModificationInformation,
                    PostAsNews                             = this.PostAsNews,
                    DisablePageComments                    = this.DisablePageComments,
                    TargetPageName                         = !string.IsNullOrEmpty(this.PublishingTargetPageName) ? this.PublishingTargetPageName : this.TargetPageName,
                    SkipUrlRewrite                         = this.SkipUrlRewriting,
                    SkipDefaultUrlRewrite                  = this.SkipDefaultUrlRewriting,
                    UrlMappingFile                         = this.UrlMappingFile,
                    AddTableListImageAsImageWebPart        = this.AddTableListImageAsImageWebPart,
                    SkipUserMapping                        = this.SkipUserMapping,
                    UserMappingFile                        = this.UserMappingFile,
                    LDAPConnectionString                   = this.LDAPConnectionString,
                    TargetPageFolder                       = this.TargetPageFolder,
                    TargetPageFolderOverridesDefaultFolder = this.TargetPageFolderOverridesDefaultFolder,
                    TermMappingFile                        = TermMappingFile,
                    SkipTermStoreMapping                   = SkipTermStoreMapping,
                    RemoveEmptySectionsAndColumns          = this.RemoveEmptySectionsAndColumns
                };

                // Set mapping properties
                pti.MappingProperties["SummaryLinksToQuickLinks"] = (!SummaryLinksToHtml).ToString().ToLower();
                pti.MappingProperties["UseCommunityScriptEditor"] = UseCommunityScriptEditor.ToString().ToLower();

                try
                {
                    serverRelativeClientPageUrl = publishingPageTransformator.Transform(pti);
                }
                finally
                {
                    // Flush log
                    if (this.LogType != ClientSidePageTransformatorLogType.None && this.LogType != ClientSidePageTransformatorLogType.Console && !this.LogSkipFlush)
                    {
                        publishingPageTransformator.FlushObservers();
                    }
                }
            }
            else if (this.DelveBlogPage)
            {
                // Setup Transformation information
                DelvePageTransformationInformation pti = new DelvePageTransformationInformation(page)
                {
                    Overwrite = this.Overwrite,
                    KeepPageSpecificPermissions             = !this.SkipItemLevelPermissionCopyToClientSidePage,
                    PublishCreatedPage                      = !this.DontPublish,
                    KeepPageCreationModificationInformation = this.KeepPageCreationModificationInformation,
                    SetAuthorInPageHeader                   = this.SetAuthorInPageHeader,
                    PostAsNews                             = this.PostAsNews,
                    DisablePageComments                    = this.DisablePageComments,
                    TargetPageName                         = crossSiteTransformation ? this.TargetPageName : "",
                    SkipUrlRewrite                         = this.SkipUrlRewriting,
                    SkipDefaultUrlRewrite                  = this.SkipDefaultUrlRewriting,
                    UrlMappingFile                         = this.UrlMappingFile,
                    AddTableListImageAsImageWebPart        = this.AddTableListImageAsImageWebPart,
                    SkipUserMapping                        = this.SkipUserMapping,
                    UserMappingFile                        = this.UserMappingFile,
                    LDAPConnectionString                   = this.LDAPConnectionString,
                    TargetPageFolder                       = this.TargetPageFolder,
                    TargetPageFolderOverridesDefaultFolder = this.TargetPageFolderOverridesDefaultFolder,
                    RemoveEmptySectionsAndColumns          = this.RemoveEmptySectionsAndColumns
                };

                // Set mapping properties
                pti.MappingProperties["SummaryLinksToQuickLinks"] = (!SummaryLinksToHtml).ToString().ToLower();
                pti.MappingProperties["UseCommunityScriptEditor"] = UseCommunityScriptEditor.ToString().ToLower();

                try
                {
                    serverRelativeClientPageUrl = delvePageTransformator.Transform(pti);
                }
                finally
                {
                    // Flush log
                    if (this.LogType != ClientSidePageTransformatorLogType.None && this.LogType != ClientSidePageTransformatorLogType.Console && !this.LogSkipFlush)
                    {
                        pageTransformator.FlushObservers();
                    }
                }
            }
            else
            {
                Microsoft.SharePoint.Client.File fileToModernize = null;
                if (this.Folder != null && this.Folder.Equals(rootFolder, StringComparison.InvariantCultureIgnoreCase))
                {
                    // Load the page file from the site root folder
                    var webServerRelativeUrl = this.ClientContext.Web.EnsureProperty(p => p.ServerRelativeUrl);
                    fileToModernize = this.ClientContext.Web.GetFileByServerRelativeUrl($"{webServerRelativeUrl}/{this.Identity.Name}");
                    this.ClientContext.Load(fileToModernize);
                    this.ClientContext.ExecuteQueryRetry();
                }

                // Setup Transformation information
                PageTransformationInformation pti = new PageTransformationInformation(page)
                {
                    SourceFile = fileToModernize,
                    Overwrite  = this.Overwrite,
                    TargetPageTakesSourcePageName      = this.TakeSourcePageName,
                    ReplaceHomePageWithDefaultHomePage = this.ReplaceHomePageWithDefault,
                    KeepPageSpecificPermissions        = !this.SkipItemLevelPermissionCopyToClientSidePage,
                    CopyPageMetadata   = this.CopyPageMetadata,
                    PublishCreatedPage = !this.DontPublish,
                    KeepPageCreationModificationInformation = this.KeepPageCreationModificationInformation,
                    SetAuthorInPageHeader                  = this.SetAuthorInPageHeader,
                    PostAsNews                             = this.PostAsNews,
                    DisablePageComments                    = this.DisablePageComments,
                    TargetPageName                         = crossSiteTransformation ? this.TargetPageName : "",
                    SkipUrlRewrite                         = this.SkipUrlRewriting,
                    SkipDefaultUrlRewrite                  = this.SkipDefaultUrlRewriting,
                    UrlMappingFile                         = this.UrlMappingFile,
                    AddTableListImageAsImageWebPart        = this.AddTableListImageAsImageWebPart,
                    SkipUserMapping                        = this.SkipUserMapping,
                    UserMappingFile                        = this.UserMappingFile,
                    LDAPConnectionString                   = this.LDAPConnectionString,
                    TargetPageFolder                       = this.TargetPageFolder,
                    TargetPageFolderOverridesDefaultFolder = this.TargetPageFolderOverridesDefaultFolder,
                    ModernizationCenterInformation         = new ModernizationCenterInformation()
                    {
                        AddPageAcceptBanner = this.AddPageAcceptBanner
                    },
                    TermMappingFile               = TermMappingFile,
                    SkipTermStoreMapping          = SkipTermStoreMapping,
                    RemoveEmptySectionsAndColumns = this.RemoveEmptySectionsAndColumns
                };

                // Set mapping properties
                pti.MappingProperties["SummaryLinksToQuickLinks"] = (!SummaryLinksToHtml).ToString().ToLower();
                pti.MappingProperties["UseCommunityScriptEditor"] = UseCommunityScriptEditor.ToString().ToLower();

                try
                {
                    serverRelativeClientPageUrl = pageTransformator.Transform(pti);
                }
                finally
                {
                    // Flush log
                    if (this.LogType != ClientSidePageTransformatorLogType.None && this.LogType != ClientSidePageTransformatorLogType.Console && !this.LogSkipFlush)
                    {
                        pageTransformator.FlushObservers();
                    }
                }
            }

            // Output the server relative url to the newly created page
            if (!string.IsNullOrEmpty(serverRelativeClientPageUrl))
            {
                WriteObject(serverRelativeClientPageUrl);
            }
        }
示例#3
0
        protected override void ExecuteCmdlet()
        {
            //Fix loading of modernization framework
            FixLocalAssemblyResolving();

            // Load the page to transform
            Identity.Library = this.Library;
            Identity.Folder  = this.Folder;

            ListItem page = null;

            if (this.PublishingPage)
            {
                page = Identity.GetPage(this.ClientContext.Web, CacheManager.Instance.GetPublishingPagesLibraryName(this.ClientContext));
            }
            else
            {
                if (this.Folder == null || !this.Folder.Equals(rootFolder, StringComparison.InvariantCultureIgnoreCase))
                {
                    page = Identity.GetPage(this.ClientContext.Web, "sitepages");
                }
            }

            if (page == null && !this.Folder.Equals(rootFolder, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Exception($"Page '{Identity?.Name}' does not exist");
            }

            // Publishing specific validation
            if (this.PublishingPage && string.IsNullOrEmpty(this.TargetWebUrl) && TargetConnection == null)
            {
                throw new Exception($"Publishing page transformation is only supported when transformating into another site collection. Use the -TargetWebUrl to specify a modern target site.");
            }

            // Load transformation models
            PageTransformation webPartMappingModel = null;

            if (string.IsNullOrEmpty(this.WebPartMappingFile))
            {
                // Load xml mapping data
                XmlSerializer xmlMapping = new XmlSerializer(typeof(PageTransformation));

                // Load the default one from resources into a model, no need for persisting this file
                string webpartMappingFileContents = WebPartMappingLoader.LoadFile("SharePointPnP.PowerShell.Commands.ClientSidePages.webpartmapping.xml");

                using (var stream = GenerateStreamFromString(webpartMappingFileContents))
                {
                    webPartMappingModel = (PageTransformation)xmlMapping.Deserialize(stream);
                }

                this.WriteVerbose("Using embedded webpartmapping file. Use Export-PnPClientSidePageMapping to get that file in case you want to base your version of the embedded version.");
            }

            // 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");
                }
            }

            if (this.PublishingPage && !string.IsNullOrEmpty(this.PageLayoutMapping) && !System.IO.File.Exists(this.PageLayoutMapping))
            {
                throw new Exception($"Provided pagelayout mapping file {this.PageLayoutMapping} does not exist");
            }

            // Create target client context (when needed)
            ClientContext targetContext = null;

            if (TargetConnection == null)
            {
                if (!string.IsNullOrEmpty(TargetWebUrl))
                {
                    targetContext = this.ClientContext.Clone(TargetWebUrl);
                }
            }
            else
            {
                targetContext = TargetConnection.Context;
            }


            // Create transformator instance
            PageTransformator           pageTransformator           = null;
            PublishingPageTransformator publishingPageTransformator = null;

            if (!string.IsNullOrEmpty(this.WebPartMappingFile))
            {
                // Using custom web part mapping file
                if (this.PublishingPage)
                {
                    if (!string.IsNullOrEmpty(this.PageLayoutMapping))
                    {
                        // Using custom page layout mapping file + default one (they're merged together)
                        publishingPageTransformator = new PublishingPageTransformator(this.ClientContext, targetContext, this.WebPartMappingFile, this.PageLayoutMapping);
                    }
                    else
                    {
                        // Using default page layout mapping file
                        publishingPageTransformator = new PublishingPageTransformator(this.ClientContext, targetContext, this.WebPartMappingFile, null);
                    }
                }
                else
                {
                    // Use web part mapping file
                    pageTransformator = new PageTransformator(this.ClientContext, targetContext, this.WebPartMappingFile);
                }
            }
            else
            {
                // Using default web part mapping file
                if (this.PublishingPage)
                {
                    if (!string.IsNullOrEmpty(this.PageLayoutMapping))
                    {
                        // Load and validate the custom mapping file
                        PageLayoutManager pageLayoutManager = new PageLayoutManager();
                        var pageLayoutMappingModel          = pageLayoutManager.LoadPageLayoutMappingFile(this.PageLayoutMapping);

                        // Using custom page layout mapping file + default one (they're merged together)
                        publishingPageTransformator = new PublishingPageTransformator(this.ClientContext, targetContext, webPartMappingModel, pageLayoutMappingModel);
                    }
                    else
                    {
                        // Using default page layout mapping file
                        publishingPageTransformator = new PublishingPageTransformator(this.ClientContext, targetContext, webPartMappingModel, null);
                    }
                }
                else
                {
                    // Use web part mapping model loaded from embedded mapping file
                    pageTransformator = new PageTransformator(this.ClientContext, targetContext, webPartMappingModel);
                }
            }

            // Setup logging
            if (this.LogType == ClientSidePageTransformatorLogType.File)
            {
                if (this.PublishingPage)
                {
                    publishingPageTransformator.RegisterObserver(new MarkdownObserver(folder: this.LogFolder, includeVerbose: this.LogVerbose, includeDebugEntries: this.LogVerbose));
                }
                else
                {
                    pageTransformator.RegisterObserver(new MarkdownObserver(folder: this.LogFolder, includeVerbose: this.LogVerbose, includeDebugEntries: this.LogVerbose));
                }
            }
            else if (this.LogType == ClientSidePageTransformatorLogType.SharePoint)
            {
                if (this.PublishingPage)
                {
                    publishingPageTransformator.RegisterObserver(new MarkdownToSharePointObserver(targetContext ?? this.ClientContext, includeVerbose: this.LogVerbose, includeDebugEntries: this.LogVerbose));
                }
                else
                {
                    pageTransformator.RegisterObserver(new MarkdownToSharePointObserver(targetContext ?? this.ClientContext, includeVerbose: this.LogVerbose, includeDebugEntries: this.LogVerbose));
                }
            }

            // Clear the client side component cache
            if (this.ClearCache)
            {
                CacheManager.Instance.ClearAllCaches();
            }

            string serverRelativeClientPageUrl = "";

            if (this.PublishingPage)
            {
                // Setup Transformation information
                PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page)
                {
                    Overwrite = this.Overwrite,
                    KeepPageSpecificPermissions = !this.SkipItemLevelPermissionCopyToClientSidePage,
                    PublishCreatedPage          = !this.DontPublish,
                    DisablePageComments         = this.DisablePageComments,
                    TargetPageName = this.PublishingTargetPageName,
                    SkipUrlRewrite = this.SkipUrlRewriting
                };

                // Set mapping properties
                pti.MappingProperties["SummaryLinksToQuickLinks"] = (!SummaryLinksToHtml).ToString().ToLower();
                pti.MappingProperties["UseCommunityScriptEditor"] = UseCommunityScriptEditor.ToString().ToLower();

                serverRelativeClientPageUrl = publishingPageTransformator.Transform(pti);
            }
            else
            {
                Microsoft.SharePoint.Client.File fileToModernize = null;
                if (this.Folder != null && this.Folder.Equals(rootFolder, StringComparison.InvariantCultureIgnoreCase))
                {
                    // Load the page file from the site root folder
                    var webServerRelativeUrl = this.ClientContext.Web.EnsureProperty(p => p.ServerRelativeUrl);
                    fileToModernize = this.ClientContext.Web.GetFileByServerRelativeUrl($"{webServerRelativeUrl}/{this.Identity.Name}");
                    this.ClientContext.Load(fileToModernize);
                    this.ClientContext.ExecuteQueryRetry();
                }

                // Setup Transformation information
                PageTransformationInformation pti = new PageTransformationInformation(page)
                {
                    SourceFile = fileToModernize,
                    Overwrite  = this.Overwrite,
                    TargetPageTakesSourcePageName      = this.TakeSourcePageName,
                    ReplaceHomePageWithDefaultHomePage = this.ReplaceHomePageWithDefault,
                    KeepPageSpecificPermissions        = !this.SkipItemLevelPermissionCopyToClientSidePage,
                    CopyPageMetadata               = this.CopyPageMetadata,
                    PublishCreatedPage             = !this.DontPublish,
                    DisablePageComments            = this.DisablePageComments,
                    SkipUrlRewrite                 = this.SkipUrlRewriting,
                    ModernizationCenterInformation = new ModernizationCenterInformation()
                    {
                        AddPageAcceptBanner = this.AddPageAcceptBanner
                    },
                };

                // Set mapping properties
                pti.MappingProperties["SummaryLinksToQuickLinks"] = (!SummaryLinksToHtml).ToString().ToLower();
                pti.MappingProperties["UseCommunityScriptEditor"] = UseCommunityScriptEditor.ToString().ToLower();

                serverRelativeClientPageUrl = pageTransformator.Transform(pti);
            }

            // Flush log
            if (this.LogType != ClientSidePageTransformatorLogType.None)
            {
                if (!this.LogSkipFlush)
                {
                    if (this.PublishingPage)
                    {
                        publishingPageTransformator.FlushObservers();
                    }
                    else
                    {
                        pageTransformator.FlushObservers();
                    }
                }
            }

            // Output the server relative url to the newly created page
            if (!string.IsNullOrEmpty(serverRelativeClientPageUrl))
            {
                WriteObject(serverRelativeClientPageUrl);
            }
        }
示例#4
0
        protected override void ExecuteCmdlet()
        {
            //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");
            }

            PageTransformation webPartMappingModel = null;

            if (string.IsNullOrEmpty(this.WebPartMappingFile))
            {
                // Load xml mapping data
                XmlSerializer xmlMapping = new XmlSerializer(typeof(PageTransformation));

                // Load the default one from resources into a model, no need for persisting this file
                string webpartMappingFileContents = WebPartMappingLoader.LoadFile("SharePointPnP.PowerShell.Commands.ClientSidePages.webpartmapping.xml");

                using (var stream = GenerateStreamFromString(webpartMappingFileContents))
                {
                    webPartMappingModel = (PageTransformation)xmlMapping.Deserialize(stream);
                }

                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 target client context (when needed)
            ClientContext targetContext = null;

            if (!string.IsNullOrEmpty(TargetWebUrl))
            {
                targetContext = this.ClientContext.Clone(TargetWebUrl);
            }

            // Create transformator instance
            PageTransformator pageTransformator = null;

            if (!string.IsNullOrEmpty(this.WebPartMappingFile))
            {
                // Use web part mapping file
                pageTransformator = new PageTransformator(this.ClientContext, targetContext, this.WebPartMappingFile);
            }
            else
            {
                // Use web part mapping model loaded from embedded mapping file
                pageTransformator = new PageTransformator(this.ClientContext, targetContext, webPartMappingModel);
            }

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

            // Set mapping properties
            pti.MappingProperties["SummaryLinksToQuickLinks"] = (!SummaryLinksToHtml).ToString().ToLower();
            pti.MappingProperties["UseCommunityScriptEditor"] = UseCommunityScriptEditor.ToString().ToLower();

            // Clear the client side component cache
            if (this.ClearCache)
            {
                CacheManager.Instance.ClearAllCaches();
            }

            string serverRelativeClientPageUrl = pageTransformator.Transform(pti);

            // Output the server relative url to the newly created page
            if (!string.IsNullOrEmpty(serverRelativeClientPageUrl))
            {
                WriteObject(serverRelativeClientPageUrl);
            }
        }
示例#5
0
 internal HistoryInfo[] GetEntries(WildcardPattern wildcardpattern, long count, SwitchParameter newest)
 {
     lock (this._syncRoot)
     {
         if (count < -1L)
         {
             throw PSTraceSource.NewArgumentOutOfRangeException("count", count);
         }
         if (newest.ToString() == null)
         {
             throw PSTraceSource.NewArgumentNullException("newest");
         }
         if ((count > this._countEntriesAdded) || (count == -1L))
         {
             count = this._countEntriesInBuffer;
         }
         ArrayList list = new ArrayList();
         long      num  = 1L;
         if (this._capacity != 0x1000)
         {
             num = this.SmallestIDinBuffer();
         }
         if (count != 0L)
         {
             if (!newest.IsPresent)
             {
                 long id = 1L;
                 if ((this._capacity != 0x1000) && (this._countEntriesAdded > this._capacity))
                 {
                     id = num;
                 }
                 long num3 = 0L;
                 while (num3 <= (count - 1L))
                 {
                     if (id > this._countEntriesAdded)
                     {
                         break;
                     }
                     if (!this._buffer[this.GetIndexFromId(id)].Cleared && wildcardpattern.IsMatch(this._buffer[this.GetIndexFromId(id)].CommandLine.Trim()))
                     {
                         list.Add(this._buffer[this.GetIndexFromId(id)].Clone());
                         num3 += 1L;
                     }
                     id += 1L;
                 }
             }
             else
             {
                 long num4 = this._countEntriesAdded;
                 long num5 = 0L;
                 while (num5 <= (count - 1L))
                 {
                     if ((((this._capacity != 0x1000) && (this._countEntriesAdded > this._capacity)) && (num4 < num)) || (num4 < 1L))
                     {
                         break;
                     }
                     if (!this._buffer[this.GetIndexFromId(num4)].Cleared && wildcardpattern.IsMatch(this._buffer[this.GetIndexFromId(num4)].CommandLine.Trim()))
                     {
                         list.Add(this._buffer[this.GetIndexFromId(num4)].Clone());
                         num5 += 1L;
                     }
                     num4 -= 1L;
                 }
             }
         }
         else
         {
             for (long i = 1L; i <= this._countEntriesAdded; i += 1L)
             {
                 if (!this._buffer[this.GetIndexFromId(i)].Cleared && wildcardpattern.IsMatch(this._buffer[this.GetIndexFromId(i)].CommandLine.Trim()))
                 {
                     list.Add(this._buffer[this.GetIndexFromId(i)].Clone());
                 }
             }
         }
         HistoryInfo[] array = new HistoryInfo[list.Count];
         list.CopyTo(array);
         return(array);
     }
 }
示例#6
0
 internal HistoryInfo[] GetEntries(long id, long count, SwitchParameter newest)
 {
     this.ReallocateBufferIfNeeded();
     if (count < -1L)
     {
         throw PSTraceSource.NewArgumentOutOfRangeException("count", count);
     }
     if (newest.ToString() == null)
     {
         throw PSTraceSource.NewArgumentNullException("newest");
     }
     if (((count == -1L) || (count > this._countEntriesAdded)) || (count > this._countEntriesInBuffer))
     {
         count = this._countEntriesInBuffer;
     }
     if ((count == 0L) || (this._countEntriesInBuffer == 0))
     {
         return(new HistoryInfo[0]);
     }
     lock (this._syncRoot)
     {
         ArrayList list = new ArrayList();
         if (id > 0L)
         {
             long num;
             long num2 = id;
             if (!newest.IsPresent)
             {
                 num = (num2 - count) + 1L;
                 if (num < 1L)
                 {
                     num = 1L;
                 }
                 for (long i = num2; i >= num; i -= 1L)
                 {
                     if (num <= 1L)
                     {
                         break;
                     }
                     if ((this._buffer[this.GetIndexFromId(i)] != null) && this._buffer[this.GetIndexFromId(i)].Cleared)
                     {
                         num -= 1L;
                     }
                 }
                 for (long j = num; j <= num2; j += 1L)
                 {
                     if ((this._buffer[this.GetIndexFromId(j)] != null) && !this._buffer[this.GetIndexFromId(j)].Cleared)
                     {
                         list.Add(this._buffer[this.GetIndexFromId(j)].Clone());
                     }
                 }
             }
             else
             {
                 num = (num2 + count) - 1L;
                 if (num >= this._countEntriesAdded)
                 {
                     num = this._countEntriesAdded;
                 }
                 for (long k = num2; k <= num; k += 1L)
                 {
                     if (num >= this._countEntriesAdded)
                     {
                         break;
                     }
                     if ((this._buffer[this.GetIndexFromId(k)] != null) && this._buffer[this.GetIndexFromId(k)].Cleared)
                     {
                         num += 1L;
                     }
                 }
                 for (long m = num; m >= num2; m -= 1L)
                 {
                     if ((this._buffer[this.GetIndexFromId(m)] != null) && !this._buffer[this.GetIndexFromId(m)].Cleared)
                     {
                         list.Add(this._buffer[this.GetIndexFromId(m)].Clone());
                     }
                 }
             }
         }
         else
         {
             long num7;
             long num8 = 0L;
             if (this._capacity != 0x1000)
             {
                 num8 = this.SmallestIDinBuffer();
             }
             if (!newest.IsPresent)
             {
                 num7 = 1L;
                 if ((this._capacity != 0x1000) && (this._countEntriesAdded > this._capacity))
                 {
                     num7 = num8;
                 }
                 long num9 = count - 1L;
                 while (num9 >= 0L)
                 {
                     if (num7 > this._countEntriesAdded)
                     {
                         break;
                     }
                     if (((num7 <= 0L) || (this.GetIndexFromId(num7) >= this._buffer.Length)) || this._buffer[this.GetIndexFromId(num7)].Cleared)
                     {
                         num7 += 1L;
                     }
                     else
                     {
                         list.Add(this._buffer[this.GetIndexFromId(num7)].Clone());
                         num9 -= 1L;
                         num7 += 1L;
                     }
                 }
             }
             else
             {
                 num7 = this._countEntriesAdded;
                 long num10 = count - 1L;
                 while (num10 >= 0L)
                 {
                     if ((((this._capacity != 0x1000) && (this._countEntriesAdded > this._capacity)) && (num7 < num8)) || (num7 < 1L))
                     {
                         break;
                     }
                     if (((num7 <= 0L) || (this.GetIndexFromId(num7) >= this._buffer.Length)) || this._buffer[this.GetIndexFromId(num7)].Cleared)
                     {
                         num7 -= 1L;
                     }
                     else
                     {
                         list.Add(this._buffer[this.GetIndexFromId(num7)].Clone());
                         num10 -= 1L;
                         num7  -= 1L;
                     }
                 }
             }
         }
         HistoryInfo[] array = new HistoryInfo[list.Count];
         list.CopyTo(array);
         return(array);
     }
 }
示例#7
0
 internal HistoryInfo[] GetEntries(
     WildcardPattern wildcardpattern,
     long count,
     SwitchParameter newest)
 {
     using (History._trace.TraceMethod())
     {
         lock (this._syncRoot)
         {
             if (count < -1L)
             {
                 throw History._trace.NewArgumentOutOfRangeException(nameof(count), (object)count);
             }
             if (newest.ToString() == null)
             {
                 throw History._trace.NewArgumentNullException(nameof(newest));
             }
             if (count > this._countEntriesAdded || count == -1L)
             {
                 count = (long)this._countEntriesInBuffer;
             }
             ArrayList arrayList = new ArrayList();
             long      num       = 1;
             if (this._capacity != 64)
             {
                 num = this.SmallestIDinBuffer();
             }
             if (count != 0L)
             {
                 if (!newest.IsPresent)
                 {
                     long id = 1;
                     if (this._capacity != 64 && this._countEntriesAdded > (long)this._capacity)
                     {
                         id = num;
                     }
                     for (long index = 0; index <= count - 1L && id <= this._countEntriesAdded; ++id)
                     {
                         if (!this._buffer[this.GetIndexFromId(id)].Cleared && wildcardpattern.IsMatch(this._buffer[this.GetIndexFromId(id)].CommandLine.Trim()))
                         {
                             arrayList.Add((object)this._buffer[this.GetIndexFromId(id)].Clone());
                             ++index;
                         }
                     }
                 }
                 else
                 {
                     long countEntriesAdded = this._countEntriesAdded;
                     for (long index = 0; index <= count - 1L && (this._capacity == 64 || this._countEntriesAdded <= (long)this._capacity || countEntriesAdded >= num) && countEntriesAdded >= 1L; --countEntriesAdded)
                     {
                         if (!this._buffer[this.GetIndexFromId(countEntriesAdded)].Cleared && wildcardpattern.IsMatch(this._buffer[this.GetIndexFromId(countEntriesAdded)].CommandLine.Trim()))
                         {
                             arrayList.Add((object)this._buffer[this.GetIndexFromId(countEntriesAdded)].Clone());
                             ++index;
                         }
                     }
                 }
             }
             else
             {
                 for (long id = 1; id <= this._countEntriesAdded; ++id)
                 {
                     if (!this._buffer[this.GetIndexFromId(id)].Cleared && wildcardpattern.IsMatch(this._buffer[this.GetIndexFromId(id)].CommandLine.Trim()))
                     {
                         arrayList.Add((object)this._buffer[this.GetIndexFromId(id)].Clone());
                     }
                 }
             }
             HistoryInfo[] historyInfoArray = new HistoryInfo[arrayList.Count];
             arrayList.CopyTo((Array)historyInfoArray);
             return(historyInfoArray);
         }
     }
 }
示例#8
0
 internal HistoryInfo[] GetEntries(long id, long count, SwitchParameter newest)
 {
     using (History._trace.TraceMethod())
     {
         this.ReallocateBufferIfNeeded();
         if (count < -1L)
         {
             throw History._trace.NewArgumentOutOfRangeException(nameof(count), (object)count);
         }
         if (newest.ToString() == null)
         {
             throw History._trace.NewArgumentNullException(nameof(newest));
         }
         if (count == -1L || count > this._countEntriesAdded || count > (long)this._countEntriesInBuffer)
         {
             count = (long)this._countEntriesInBuffer;
         }
         if (count == 0L || this._countEntriesInBuffer == 0)
         {
             return(new HistoryInfo[0]);
         }
         lock (this._syncRoot)
         {
             ArrayList arrayList = new ArrayList();
             if (id > 0L)
             {
                 long num1 = id;
                 if (!newest.IsPresent)
                 {
                     long num2 = num1 - count + 1L;
                     if (num2 < 1L)
                     {
                         num2 = 1L;
                     }
                     for (long id1 = num1; id1 >= num2 && num2 > 1L; --id1)
                     {
                         if (this._buffer[this.GetIndexFromId(id1)] != null && this._buffer[this.GetIndexFromId(id1)].Cleared)
                         {
                             --num2;
                         }
                     }
                     for (long id1 = num2; id1 <= num1; ++id1)
                     {
                         if (this._buffer[this.GetIndexFromId(id1)] != null && !this._buffer[this.GetIndexFromId(id1)].Cleared)
                         {
                             arrayList.Add((object)this._buffer[this.GetIndexFromId(id1)].Clone());
                         }
                     }
                 }
                 else
                 {
                     long num2 = num1 + count - 1L;
                     if (num2 >= this._countEntriesAdded)
                     {
                         num2 = this._countEntriesAdded;
                     }
                     for (long id1 = num1; id1 <= num2 && num2 < this._countEntriesAdded; ++id1)
                     {
                         if (this._buffer[this.GetIndexFromId(id1)] != null && this._buffer[this.GetIndexFromId(id1)].Cleared)
                         {
                             ++num2;
                         }
                     }
                     for (long id1 = num2; id1 >= num1; --id1)
                     {
                         if (this._buffer[this.GetIndexFromId(id1)] != null && !this._buffer[this.GetIndexFromId(id1)].Cleared)
                         {
                             arrayList.Add((object)this._buffer[this.GetIndexFromId(id1)].Clone());
                         }
                     }
                 }
             }
             else
             {
                 long num1 = 0;
                 if (this._capacity != 64)
                 {
                     num1 = this.SmallestIDinBuffer();
                 }
                 if (!newest.IsPresent)
                 {
                     long id1 = 1;
                     if (this._capacity != 64 && this._countEntriesAdded > (long)this._capacity)
                     {
                         id1 = num1;
                     }
                     long num2 = count - 1L;
                     while (num2 >= 0L && id1 <= this._countEntriesAdded)
                     {
                         if (this._buffer[this.GetIndexFromId(id1)].Cleared)
                         {
                             ++id1;
                         }
                         else
                         {
                             arrayList.Add((object)this._buffer[this.GetIndexFromId(id1)].Clone());
                             --num2;
                             ++id1;
                         }
                     }
                 }
                 else
                 {
                     long countEntriesAdded = this._countEntriesAdded;
                     long num2 = count - 1L;
                     while (num2 >= 0L && (this._capacity == 64 || this._countEntriesAdded <= (long)this._capacity || countEntriesAdded >= num1) && countEntriesAdded >= 1L)
                     {
                         if (this._buffer[this.GetIndexFromId(countEntriesAdded)].Cleared)
                         {
                             --countEntriesAdded;
                         }
                         else
                         {
                             arrayList.Add((object)this._buffer[this.GetIndexFromId(countEntriesAdded)].Clone());
                             --num2;
                             --countEntriesAdded;
                         }
                     }
                 }
             }
             HistoryInfo[] historyInfoArray = new HistoryInfo[arrayList.Count];
             arrayList.CopyTo((Array)historyInfoArray);
             return(historyInfoArray);
         }
     }
 }