public void PrincipalAccountTest() { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext()) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation() { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are should work given cross domain with mapping KeepPageSpecificPermissions = true, SourceVersion = SPVersion.SP2010 //example only }; UserTransformator userTransformator = new UserTransformator(pti, sourceClientContext, targetClientContext, null); var result = userTransformator.RemapPrincipal("test.user3"); Console.WriteLine(result); Assert.IsTrue(!string.IsNullOrEmpty(result)); } } }
/// <summary> /// Common Test for URL Rewriting /// </summary> /// <param name="input"></param> /// <param name="sourceSite"></param> /// <param name="sourceWeb"></param> /// <param name="targetWeb"></param> /// <param name="pagesLibrary"></param> /// <param name="expected"></param> public void CommonUrlReWriteTest(string input, string sourceSite, string sourceWeb, string targetWeb, string pagesLibrary, string expected) { //Pre-requisite objects using (var targetClientContext = TestCommon.CreateClientContext("https://capadevtest.sharepoint.com/sites/PnPSauceModern")) { using (var sourceClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPODevSiteUrl"))) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation() { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, KeepPageCreationModificationInformation = false, }; UrlTransformator urlTransform = new UrlTransformator(pti, sourceClientContext, targetClientContext); var result = urlTransform.ReWriteUrls(input, sourceSite, sourceWeb, targetWeb, pagesLibrary); Assert.AreEqual(expected, result); } } }
public void PublishingPageUrlTest() { using (var targetClientContext = TestCommon.CreateClientContext("https://capadevtest.sharepoint.com/sites/PnPSauceModern")) { using (var sourceClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPODevSiteUrl"))) { var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext); pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose: true)); //pageTransformator.RegisterObserver(new MarkdownToSharePointObserver(targetClientContext, includeVerbose: true)); var pages = sourceClientContext.Web.GetPagesFromList("Pages", folder: "News", pageNameStartsWith: "Hot-Off-The-Press"); foreach (var page in pages) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, KeepPageCreationModificationInformation = false, }; pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; var result = pageTransformator.Transform(pti); } pageTransformator.FlushObservers(); } } }
public void GetUPNFromAccountTest() { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext()) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation() { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are should work given cross domain with mapping KeepPageSpecificPermissions = true, // Replace User Mapping UserMappingFile = @"..\..\Transform\Mapping\usermapping_sample.csv" }; UserTransformator userTransformator = new UserTransformator(pti, sourceClientContext, targetClientContext, null); var result = userTransformator.SearchSourceDomainForUPN(AccountType.User, "test.user3"); Console.WriteLine(result); Assert.IsTrue(!string.IsNullOrEmpty(result)); } } }
public void GetUPNFromGroupWithSIDTest() { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext()) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation() { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are should work given cross domain with mapping KeepPageSpecificPermissions = true, // Replace User Mapping UserMappingFile = @"..\..\Transform\Mapping\usermapping_sample.csv" }; UserTransformator userTransformator = new UserTransformator(pti, sourceClientContext, targetClientContext, null); // SharePoint-Readers (note specific to PBs test rig) var result = userTransformator.SearchSourceDomainForUPN(AccountType.Group, "s-1-5-21-2364077317-3999105188-691961326-1129"); Console.WriteLine(result); Assert.IsTrue(!string.IsNullOrEmpty(result)); } } }
public void GetUPNFromAccountWithCustomLDAPPositiveTest() { var ldap = "LDAP://OU=CDT,OU=Demo Users,DC=AlphaDelta,DC=Local"; using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext()) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation() { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are should work given cross domain with mapping KeepPageSpecificPermissions = true, LDAPConnectionString = ldap }; UserTransformator userTransformator = new UserTransformator(pti, sourceClientContext, targetClientContext, null); var result = userTransformator.SearchSourceDomainForUPN(AccountType.User, "Cara.Irvine"); //User Outside of LDAP Connection String Console.WriteLine(result); Assert.IsTrue(!string.IsNullOrEmpty(result)); } } }
public void BasicOnPremPublishingPageUserMappingDefaultTest() { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext()) { //"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\SharePointPnP.Modernization.Framework.Tests\Transform\Publishing\custompagelayoutmapping.xml" //"C:\temp\onprem-mapping-all-test.xml.xml" var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"C:\temp\onprem-mapping-all-test.xml"); pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose: true, includeDebugEntries: true)); pageTransformator.RegisterObserver(new UnitTestLogObserver()); //var pages = sourceClientContext.Web.GetPagesFromList("Pages", "Article-2010-Custom"); //var pages = sourceClientContext.Web.GetPagesFromList("Pages", "ArticlePage-2010-Multiple"); //var pages = sourceClientContext.Web.GetPagesFromList("Pages", "Article-2010-Custom-Test3"); //var pages = sourceClientContext.Web.GetPagesFromList("Pages", folder:"News"); //var pages = sourceClientContext.Web.GetPagesFromList("Pages", "Welcome-2013Legacy"); var pages = sourceClientContext.Web.GetPagesFromList("Pages", "Article-Permissions"); pages.FailTestIfZero(); try { foreach (var page in pages) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are should work given cross domain with mapping KeepPageSpecificPermissions = true, KeepPageCreationModificationInformation = true }; Console.WriteLine("SharePoint Version: {0}", pti.SourceVersion); pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; var result = pageTransformator.Transform(pti); } pageTransformator.FlushObservers(); } catch { pageTransformator.FlushObservers(); Assert.Fail("Exception occurred"); } } } }
public void BasicOnPremPublishingPageTest() { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext()) { //"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\SharePointPnP.Modernization.Framework.Tests\Transform\Publishing\custompagelayoutmapping.xml" //"C:\temp\onprem-mapping-all-test.xml.xml" var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"C:\temp\onprem-mapping-all-test.xml"); pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose: true)); pageTransformator.RegisterObserver(new UnitTestLogObserver()); var pages = sourceClientContext.Web.GetPagesFromList("Pages", "Article-SP"); //var pages = sourceClientContext.Web.GetPagesFromList("Pages", folder:"News"); foreach (var page in pages) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are unlikely to work given cross domain KeepPageSpecificPermissions = false, //RemoveEmptySectionsAndColumns = false, // Configure the page header, empty value means ClientSidePageHeaderType.None //PageHeader = new ClientSidePageHeader(cc, ClientSidePageHeaderType.None, null), // Replace embedded images and iframes with a placeholder and add respective images and video web parts at the bottom of the page // HandleWikiImagesAndVideos = false, // Callout to your custom code to allow for title overriding //PageTitleOverride = titleOverride, // Callout to your custom layout handler //LayoutTransformatorOverride = layoutOverride, // Callout to your custom content transformator...in case you fully want replace the model //ContentTransformatorOverride = contentOverride, }; pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; var result = pageTransformator.Transform(pti); } pageTransformator.FlushObservers(); } } }
public void GetGetFirstNonEmptyFieldName_TrimTest() { // Arrange var ppti = new PublishingPageTransformationInformation(null); string[] fieldNames = new string[] { " ", "" }; // Act string fieldName = ppti.GetFirstNonEmptyFieldName(fieldNames); // Assert Assert.AreEqual(string.Empty, fieldName); }
public void BasicOnPremPublishingPage_TermMappingTest() { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext()) { var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"C:\temp\onprem-mapping-all-test.xml"); //pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose: true)); pageTransformator.RegisterObserver(new UnitTestLogObserver(true)); //2013 var pages = sourceClientContext.Web.GetPagesFromList("Pages", folder: "News", pageNameStartsWith: "Our-new-IT-suite-is-mint"); //2010 //var pages = sourceClientContext.Web.GetPagesFromList("Pages", pageNameStartsWith: "Article-2010-Taxonomy"); pages.FailTestIfZero(); foreach (var page in pages) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are unlikely to work given cross domain KeepPageSpecificPermissions = false, // Term store mapping TermMappingFile = @"..\..\Transform\Mapping\term_mapping_sample.csv" }; Console.WriteLine("SharePoint Version: {0}", pti.SourceVersion); pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; var result = pageTransformator.Transform(pti); } pageTransformator.FlushObservers(); } } }
public void BasicOnlinePublishingPage_TermDefaultTest() { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPODevSiteUrl"))) { var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"C:\temp\spo-mapping-all-test.xml"); //pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose: true)); pageTransformator.RegisterObserver(new UnitTestLogObserver()); var pages = sourceClientContext.Web.GetPagesFromList("Pages", pageNameStartsWith: "Article-PnP-Example"); pages.FailTestIfZero(); foreach (var page in pages) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are unlikely to work given cross domain KeepPageSpecificPermissions = false, // Term store mapping TermMappingFile = string.Empty, //Should process default mapping SkipTermStoreMapping = false }; Console.WriteLine("SharePoint Version: {0}", pti.SourceVersion); pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; var result = pageTransformator.Transform(pti); } pageTransformator.FlushObservers(); } } }
public void GetLDAPConnectingStringTest() { //Doesnt matter what the settings are. PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation() { // Don't log test runs SkipTelemetry = true, }; UserTransformator userTransformator = new UserTransformator(pti, null, null, null); var result = userTransformator.GetLDAPConnectionString(); Console.WriteLine(result); Assert.IsTrue(!string.IsNullOrEmpty(result)); }
// Common Tests /// <summary> /// Standard Transform Test /// </summary> /// <param name="version"></param> /// <param name="fullPageLayoutMapping"></param> /// <param name="pageNameStartsWith"></param> private void TransformPage(SPPlatformVersion version, string fullPageLayoutMapping = "", string pageNameStartsWith = "Common") { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateSPPlatformClientContext(version, TransformType.PublishingPage)) { var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, fullPageLayoutMapping); pageTransformator.RegisterObserver(new MarkdownObserver(folder: TestContext.ResultsDirectory, includeVerbose: true)); pageTransformator.RegisterObserver(new UnitTestLogObserver()); var pages = sourceClientContext.Web.GetPagesFromList("Pages", pageNameStartsWith); pages.FailTestIfZero(); foreach (var page in pages) { var pageName = page.FieldValues["FileLeafRef"].ToString(); PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are unlikely to work given cross domain KeepPageSpecificPermissions = false, //Update target to include SP version TargetPageName = TestCommon.UpdatePageToIncludeVersion(version, pageName) }; Console.WriteLine("SharePoint Version: {0}", pti.SourceVersion); pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; var result = pageTransformator.Transform(pti); Assert.IsTrue(!string.IsNullOrEmpty(result)); } pageTransformator.FlushObservers(); } } }
public void PageTransformationDemoTest() { using (var targetClientContext = TestCommon.CreateClientContext("https://bertonline.sharepoint.com/sites/pagetransformationdemotarget")) { //https://bertonline.sharepoint.com/sites/modernizationtestportal using (var sourceClientContext = TestCommon.CreateClientContext("https://bertonline.sharepoint.com/sites/pagetransformationdemoportal")) { //"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\PnP.Framework.Modernization.Tests\Transform\Publishing\custompagelayoutmapping.xml" //"C:\temp\mappingtest.xml" //@"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\PnP.Framework.Modernization.Tests\Transform\Publishing\webpartmapping.xml" //var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\PnP.Framework.Modernization.Tests\Transform\Publishing\webpartmapping.xml", @"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\PnP.Framework.Modernization.Tests\Transform\Publishing\custompagelayoutmapping.xml"); var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"E:\CAB2021\contosomapping.xml"); pageTransformator.RegisterObserver(new MarkdownObserver(folder: "E:\\CAB2021", includeVerbose: true)); //pageTransformator.RegisterObserver(new MarkdownToSharePointObserver(targetClientContext, includeVerbose: true)); var pages = sourceClientContext.Web.GetPagesFromList("Pages", "D88_specs"); //var pages = sourceClientContext.Web.GetPagesFromList("Pages", folder:"News"); foreach (var page in pages) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, KeepPageCreationModificationInformation = true, PostAsNews = true, PublishCreatedPage = true, }; pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; var result = pageTransformator.Transform(pti); } pageTransformator.FlushObservers(); } } }
public void BasicOnPremPublishingPageEnterpriseWikiTest() { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateOnPremisesEnterpriseWikiClientContext()) { var mapping = "c:\\temp\\custompagelayoutmapping-enterprisewiki-home.xml"; var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, mapping); pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose: true)); pageTransformator.RegisterObserver(new UnitTestLogObserver()); var pages = sourceClientContext.Web.GetPagesFromList("Pages", "home"); pages.FailTestIfZero(); foreach (var page in pages) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are unlikely to work given cross domain KeepPageSpecificPermissions = false, // Not the home page, its just annoying to have to roll back that page or target TargetPageName = "EnterpriseWikiPage.aspx", }; Console.WriteLine("SharePoint Version: {0}", pti.SourceVersion); pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; var result = pageTransformator.Transform(pti); } pageTransformator.FlushObservers(); } } }
public void GetLDAPConnectingStringProvidedByParamTest() { var ldap = "LDAP://OU=CDT,OU=Demo Users,DC=AlphaDelta,DC=Local"; //Doesnt matter what the settings are. PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation() { // Don't log test runs SkipTelemetry = true, LDAPConnectionString = ldap }; UserTransformator userTransformator = new UserTransformator(pti, null, null, null); var result = userTransformator.GetLDAPConnectionString(); Console.WriteLine(result); Assert.IsTrue(!string.IsNullOrEmpty(result)); Assert.IsTrue(result.Equals(ldap, StringComparison.InvariantCultureIgnoreCase)); }
public void GetComputerDomainTest() { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext()) { //Doesnt matter what the settings are. PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation() { // Don't log test runs SkipTelemetry = true, }; UserTransformator userTransformator = new UserTransformator(pti, sourceClientContext, targetClientContext, null); var result = userTransformator.GetFriendlyComputerDomain(); Console.WriteLine(result); Assert.IsTrue(!string.IsNullOrEmpty(result)); } } }
public void TermMappingTransformatorTest_PassThrough() { using (var targetClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPOTargetSiteUrl"))) { using (var sourceClientContext = TestCommon.CreateOnPremisesClientContext()) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation() { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //Permissions are should work given cross domain with mapping KeepPageSpecificPermissions = true, // Term store mapping TermMappingFile = string.Empty, SkipTermStoreMapping = false }; TermTransformator termTransformator = new TermTransformator(pti, sourceClientContext, targetClientContext, null); var inputLabel = "pass-through-test"; var inputGuid = Guid.NewGuid(); var result = termTransformator.Transform(new Entities.TermData() { TermGuid = inputGuid, TermLabel = inputLabel }); Console.WriteLine(inputLabel + " and " + inputGuid); Assert.AreEqual(inputLabel, result.TermLabel); Assert.AreEqual(inputGuid, result.TermGuid); } } }
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); } }
public void BasicPublishingPageOnPremisesTest() { using (var targetClientContext = TestCommon.CreateClientContext("https://bertonline.sharepoint.com/sites/modernizationusermapping")) { //https://bertonline.sharepoint.com/sites/modernizationtestportal //using (var sourceClientContext = TestCommon.CreateClientContext(TestCommon.AppSetting("SPODevSiteUrl"))) AuthenticationManager authManager = new AuthenticationManager(); using (var sourceClientContext = authManager.GetOnPremisesContext("https://portal2013.pnp.com/sites/devportal")) { //"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\SharePointPnP.Modernization.Framework.Tests\Transform\Publishing\custompagelayoutmapping.xml" //"C:\temp\mappingtest.xml" var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"c:\github\zzscratch\pagelayoutmapping.xml"); pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose: true)); var pages = sourceClientContext.Web.GetPagesFromList("Pages", "bug268"); //var pages = sourceClientContext.Web.GetPagesFromList("Pages", folder:"News"); foreach (var page in pages) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, KeepPageCreationModificationInformation = true, PostAsNews = true, UserMappingFile = @"C:\github\pnpframework\src\lib\PnP.Framework.Modernization.Test\Transform\Mapping\usermapping_sample2.csv", //RemoveEmptySectionsAndColumns = false, // Configure the page header, empty value means ClientSidePageHeaderType.None //PageHeader = new ClientSidePageHeader(cc, ClientSidePageHeaderType.None, null), // Replace embedded images and iframes with a placeholder and add respective images and video web parts at the bottom of the page // HandleWikiImagesAndVideos = false, // Callout to your custom code to allow for title overriding //PageTitleOverride = titleOverride, // Callout to your custom layout handler //LayoutTransformatorOverride = layoutOverride, // Callout to your custom content transformator...in case you fully want replace the model //ContentTransformatorOverride = contentOverride, }; pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; var result = pageTransformator.Transform(pti); } pageTransformator.FlushObservers(); } } }
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); } }
static void Main(string[] args) { SharePointOnlineCredentials creds = new SharePointOnlineCredentials(AppSetting("Username"), ConvertToSecureString(AppSetting("Password"))); using (var targetClientContext = new ClientContext(AppSetting("SPOTargetSiteUrl"))) { targetClientContext.Credentials = creds; using (var sourceClientContext = new ClientContext(AppSetting("SPODevSiteUrl"))) { sourceClientContext.Credentials = creds; //"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\SharePointPnP.Modernization.Framework.Tests\Transform\Publishing\custompagelayoutmapping.xml" //"C:\temp\mappingtest.xml" //var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext , @"C:\github\sp-dev-modernization\Tools\SharePoint.Modernization\SharePointPnP.Modernization.Framework.Tests\Transform\Publishing\custompagelayoutmapping.xml"); var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext, @"C:\temp\mappingtest.xml"); pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp")); var pages = sourceClientContext.Web.GetPagesFromList("Pages", pageNameStartsWith: "article"); //var pages = sourceClientContext.Web.GetPagesFromList("Pages", folder:"News"); foreach (var page in pages) { PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, // Don't log test runs SkipTelemetry = true, //RemoveEmptySectionsAndColumns = false, // Configure the page header, empty value means ClientSidePageHeaderType.None //PageHeader = new ClientSidePageHeader(cc, ClientSidePageHeaderType.None, null), // Replace embedded images and iframes with a placeholder and add respective images and video web parts at the bottom of the page // HandleWikiImagesAndVideos = false, // Callout to your custom code to allow for title overriding //PageTitleOverride = titleOverride, // Callout to your custom layout handler //LayoutTransformatorOverride = layoutOverride, // Callout to your custom content transformator...in case you fully want replace the model //ContentTransformatorOverride = contentOverride, }; pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; var result = pageTransformator.Transform(pti); pageTransformator.FlushObservers(); } pageTransformator.FlushObservers(); } } Console.WriteLine("App Complete, press any key to end!"); Console.ReadKey(); }