当前位置: 首页>>代码示例>>C#>>正文


C# ProvisioningTemplateCreationInformation.ExecutePreProvisionEvent方法代码示例

本文整理汇总了C#中OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.ProvisioningTemplateCreationInformation.ExecutePreProvisionEvent方法的典型用法代码示例。如果您正苦于以下问题:C# ProvisioningTemplateCreationInformation.ExecutePreProvisionEvent方法的具体用法?C# ProvisioningTemplateCreationInformation.ExecutePreProvisionEvent怎么用?C# ProvisioningTemplateCreationInformation.ExecutePreProvisionEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.ProvisioningTemplateCreationInformation的用法示例。


在下文中一共展示了ProvisioningTemplateCreationInformation.ExecutePreProvisionEvent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtractObjects

        public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateCreationInformation creationInfo)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                var lists = this.GetListsWithPages(template);
                template.Pages = new PageCollection(template);

                var homePageUrl = web.GetHomePageRelativeUrl();
                foreach (var list in lists)
                {
                    try
                    {
                        List splist = web.Lists.GetById(list.ID);
                        web.Context.Load(splist);
                        web.Context.ExecuteQueryRetry();
                        if (!creationInfo.ExecutePreProvisionEvent<ListInstance, List>(Handlers.Pages, template, list, null))
                        {
                            continue;
                        }

                        var listItems = GetListPages(web, splist);
                        var fileItems = listItems.AsEnumerable().Where(x => x.IsFile());
                        foreach (ListItem item in fileItems)
                        {
                            try
                            {
                                IPageModelProvider provider = GetProvider(item, homePageUrl, web, parser);
                                if (null != provider)
                                {
                                    provider.AddPage(item, template);
                                }
                            }
                            catch (Exception ex)
                            {
                                var message = string.Format("Error in export page for list: {0}", list.ServerRelativeUrl);
                                scope.LogError(ex, message);
                            }
                        }

                        creationInfo.ExecutePostProvisionEvent<ListInstance, List>(Handlers.Pages, template, list, splist);
                    }
                    catch (Exception exception)
                    {
                        var message = string.Format("Error in export publishing page for list: {0}", list.ServerRelativeUrl);
                        scope.LogError(exception, message);
                    }
                }
                // Impossible to return all files in the site currently

                // If a base template is specified then use that one to "cleanup" the generated template model
                if (creationInfo.BaseTemplate != null)
                {
                    template = CleanupEntities(template, creationInfo.BaseTemplate);
                }
            }
            return template;
        }
开发者ID:skybow,项目名称:PnP-Sites-Core,代码行数:57,代码来源:ObjectPages.cs

示例2: ExtractObjects

        public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateCreationInformation creationInfo)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                foreach (var listInstance in template.Lists)
                {
                    List list = web.Lists.GetById(listInstance.ID);
                    web.Context.Load(list);
                    web.Context.ExecuteQueryRetry();

                    if (creationInfo.ExecutePreProvisionEvent<ListInstance, List>(Handlers.ListContents, template, listInstance, list))
                    {
                        ListItemsProvider provider = new ListItemsProvider(list, web, template);
                        List<DataRow> dataRows = provider.ExtractItems(creationInfo, parser, scope);
                        listInstance.DataRows.AddRange(dataRows);

                        creationInfo.ExecutePostProvisionEvent<ListInstance, List>(Handlers.ListContents, template, listInstance, list);
                    }
                }
            }
            return template;
        }
开发者ID:skybow,项目名称:PnP-Sites-Core,代码行数:22,代码来源:ObjectListInstanceDataRows.cs

