コード例 #1
0
        private Dictionary <string, string> ReplaceWebPartWebSpecificIDsWithTokens(ClientContext ctx, Web web,
                                                                                   string fileUrl, LimitedWebPartManager webPartManager, Dictionary <Guid, List> listIds)
        {
            var webPartsXml = new Dictionary <string, string>();

            foreach (var wpmWebPart in webPartManager.WebParts)
            {
                var part = RequestContextCredentials == null
                    ? WebPartUtility.GetWebPart(ctx, web, fileUrl, wpmWebPart.Id)
                           .Replace("\r", "")
                           .Replace("\n", "")
                           .Trim()
                           .Replace("  ", " ")
                           .Replace("  ", " ")
                    : WebPartUtility.GetWebPart(web, RequestContextCredentials, fileUrl, wpmWebPart.Id)
                           .Replace("\r", "")
                           .Replace("\n", "")
                           .Trim()
                           .Replace("  ", " ")
                           .Replace("  ", " ");

                part = TokenizeText(web, listIds, part);
                webPartsXml[wpmWebPart.Id.ToString().ToLower().Replace("{", "").Replace("}", "")] = part;
            }
            return(webPartsXml);
        }
コード例 #2
0
        /// <summary>
        /// Gets the content and parts for wiki and publishing pages
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="web"></param>
        /// <param name="fileUrl"></param>
        /// <param name="file"></param>
        /// <param name="pageContentFieldName"></param>
        /// <param name="newFileCreator"></param>
        private void ProcessWikiOrPublishingPage(ClientContext ctx, Web web, string fileUrl, File file, string pageContentFieldName, FileCreator newFileCreator)
        {
            OnVerboseNotify("Processing Wiki or Publishing Page " + fileUrl);
            //Get the web part manager
            var webPartManager = TryToGetWebPartManager(ctx, file);

            if (webPartManager != null)
            {
                OnVerboseNotify("Processing web parts");
                var listIds = GetWebListIds(ctx, web);

                //Get each web part and do token replacements
                var webPartsXml = ReplaceWebPartWebSpecificIDsWithTokens(ctx, web, fileUrl, webPartManager, listIds);

                var pageContentListViews = GetListViewWebPartViewSchemas(ctx, web, webPartsXml);

                //Get the field contents
                var pageContent = file.ListItemAllFields.FieldValuesForEdit[pageContentFieldName];

                newFileCreator.WebParts = webPartsXml;
                newFileCreator.WikiPageWebPartListViews = pageContentListViews;

                //Extract the storage keys
                var storageKeys = WikiPageUtility.GetStorageKeysFromWikiContent(pageContent);

                //Fetch the page
                var page = RequestContextCredentials == null
                    ? WebPartUtility.GetWebPartPage(ctx, web, fileUrl)
                    : WebPartUtility.GetWebPartPage(web, RequestContextCredentials, fileUrl);

                //Search throught the page looking for the web part ID's that match the storage keys
                newFileCreator.WikiPageWebPartStorageKeyMappings = WikiPageUtility.GetStorageKeyMappings(page,
                                                                                                         storageKeys);
            }
        }
コード例 #3
0
        private void ProcessWebPartPage(ClientContext ctx, Web web, string fileUrl, File file,
                                        FileCreator newFileCreator, Dictionary <Guid, List> listIds)
        {
            OnVerboseNotify("Processing Web Part Page " + fileUrl);
            //Get the web part manager
            var webPartManager = TryToGetWebPartManager(ctx, file);

            if (webPartManager != null)
            {
                OnVerboseNotify("Processing web parts");


                //Get each web part and do token replacements
                var webPartsXml = ReplaceWebPartWebSpecificIDsWithTokens(ctx, web, fileUrl, webPartManager, listIds);

                var webPartListViews = GetListViewWebPartViewSchemas(ctx, web, webPartsXml);

                newFileCreator.WebParts = webPartsXml;
                newFileCreator.WebPartPageWebPartListViews = webPartListViews;

                var page = RequestContextCredentials == null
                    ? WebPartUtility.GetWebPartPage(ctx, web, fileUrl)
                    : WebPartUtility.GetWebPartPage(web, RequestContextCredentials, fileUrl);

                newFileCreator.WebPartPageZoneMappings = WebPartPageUtility.GetWebPartZoneMappings(page, webPartsXml);
            }
        }
コード例 #4
0
        private void SetPageListViews(ClientContext ctx, Web web, Dictionary <string, string> newIdMappings)
        {
            Dictionary <string, string> viewCollection;

            if (WikiPageWebPartListViews == null || WikiPageWebPartListViews.Count == 0)
            {
                viewCollection = WebPartPageWebPartListViews;
            }
            else
            {
                viewCollection = WikiPageWebPartListViews;
            }

            if (viewCollection == null || viewCollection.Count == 0)
            {
                return;
            }

            var shouldExecuteQuery = false;

            var soapFailed = false;

            foreach (var webPartId in WebParts.Keys)
            {
                var listTitle = WebParts[webPartId].GetInnerText("{@ListId:", "}", true);
                if (viewCollection.ContainsKey(webPartId))
                {
                    if (!soapFailed)
                    {
                        try
                        {
                            //Get the real view id from the web part from the page
                            var partXml = WebPartUtility.GetWebPart(ctx, web, File.ServerRelativeUrl,
                                                                    Guid.Parse(newIdMappings[webPartId]));
                            var viewId = partXml.GetInnerText("View Name=\"", "\"", true);
                            var list   = web.Lists.GetByTitle(listTitle);
                            var view   = list.Views.GetById(Guid.Parse(viewId));
                            view.ListViewXml = viewCollection[webPartId];
                            view.Update();
                            shouldExecuteQuery = true;
                        }
                        catch
                        {
                            soapFailed = true;
                        }
                    }

                    if (soapFailed)
                    {
                        var list = ctx.Web.Lists.GetByTitle(listTitle);
                        ctx.Load(list.Views,
                                 v => v.Include(view => view.Id, view => view.Hidden).Where(view => view.Hidden));

                        ctx.ExecuteQueryRetry();

                        var viewCount = list.Views.Count;
                        var lastView  = list.Views[viewCount - 1];
                        lastView.ListViewXml = viewCollection[webPartId];
                        lastView.Update();
                        shouldExecuteQuery = true;
                    }
                }
            }
            if (shouldExecuteQuery)
            {
                ctx.ExecuteQueryRetry();
            }
        }