public void OnPremPageLayout_AnalyseAll_Test()
        {
            using (var context = TestCommon.CreateOnPremisesClientContext())
            {
                var analyzer = new PageLayoutAnalyser(context);
                analyzer.AnalyseAll();

                analyzer.GenerateMappingFile("c:\\temp", "onprem-mapping-all-test.xml");
            }
        }
        public void PageLayout_AnalyseAll_Test()
        {
            //https://bertonline.sharepoint.com/sites/modernizationtestportal
            using (var sourceClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPODevSiteUrl")))
            {
                var analyzer = new PageLayoutAnalyser(sourceClientContext);
                analyzer.AnalyseAll();

                analyzer.GenerateMappingFile("c:\\temp", "mappingalltest.xml");
            }
        }
Пример #3
0
        public void PageLayoutAnalyse_AnalyseAllWithOutput()
        {
            using (var sourceClientContext = TestCommon.CreateClientContext())
            {
                var pageLayoutAnalyser = new PageLayoutAnalyser(sourceClientContext);
                pageLayoutAnalyser.RegisterObserver(new UnitTestLogObserver());

                pageLayoutAnalyser.AnalyseAll();
                var result = pageLayoutAnalyser.GenerateMappingFile();

                //This will need option for target output location
                Assert.IsNotNull(result);
            }
        }
        protected override void ExecuteCmdlet()
        {
            //Fix loading of modernization framework
            FixAssemblyResolving();

            // Configure folder to export
            string folderToExportTo = Environment.CurrentDirectory;

            if (!string.IsNullOrEmpty(this.Folder))
            {
                if (!Directory.Exists(this.Folder))
                {
                    throw new Exception($"Folder '{this.Folder}' does not exist");
                }

                folderToExportTo = this.Folder;
            }

            // Export built in web part mapping
            if (this.BuiltInWebPartMapping)
            {
                string fileName = Path.Combine(folderToExportTo, "webpartmapping.xml");

                if (System.IO.File.Exists(fileName) && !Overwrite)
                {
                    Console.WriteLine($"Skipping the export from the built-in webpart mapping file {fileName} as this already exists. Use the -Overwrite flag to overwrite if needed.");
                }
                else
                {
                    // 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");
                    System.IO.File.WriteAllText(fileName, webpartMappingFileContents);
                }
            }

            // Export built in page layout mapping
            if (this.BuiltInPageLayoutMapping)
            {
                string fileName = Path.Combine(folderToExportTo, "pagelayoutmapping.xml");

                if (System.IO.File.Exists(fileName) && !Overwrite)
                {
                    Console.WriteLine($"Skipping the export from the built-in pagelayout mapping file {fileName} as this already exists. Use the -Overwrite flag to overwrite if needed.");
                }
                else
                {
                    // Load the default one from resources into a model, no need for persisting this file
                    string pageLayoutMappingFileContents = WebPartMappingLoader.LoadFile("SharePointPnP.PowerShell.Commands.ClientSidePages.pagelayoutmapping.xml");
                    System.IO.File.WriteAllText(fileName, pageLayoutMappingFileContents);
                }
            }

            // Export custom page layout mapping
            if (this.CustomPageLayoutMapping)
            {
                if (!this.ClientContext.Web.IsPublishingWeb())
                {
                    throw new Exception("The -CustomPageLayoutMapping parameter only works for publishing sites.");
                }

                Guid   siteId   = this.ClientContext.Site.EnsureProperty(p => p.Id);
                string fileName = $"custompagelayoutmapping-{siteId.ToString()}.xml";

                if (System.IO.File.Exists(Path.Combine(folderToExportTo, fileName)) && !Overwrite)
                {
                    Console.WriteLine($"Skipping the export from the custom pagelayout mapping file {Path.Combine(folderToExportTo, fileName)} as this already exists. Use the -Overwrite flag to overwrite if needed.");
                }
                else
                {
                    var analyzer = new PageLayoutAnalyser(this.ClientContext);
                    analyzer.AnalyseAll();

                    analyzer.GenerateMappingFile(folderToExportTo, fileName);
                }
            }
        }
Пример #5
0
        protected override void ExecuteCmdlet()
        {
            //Fix loading of modernization framework
            FixLocalAssemblyResolving();

            // Configure folder to export
            string folderToExportTo = Environment.CurrentDirectory;

            if (!string.IsNullOrEmpty(this.Folder))
            {
                if (!Directory.Exists(this.Folder))
                {
                    throw new Exception($"Folder '{this.Folder}' does not exist");
                }

                folderToExportTo = this.Folder;
            }

            // Export built in web part mapping
            if (this.BuiltInWebPartMapping)
            {
                string fileName = Path.Combine(folderToExportTo, "webpartmapping.xml");

                if (System.IO.File.Exists(fileName) && !Overwrite)
                {
                    Console.WriteLine($"Skipping the export from the built-in webpart mapping file {fileName} as this already exists. Use the -Overwrite flag to overwrite if needed.");
                }
                else
                {
                    // Load the default one from resources into a model, no need for persisting this file
                    string webpartMappingFileContents = PageTransformator.LoadDefaultWebPartMappingFile();
                    System.IO.File.WriteAllText(fileName, webpartMappingFileContents);
                }
            }

            // Export built in page layout mapping
            if (this.BuiltInPageLayoutMapping)
            {
                string fileName = Path.Combine(folderToExportTo, "pagelayoutmapping.xml");

                if (System.IO.File.Exists(fileName) && !Overwrite)
                {
                    Console.WriteLine($"Skipping the export from the built-in pagelayout mapping file {fileName} as this already exists. Use the -Overwrite flag to overwrite if needed.");
                }
                else
                {
                    // Load the default one from resources into a model, no need for persisting this file
                    string pageLayoutMappingFileContents = PublishingPageTransformator.LoadDefaultPageLayoutMappingFile();
                    System.IO.File.WriteAllText(fileName, pageLayoutMappingFileContents);
                }
            }

            // Export custom page layout mapping
            if (this.CustomPageLayoutMapping)
            {
                if (!this.ClientContext.Web.IsPublishingWeb())
                {
                    throw new Exception("The -CustomPageLayoutMapping parameter only works for publishing sites.");
                }

                ListItem page = null;

                if (PublishingPage != null)
                {
                    page = PublishingPage.GetPage(this.ClientContext.Web, CacheManager.Instance.GetPublishingPagesLibraryName(this.ClientContext));
                }

                Guid siteId = this.ClientContext.Site.EnsureProperty(p => p.Id);

                string fileName = $"custompagelayoutmapping-{siteId.ToString()}.xml";

                if (page != null)
                {
                    fileName = $"custompagelayoutmapping-{siteId.ToString()}-{page.FieldValues["FileLeafRef"].ToString().ToLower().Replace(".aspx", "")}.xml";
                }

                if (System.IO.File.Exists(Path.Combine(folderToExportTo, fileName)) && !Overwrite)
                {
                    Console.WriteLine($"Skipping the export from the custom pagelayout mapping file {Path.Combine(folderToExportTo, fileName)} as this already exists. Use the -Overwrite flag to overwrite if needed.");
                }
                else
                {
                    var analyzer = new PageLayoutAnalyser(this.ClientContext);

                    if (Logging)
                    {
                        analyzer.RegisterObserver(new ConsoleObserver(false));
                    }

                    if (page != null)
                    {
                        analyzer.AnalysePageLayoutFromPublishingPage(page);
                    }
                    else
                    {
                        analyzer.AnalyseAll(!this.AnalyzeOOBPageLayouts);
                    }

                    analyzer.GenerateMappingFile(folderToExportTo, fileName);
                }
            }
        }