static void Main(string[] args) { SystemContext.InitSystemContext(new MySystemContextConstructor()); // login: Admin, hasło: password // login: SomeUser, hasło: pass Login(); var pageLayoutManager = new PageLayoutManager(); pageLayoutManager.StartPage = new MainPage(); pageLayoutManager.Show(); }
public override bool ProcessInput(PageLayoutManager manager, object obj) { var shouldTurnOff = (bool)obj; if (shouldTurnOff && _alarmSystem.AlarmOn) { _alarmSystem.TurnOffAlarm(); } else if (!shouldTurnOff && !_alarmSystem.AlarmOn) { _alarmSystem.TurnOnAlarm(_alarmSystem.BeepLengthInMiliseconds, _alarmSystem.BeepIntervalInMiliseconds); } return(true); }
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); } }
public virtual bool ProcessInput(PageLayoutManager manager, object obj) { return(true); }
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); } }
/// <summary> /// Analyses a publishing page /// </summary> /// <returns>Information about the analyzed publishing page</returns> public override Tuple <PageLayout, List <WebPartEntity> > Analyze(Publishing.PageLayout publishingPageTransformationModel) { List <WebPartEntity> webparts = new List <WebPartEntity>(); //Load the page var publishingPageUrl = page[Constants.FileRefField].ToString(); var publishingPage = cc.Web.GetFileByServerRelativeUrl(publishingPageUrl); // Load relevant model data for the used page layout in case not already provided - safetynet for calls from modernization scanner string usedPageLayout = System.IO.Path.GetFileNameWithoutExtension(page.PageLayoutFile()); if (publishingPageTransformationModel == null) { publishingPageTransformationModel = new PageLayoutManager(this.RegisteredLogObservers).GetPageLayoutMappingModel(this.publishingPageTransformation, page); } // Still no layout...can't continue... if (publishingPageTransformationModel == null) { LogError(string.Format(LogStrings.Error_NoPageLayoutTransformationModel, usedPageLayout), LogStrings.Heading_PublishingPage); throw new Exception(string.Format(LogStrings.Error_NoPageLayoutTransformationModel, usedPageLayout)); } // Map layout bool includeVerticalColumn = false; if (publishingPageTransformationModel.IncludeVerticalColumnSpecified) { includeVerticalColumn = publishingPageTransformationModel.IncludeVerticalColumn; } PageLayout layout = MapToLayout(publishingPageTransformationModel.PageLayoutTemplate, includeVerticalColumn); #region Process fields that become web parts if (publishingPageTransformationModel.WebParts != null) { #region Publishing Html column processing // Converting to WikiTextPart is a special case as we'll need to process the html var wikiTextWebParts = publishingPageTransformationModel.WebParts.Where(p => p.TargetWebPart.Equals(WebParts.WikiText, StringComparison.InvariantCultureIgnoreCase)); List <WebPartPlaceHolder> webPartsToRetrieve = new List <WebPartPlaceHolder>(); foreach (var wikiTextPart in wikiTextWebParts) { string pageContents = page.GetFieldValueAs <string>(wikiTextPart.Name); if (wikiTextPart.Property.Count() > 0) { foreach (var fieldWebPartProperty in wikiTextPart.Property) { if (fieldWebPartProperty.Name.Equals("Text", StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(fieldWebPartProperty.Functions)) { // execute function var evaluatedField = this.functionProcessor.Process(fieldWebPartProperty.Functions, fieldWebPartProperty.Name, MapToFunctionProcessorFieldType(fieldWebPartProperty.Type)); if (!string.IsNullOrEmpty(evaluatedField.Item1)) { pageContents = evaluatedField.Item2; } } } } if (pageContents != null && !string.IsNullOrEmpty(pageContents)) { var htmlDoc = parser.Parse(pageContents); // Analyze the html block (which is a wiki block) var content = htmlDoc.FirstElementChild.LastElementChild; AnalyzeWikiContentBlock(webparts, htmlDoc, webPartsToRetrieve, wikiTextPart.Row, wikiTextPart.Column, GetNextOrder(wikiTextPart.Row, wikiTextPart.Column, wikiTextPart.Order, webparts), content); } else { LogWarning(LogStrings.Warning_CannotRetrieveFieldValue, LogStrings.Heading_PublishingPage); } } // Bulk load the needed web part information if (webPartsToRetrieve.Count > 0) { LoadWebPartsInWikiContentFromOnPremisesServer(webparts, publishingPage, webPartsToRetrieve); } #endregion #region Generic processing of the other 'webpart' fields var fieldWebParts = publishingPageTransformationModel.WebParts.Where(p => !p.TargetWebPart.Equals(WebParts.WikiText, StringComparison.InvariantCultureIgnoreCase)); foreach (var fieldWebPart in fieldWebParts.OrderBy(p => p.Row).OrderBy(p => p.Column)) { // In publishing scenarios it's common to not have all fields defined in the page layout mapping filled. By default we'll not map empty fields as that will result in empty web parts // which impact the page look and feel. Using the RemoveEmptySectionsAndColumns flag this behaviour can be turned off. if (this.baseTransformationInformation.RemoveEmptySectionsAndColumns) { var fieldContents = page.GetFieldValueAs <string>(fieldWebPart.Name); if (string.IsNullOrEmpty(fieldContents)) { LogWarning(String.Format(LogStrings.Warning_SkippedWebPartDueToEmptyInSourcee, fieldWebPart.TargetWebPart, fieldWebPart.Name), LogStrings.Heading_PublishingPage); continue; } } Dictionary <string, string> properties = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase); foreach (var fieldWebPartProperty in fieldWebPart.Property) { if (!string.IsNullOrEmpty(fieldWebPartProperty.Functions)) { // execute function var evaluatedField = this.functionProcessor.Process(fieldWebPartProperty.Functions, fieldWebPartProperty.Name, MapToFunctionProcessorFieldType(fieldWebPartProperty.Type)); if (!string.IsNullOrEmpty(evaluatedField.Item1) && !properties.ContainsKey(evaluatedField.Item1)) { properties.Add(evaluatedField.Item1, evaluatedField.Item2); } } else { var webPartName = page.FieldValues[fieldWebPart.Name]?.ToString().Trim(); if (webPartName != null) { properties.Add(fieldWebPartProperty.Name, page.FieldValues[fieldWebPart.Name].ToString().Trim()); } } } var wpEntity = new WebPartEntity() { Title = fieldWebPart.Name, Type = fieldWebPart.TargetWebPart, Id = Guid.Empty, Row = fieldWebPart.Row, Column = fieldWebPart.Column, Order = GetNextOrder(fieldWebPart.Row, fieldWebPart.Column, fieldWebPart.Order, webparts), Properties = properties, }; webparts.Add(wpEntity); } } #endregion #endregion #region Process fields that become metadata as they might result in the creation of page properties web part if (publishingPageTransformationModel.MetaData != null && publishingPageTransformationModel.MetaData.ShowPageProperties) { List <string> pagePropertiesFields = new List <string>(); var fieldsToProcess = publishingPageTransformationModel.MetaData.Field.Where(p => p.ShowInPageProperties == true && !string.IsNullOrEmpty(p.TargetFieldName)); if (fieldsToProcess.Any()) { // Loop over the fields that are defined to be shown in the page properties and that have a target field name set foreach (var fieldToProcess in fieldsToProcess) { var targetFieldInstance = targetContext.Web.GetFieldByInternalName(fieldToProcess.TargetFieldName, true) ?? targetContext.Web.GetListByUrl("SitePages").Fields.GetFieldByInternalName(fieldToProcess.TargetFieldName); if (targetFieldInstance != null) { if (!pagePropertiesFields.Contains(targetFieldInstance.Id.ToString())) { pagePropertiesFields.Add(targetFieldInstance.Id.ToString()); } } } if (pagePropertiesFields.Count > 0) { string propertyString = ""; foreach (var propertyField in pagePropertiesFields) { if (!string.IsNullOrEmpty(propertyField)) { propertyString = $"{propertyString},\"{propertyField.ToString()}\""; } } if (!string.IsNullOrEmpty(propertyString)) { propertyString = propertyString.TrimStart(new char[] { ',' }); } if (!string.IsNullOrEmpty(propertyString)) { Dictionary <string, string> properties = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase) { { "SelectedFields", propertyString } }; var wpEntity = new WebPartEntity() { Type = WebParts.PageProperties, Id = Guid.Empty, Row = publishingPageTransformationModel.MetaData.PagePropertiesRow, Column = publishingPageTransformationModel.MetaData.PagePropertiesColumn, Order = GetNextOrder(publishingPageTransformationModel.MetaData.PagePropertiesRow, publishingPageTransformationModel.MetaData.PagePropertiesColumn, publishingPageTransformationModel.MetaData.PagePropertiesOrder, webparts), Properties = properties, }; webparts.Add(wpEntity); } } } } #endregion #region Web Parts in webpart zone handling // Load web parts put in web part zones on the publishing page // Note: Web parts placed outside of a web part zone using SPD are not picked up by the web part manager. var limitedWPManager = publishingPage.GetLimitedWebPartManager(PersonalizationScope.Shared); cc.Load(limitedWPManager); IEnumerable <WebPartDefinition> webPartsViaManager = null; List <WebServiceWebPartEntity> webServiceWebPartEntities = null; //Properties, ExportMode and ZoneId - not Supported in 2010, Web Services are used to compensate for the missing properties webPartsViaManager = cc.LoadQuery(limitedWPManager.WebParts.IncludeWithDefaultProperties(wp => wp.Id, wp => wp.WebPart.Title, wp => wp.WebPart.ZoneIndex, wp => wp.WebPart.IsClosed, wp => wp.WebPart.Hidden)); cc.ExecuteQueryRetry(); webServiceWebPartEntities = LoadPublishingPageFromWebServices(publishingPage.EnsureProperty(p => p.ServerRelativeUrl)); if (webPartsViaManager.Count() > 0) { List <WebPartPlaceHolder> webPartsToRetrieve = new List <WebPartPlaceHolder>(); foreach (var foundWebPart in webPartsViaManager) { // Remove the web parts which we've already picked up by analyzing the wiki content block if (webparts.Where(p => p.Id.Equals(foundWebPart.Id)).FirstOrDefault() != null) { continue; } webPartsToRetrieve.Add(new WebPartPlaceHolder() { WebPartDefinition = foundWebPart, WebPartXml = null, WebPartType = "", }); } foreach (var foundWebPart in webPartsToRetrieve) { // If the web service call includes the export mode value then set the export options var wsWp = webServiceWebPartEntities.FirstOrDefault(o => o.Id == foundWebPart.WebPartDefinition.Id); var wsExportMode = wsWp.Properties.FirstOrDefault(o => o.Key.Equals("exportmode", StringComparison.InvariantCultureIgnoreCase)); if (!string.IsNullOrEmpty(wsExportMode.Value) && wsExportMode.Value.Equals("all", StringComparison.InvariantCultureIgnoreCase)) { var webPartXml = base.ExportWebPartXmlWorkaround(publishingPageUrl, foundWebPart.WebPartDefinition.Id.ToString()); foundWebPart.WebPartXmlOnPremises = webPartXml; } } List <WebPartZoneLayoutMap> webPartZoneLayoutMap = new List <WebPartZoneLayoutMap>(); foreach (var foundWebPart in webPartsToRetrieve.OrderBy(p => p.WebPartDefinition.WebPart.ZoneIndex)) { bool isExportable = false; Dictionary <string, object> webPartProperties = null; // If the web service call includes the export mode value then set the export options var wsWp = webServiceWebPartEntities.FirstOrDefault(o => o.Id == foundWebPart.WebPartDefinition.Id); webPartProperties = wsWp.PropertiesAsStringObjectDictionary(); var wsExportMode = wsWp.Properties.FirstOrDefault(o => o.Key.Equals("exportmode", StringComparison.InvariantCultureIgnoreCase)); if (!string.IsNullOrEmpty(wsExportMode.Value) && wsExportMode.Value.ToString().Equals("all", StringComparison.InvariantCultureIgnoreCase)) { isExportable = true; } if (!isExportable) { // Use different approach to determine type as we can't export the web part XML without indroducing a change foundWebPart.WebPartType = GetTypeFromProperties(webPartProperties, true); } else { foundWebPart.WebPartType = GetType(foundWebPart.WebPartXmlOnPremises); } string zoneId = string.Empty; var wsZoneId = wsWp.Properties.FirstOrDefault(o => o.Key.Equals("zoneid", StringComparison.InvariantCultureIgnoreCase)); if (!string.IsNullOrEmpty(wsZoneId.Value)) { zoneId = wsZoneId.Value; } int wpInZoneRow = 1; int wpInZoneCol = 1; int wpStartOrder = 0; // Determine location based upon the location given to the web part zone in the mapping if (publishingPageTransformationModel.WebPartZones != null) { var wpZoneFromTemplate = publishingPageTransformationModel.WebPartZones.Where(p => p.ZoneId.Equals(zoneId, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (wpZoneFromTemplate != null) { // Was there a webpart zone layout specified? If so then use that information to correctly position the webparts on the target page if (wpZoneFromTemplate.WebPartZoneLayout != null && wpZoneFromTemplate.WebPartZoneLayout.Count() > 0) { // Did we already map a web part of this type? var webPartZoneLayoutMapEntry = webPartZoneLayoutMap.Where(p => p.ZoneId.Equals(wpZoneFromTemplate.ZoneId, StringComparison.InvariantCultureIgnoreCase) && p.Type.Equals(foundWebPart.WebPartType, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); // What's the expected occurance for this web part in the mapping? int webPartOccuranceInZoneLayout = 1; if (webPartZoneLayoutMapEntry != null) { webPartOccuranceInZoneLayout += webPartZoneLayoutMapEntry.Occurances; } // Get the webpart from the webpart zone layout mapping int occuranceCounter = 0; bool occuranceFound = false; foreach (var wpInWebPartZoneLayout in wpZoneFromTemplate.WebPartZoneLayout.Where(p => p.Type.Equals(foundWebPart.WebPartType, StringComparison.InvariantCultureIgnoreCase))) { occuranceCounter++; if (occuranceCounter == webPartOccuranceInZoneLayout) { occuranceFound = true; wpInZoneRow = wpInWebPartZoneLayout.Row; wpInZoneCol = wpInWebPartZoneLayout.Column; wpStartOrder = wpInWebPartZoneLayout.Order; break; } } if (occuranceFound) { // Update the WebPartZoneLayoutMap if (webPartZoneLayoutMapEntry != null) { webPartZoneLayoutMapEntry.Occurances = webPartOccuranceInZoneLayout; } else { webPartZoneLayoutMap.Add(new WebPartZoneLayoutMap() { ZoneId = wpZoneFromTemplate.ZoneId, Type = foundWebPart.WebPartType, Occurances = webPartOccuranceInZoneLayout }); } } else { // fall back to the defaults from the zone definition wpInZoneRow = wpZoneFromTemplate.Row; wpInZoneCol = wpZoneFromTemplate.Column; wpStartOrder = wpZoneFromTemplate.Order; } } else { wpInZoneRow = wpZoneFromTemplate.Row; wpInZoneCol = wpZoneFromTemplate.Column; wpStartOrder = wpZoneFromTemplate.Order; } } } // Determine order already taken int wpInZoneOrderUsed = GetNextOrder(wpInZoneRow, wpInZoneCol, wpStartOrder, webparts); string webPartXmlForPropertiesMethod = null; webPartXmlForPropertiesMethod = foundWebPart.WebPartXmlOnPremises; LogInfo(string.Format(LogStrings.ContentTransformFoundSourceWebParts, foundWebPart.WebPartDefinition.WebPart.Title, foundWebPart.WebPartType.GetTypeShort()), LogStrings.Heading_ContentTransform); webparts.Add(new WebPartEntity() { Title = foundWebPart.WebPartDefinition.WebPart.Title, Type = foundWebPart.WebPartType, Id = foundWebPart.WebPartDefinition.Id, ServerControlId = foundWebPart.WebPartDefinition.Id.ToString(), Row = wpInZoneRow, Column = wpInZoneCol, Order = wpInZoneOrderUsed + foundWebPart.WebPartDefinition.WebPart.ZoneIndex, ZoneId = zoneId, ZoneIndex = (uint)foundWebPart.WebPartDefinition.WebPart.ZoneIndex, IsClosed = foundWebPart.WebPartDefinition.WebPart.IsClosed, Hidden = foundWebPart.WebPartDefinition.WebPart.Hidden, Properties = Properties(webPartProperties, foundWebPart.WebPartType, webPartXmlForPropertiesMethod), }); } } else { LogInfo(LogStrings.AnalysingNoWebPartsFound, LogStrings.Heading_ArticlePageHandling); } #endregion #region Fixed webparts mapping if (publishingPageTransformationModel.FixedWebParts != null) { foreach (var fixedWebpart in publishingPageTransformationModel.FixedWebParts) { int wpFixedOrderUsed = GetNextOrder(fixedWebpart.Row, fixedWebpart.Column, fixedWebpart.Order, webparts); webparts.Add(new WebPartEntity() { Title = GetFixedWebPartProperty <string>(fixedWebpart, "Title", ""), Type = fixedWebpart.Type, Id = Guid.NewGuid(), Row = fixedWebpart.Row, Column = fixedWebpart.Column, Order = wpFixedOrderUsed, ZoneId = "", ZoneIndex = 0, IsClosed = GetFixedWebPartProperty <bool>(fixedWebpart, "__designer:IsClosed", false), Hidden = false, Properties = CastAsPropertiesDictionary(fixedWebpart), }); } } #endregion return(new Tuple <PageLayout, List <WebPartEntity> >(layout, webparts)); }
public override bool ProcessInput(PageLayoutManager manager, object obj) { return(Helpers.PageHelper.GoToPage(manager, pageConnection, obj)); }