public void PageLayoutAnalyse_AnalyseByPageWithOutput() { using (var sourceClientContext = TestCommon.CreateClientContext()) { var pageLayoutAnalyser = new PageLayoutAnalyser(sourceClientContext); pageLayoutAnalyser.RegisterObserver(new UnitTestLogObserver()); var pageUrl = $"{sourceClientContext.Web.EnsureProperty(o => o.ServerRelativeUrl)}/pages/Article-Custom.aspx"; var publishingPage = sourceClientContext.Web.GetFileByServerRelativeUrl(pageUrl); var result = string.Empty; if (publishingPage != null && publishingPage.ServerObjectIsNull != true) { ListItem item = publishingPage.EnsureProperty(o => o.ListItemAllFields); pageLayoutAnalyser.AnalysePageLayoutFromPublishingPage(item); result = pageLayoutAnalyser.GenerateMappingFile(); } else { Assert.Fail("Failed to retrieve object for the test"); } Assert.IsTrue(result != string.Empty); } }
public void OnPremPageLayout_AnalyzeByPages_Test() { using (var context = TestCommon.CreateOnPremisesClientContext()) { var pages = context.Web.GetPagesFromList("Pages", pageNameStartsWith: "Article-2010-Taxonomy.aspx"); var analyzer = new PageLayoutAnalyser(context); int errorCount = 0; foreach (var page in pages) { try { analyzer.AnalysePageLayoutFromPublishingPage(page); } catch (Exception ex) { Console.WriteLine("Error {0} {1}", ex.Message, ex.StackTrace); errorCount++; } } Console.WriteLine("Error Count {0}", errorCount); Assert.IsTrue((errorCount == 0)); analyzer.GenerateMappingFile("c:\\temp", "onprem-mapping-test-taxonomy.xml"); } }
public void PageLayoutAnalyse_AnalyseSingleWithOutput() { using (var sourceClientContext = TestCommon.CreateClientContext()) { // Source Context could be a site collection ClientContext contextToUse; if (sourceClientContext.Web.IsSubSite()) { string siteCollectionUrl = sourceClientContext.Site.EnsureProperty(o => o.Url); contextToUse = sourceClientContext.Clone(siteCollectionUrl); } else { contextToUse = sourceClientContext; } var pageLayoutAnalyser = new PageLayoutAnalyser(sourceClientContext); pageLayoutAnalyser.RegisterObserver(new UnitTestLogObserver()); var layout = contextToUse.Web.GetFileByServerRelativeUrl($"{contextToUse.Web.EnsureProperty(o => o.ServerRelativeUrl)}/_catalogs/masterpage/ArticleCustom.aspx"); var result = string.Empty; if (layout != null) { ListItem item = layout.EnsureProperty(o => o.ListItemAllFields); pageLayoutAnalyser.AnalysePageLayout(item); result = pageLayoutAnalyser.GenerateMappingFile(); } Assert.IsTrue(result != string.Empty); } }
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"); } }
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); } }
public void PageLayoutAnalyse_SimpleReadOutput() { using (var sourceClientContext = TestCommon.CreateClientContext()) { var pageLayoutAnalyser = new PageLayoutAnalyser(sourceClientContext); pageLayoutAnalyser.RegisterObserver(new UnitTestLogObserver()); //This will need option for target output location var result = pageLayoutAnalyser.GenerateMappingFile(); Console.WriteLine("Mapping file: {0}", result); Assert.IsNotNull(result); } }
public void PageLayout_AnalyzeByPages_Test() { //https://bertonline.sharepoint.com/sites/modernizationtestportal using (var sourceClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPODevSiteUrl"))) { var pages = sourceClientContext.Web.GetPagesFromList("Pages"); var analyzer = new PageLayoutAnalyser(sourceClientContext); foreach (var page in pages) { analyzer.AnalysePageLayoutFromPublishingPage(page); } analyzer.GenerateMappingFile("c:\\temp", "mappingtest.xml"); } }
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); } } }
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); } } }