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 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 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 PageLayoutAnalyse_GetPageLayouts() { using (var sourceClientContext = TestCommon.CreateClientContext()) { var pageLayoutAnalyser = new PageLayoutAnalyser(sourceClientContext); pageLayoutAnalyser.RegisterObserver(new UnitTestLogObserver()); var result = pageLayoutAnalyser.GetAllPageLayouts(); //This will need option for target output location Assert.IsNotNull(result); Assert.IsTrue(result.Count > 0); } }
public void PageLayoutAnalyse_AspxHeaderAndNameSpaces() { 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 results = new List <Tuple <string, string> >(); if (layout != null) { ListItem item = layout.EnsureProperty(o => o.ListItemAllFields); results.AddRange(pageLayoutAnalyser.ExtractWebPartPrefixesFromNamespaces(item)); } else { Assert.Fail("Layout file is missing, upload ArticleCustom.aspx as a page layout and publish the file"); } Assert.IsTrue(results.Count > 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); } } }