示例3: ExtractObjects

        public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateCreationInformation creationInfo)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                // if this is a sub site then we're not creating field entities.
                if (web.IsSubSite())
                {
                    scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Context_web_is_subweb__skipping_site_columns);
                    return template;
                }

                var existingFields = web.Fields;
                web.Context.Load(web, w => w.ServerRelativeUrl);
                web.Context.Load(existingFields);
                web.Context.Load(web.Lists, ls => ls.Include(l => l.Id, l => l.Title));
                web.Context.ExecuteQueryRetry();

                var taxTextFieldsToMoveUp = new List<Guid>();

                foreach (var field in existingFields)
                {
                    if (!BuiltInFieldId.Contains(field.Id))
                    {
                        if (creationInfo.ExecutePreProvisionEvent<Field,SPField>(Handlers.Fields, template, null, field))
                        {
                            var fieldXml = field.SchemaXml;
                            XElement element = XElement.Parse(fieldXml);

                            // Check if the field contains a reference to a list. If by Guid, rewrite the value of the attribute to use web relative paths
                            var listIdentifier = element.Attribute("List") != null ? element.Attribute("List").Value : null;
                            if (!string.IsNullOrEmpty(listIdentifier))
                            {
                                var listGuid = Guid.Empty;
                                fieldXml = ParseFieldSchema(fieldXml, web.Lists);
                                element = XElement.Parse(fieldXml);
                                //if (Guid.TryParse(listIdentifier, out listGuid))
                                //{
                                //    fieldXml = ParseListSchema(fieldXml, web.Lists);
                                //if (newfieldXml == fieldXml)
                                //{
                                //    var list = web.Lists.GetById(listGuid);
                                //    web.Context.Load(list, l => l.RootFolder.ServerRelativeUrl);
                                //    web.Context.ExecuteQueryRetry();

                                //    var listUrl = list.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart('/');
                                //    element.Attribute("List").SetValue(listUrl);
                                //    fieldXml = element.ToString();
                                //}
                                //}
                            }
                            // Check if the field is of type TaxonomyField
                            if (field.TypeAsString.StartsWith("TaxonomyField"))
                            {
                                var taxField = (TaxonomyField)field;
                                web.Context.Load(taxField, tf => tf.TextField, tf => tf.Id);
                                web.Context.ExecuteQueryRetry();
                                taxTextFieldsToMoveUp.Add(taxField.TextField);
                            }
                            // Check if we have version attribute. Remove if exists
                            if (element.Attribute("Version") != null)
                            {
                                element.Attributes("Version").Remove();
                                fieldXml = element.ToString();
                            }
                            Field templateField = new Field() { SchemaXml = fieldXml };
                            template.SiteFields.Add(templateField);

                            creationInfo.ExecutePostProvisionEvent<Field, SPField>(Handlers.Fields, template, templateField, field);
                        }
                    }
                }
                // move hidden taxonomy text fields to the top of the list
                foreach (var textFieldId in taxTextFieldsToMoveUp)
                {
                    var field = template.SiteFields.First(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId));
                    template.SiteFields.RemoveAll(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId));
                    template.SiteFields.Insert(0, field);
                }
                // If a base template is specified then use that one to "cleanup" the generated template model
                if (creationInfo.BaseTemplate != null)
                {
                    template = CleanupEntities(template, creationInfo.BaseTemplate);
                }
            }
            return template;
        }
开发者ID:skybow,项目名称:PnP-Sites-Core,代码行数:86,代码来源:ObjectField.cs

示例4: ExtractObjects

        public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateCreationInformation creationInfo)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                web.EnsureProperties(w => w.ServerRelativeUrl, w => w.Url, w => w.Id);

                var serverRelativeUrl = web.ServerRelativeUrl;

                // For each list in the site
                var lists = web.Lists;

                web.Context.Load(lists,
                    lc => lc.IncludeWithDefaultProperties(
                        l => l.ContentTypes.IncludeWithDefaultProperties(
                            ct => ct.Parent,
                            ct => ct.Parent.StringId,
                            ct => ct.FieldLinks
                            ),
                        l => l.Id,
                        l => l.ParentWebUrl,
                        l => l.Views,
                        l => l.DefaultNewFormUrl,
                        l => l.DefaultDisplayFormUrl,
                        l => l.DefaultEditFormUrl,
                        l => l.BaseTemplate,
                        l => l.OnQuickLaunch,
                        l => l.RootFolder.ServerRelativeUrl,
                        l => l.Fields.IncludeWithDefaultProperties(
                            f => f.Id,
                            f => f.Title,
                            f => f.Hidden,
                            f => f.InternalName,
                            f => f.Required),
                        l => l.HasUniqueRoleAssignments));

                web.Context.ExecuteQueryRetry();

                // Let's see if there are workflow subscriptions
                Microsoft.SharePoint.Client.WorkflowServices.WorkflowSubscription[] workflowSubscriptions = null;
                try
                {
                    workflowSubscriptions = web.GetWorkflowSubscriptions();
                }
                catch (ServerException)
                {
                    // If there is no workflow service present in the farm this method will throw an error.
                    // Swallow the exception
                }

                // Retrieve all not hidden lists and the Workflow History Lists, just in case there are active workflow subscriptions
                var includeWorkflowSubscriptions = workflowSubscriptions != null && workflowSubscriptions.Length > 0;
                var allowedLists = lists.AsEnumerable().Where(l => !l.Hidden || includeWorkflowSubscriptions && l.BaseTemplate == 140);

                //Performance improvements: retrieve site columns for extract list fields
                var siteColumns = web.AvailableFields;
                web.Context.Load(siteColumns, scs => scs.Include(sc => sc.Id));
                web.Context.ExecuteQueryRetry();

                foreach (var siteList in allowedLists)
                {
                    ListInstance baseTemplateList = null;
                    if (creationInfo.BaseTemplate != null)
                    {
                        // Check if we need to skip this list...if so let's do it before we gather all the other information for this list...improves performance
                        var index = creationInfo.BaseTemplate.Lists.FindIndex(f => f.Url.Equals(siteList.RootFolder.ServerRelativeUrl.Substring(serverRelativeUrl.Length + 1)) &&
                                                                                   f.TemplateType.Equals(siteList.BaseTemplate));
                        if (index != -1)
                        {
                            baseTemplateList = creationInfo.BaseTemplate.Lists[index];
                            if (siteList.Hidden && !(includeWorkflowSubscriptions && siteList.BaseTemplate == 140))
                            {
                                continue;
                            }
                        }
                    }

                    if (!creationInfo.ExecutePreProvisionEvent<ListInstance, List>(Handlers.Lists, template, null, siteList))
                    {
                        continue;
                    }

                    string documentTemplateContent = string.Empty;
                    if (!String.IsNullOrEmpty(siteList.DocumentTemplateUrl)) {
                        documentTemplateContent = web.GetFileAsString(siteList.DocumentTemplateUrl);
                    }

                    var contentTypeFields = new List<FieldRef>();
                    var list = new ListInstance
                    {
                        Description = siteList.Description,
                        EnableVersioning = siteList.EnableVersioning,
                        TemplateType = siteList.BaseTemplate,
                        Title = siteList.Title,
                        Hidden = siteList.Hidden,
                        EnableFolderCreation = siteList.EnableFolderCreation,
                        DocumentTemplate = TokenizeUrl(siteList.DocumentTemplateUrl, parser),
                        DocumentTemplateContent = documentTemplateContent,
                        ContentTypesEnabled = siteList.ContentTypesEnabled,
                        Url = siteList.RootFolder.ServerRelativeUrl.Substring(serverRelativeUrl.Length).TrimStart('/'),
                        TemplateFeatureID = siteList.TemplateFeatureId,
//.........这里部分代码省略.........
开发者ID:skybow,项目名称:PnP-Sites-Core,代码行数:101,代码来源:ObjectListInstance.cs


注:本文中的OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.ProvisioningTemplateCreationInformation.ExecutePreProvisionEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。