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


C# IContentType.SetDefaultTemplate方法代码示例

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


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

示例1: UpdateContentType

        /// <summary>
        /// Update the existing content Type based on the data in the attributes
        /// </summary>
        /// <param name="contentTypeService"></param>
        /// <param name="fileService"></param>
        /// <param name="attribute"></param>
        /// <param name="contentType"></param>
        /// <param name="type"></param>
        /// <param name="dataTypeService"></param>
        private static void UpdateContentType(IContentTypeService contentTypeService, IFileService fileService, UmbracoContentTypeAttribute attribute, IContentType contentType, Type type, IDataTypeService dataTypeService)
        {
            contentType.Name = attribute.ContentTypeName;
            contentType.Alias = attribute.ContentTypeAlias;
            contentType.Icon = attribute.Icon;
            contentType.IsContainer = attribute.EnableListView;
            contentType.AllowedContentTypes = FetchAllowedContentTypes(attribute.AllowedChildren, contentTypeService);
            contentType.AllowedAsRoot = attribute.AllowedAtRoot;

            Type parentType = type.BaseType;
            if (parentType != null && parentType != typeof(UmbracoGeneratedBase) && parentType.GetBaseTypes(false).Any(x => x == typeof(UmbracoGeneratedBase)))
            {
                UmbracoContentTypeAttribute parentAttribute = parentType.GetCustomAttribute<UmbracoContentTypeAttribute>();
                if (parentAttribute != null)
                {
                    string parentAlias = parentAttribute.ContentTypeAlias;
                    IContentType parentContentType = contentTypeService.GetContentType(parentAlias);
                    contentType.ParentId = parentContentType.Id;
                }
                else
                {
                    throw new Exception("The given base class has no UmbracoContentTypeAttribute");
                }
            }

            if (attribute.CreateMatchingView)
            {
                Template currentTemplate = fileService.GetTemplate(attribute.ContentTypeAlias) as Template;
                if (currentTemplate == null)
                {
                    //there should be a template but there isn't so we create one
                    currentTemplate = new Template("~/Views/" + attribute.ContentTypeAlias + ".cshtml", attribute.ContentTypeName, attribute.ContentTypeAlias);
                    CreateViewFile(attribute.ContentTypeAlias, attribute.MasterTemplate, currentTemplate, type, fileService);
                    fileService.SaveTemplate(currentTemplate, 0);
                }
                contentType.AllowedTemplates = new ITemplate[] { currentTemplate };
                contentType.SetDefaultTemplate(currentTemplate);
            }

            VerifyProperties(contentType, type, dataTypeService);

            //verify if a tab has no properties, if so remove
            var propertyGroups = contentType.PropertyGroups.ToArray();
            int length = propertyGroups.Length;
            for (int i = 0; i < length; i++)
            {
                if (propertyGroups[i].PropertyTypes.Count == 0)
                {
                    //remove
                    contentType.RemovePropertyGroup(propertyGroups[i].Name);
                }
            }

            //persist
            contentTypeService.Save(contentType, 0);
        }
开发者ID:JimBobSquarePants,项目名称:Umbraco-Inception,代码行数:65,代码来源:UmbracoCodeFirstInitializer.cs

示例2: CreateMatchingView

        /// <summary>
        /// Creates a View if specified in the attribute
        /// </summary>
        /// <param name="fileService"></param>
        /// <param name="attribute"></param>
        /// <param name="type"></param>
        /// <param name="newContentType"></param>
        private static void CreateMatchingView(IFileService fileService, UmbracoContentTypeAttribute attribute, Type type, IContentType newContentType)
        {
            Template currentTemplate = fileService.GetTemplate(attribute.ContentTypeAlias) as Template;
            if (currentTemplate == null)
            {
                currentTemplate = new Template("~/Views/" + attribute.ContentTypeAlias + ".cshtml", attribute.ContentTypeName, attribute.ContentTypeAlias);
                CreateViewFile(attribute.ContentTypeAlias, attribute.MasterTemplate, currentTemplate, type, fileService);
            }

            newContentType.AllowedTemplates = new ITemplate[] { currentTemplate };
            newContentType.SetDefaultTemplate(currentTemplate);

            //TODO: in Umbraco 7.1 it will be possible to set the master template of the newly created template
            //https://github.com/umbraco/Umbraco-CMS/pull/294
        }
开发者ID:JimBobSquarePants,项目名称:Umbraco-Inception,代码行数:22,代码来源:UmbracoCodeFirstInitializer.cs

示例3: UpdateContentTypesAllowedTemplates

        private void UpdateContentTypesAllowedTemplates(IContentType contentType,
                                                        XElement allowedTemplatesElement, XElement defaultTemplateElement)
        {
            if (allowedTemplatesElement != null && allowedTemplatesElement.Elements("Template").Any())
            {
                var allowedTemplates = contentType.AllowedTemplates.ToList();
                foreach (var templateElement in allowedTemplatesElement.Elements("Template"))
                {
                    var alias = templateElement.Value;
                    var template = _fileService.GetTemplate(alias.ToSafeAlias());
                    if (template != null)
                    {
                        if(allowedTemplates.Any(x => x.Id == template.Id)) continue;
                        allowedTemplates.Add(template);
                    }
                    else
                    {
                        LogHelper.Warn<PackagingService>(
                            string.Format(
                                "Packager: Error handling allowed templates. Template with alias '{0}' could not be found.",
                                alias));
                    }
                }

                contentType.AllowedTemplates = allowedTemplates;
            }

            if (string.IsNullOrEmpty(defaultTemplateElement.Value) == false)
            {
                var defaultTemplate = _fileService.GetTemplate(defaultTemplateElement.Value.ToSafeAlias());
                if (defaultTemplate != null)
                {
                    contentType.SetDefaultTemplate(defaultTemplate);
                }
                else
                {
                    LogHelper.Warn<PackagingService>(
                        string.Format(
                            "Packager: Error handling default template. Default template with alias '{0}' could not be found.",
                            defaultTemplateElement.Value));
                }
            }
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:43,代码来源:PackagingService.cs

示例4: SetAllowedTemplates

        private void SetAllowedTemplates(IContentType contentType, DocumentTypeAttribute docTypeAttr, Type typeDocType)
        {
            List<ITemplate> allowedTemplates = GetAllowedTemplates(docTypeAttr, typeDocType);
            try
            {
                if ((allowedTemplates.Count == 0) && (contentType.AllowedTemplates.Count() != 0))
                {
                    // Clear all allowed templates and default template
                    foreach (var templateItem in contentType.AllowedTemplates)
                    {
                        contentType.RemoveTemplate(templateItem);
                    }
                }
                else
                {
                    contentType.AllowedTemplates = allowedTemplates.ToArray();
                }
            }
            catch (SqlHelperException e)
            {
                throw new Exception(string.Format("Sql error setting templates for doc type '{0}' with templates '{1}'",
                    GetDocumentTypeAlias(typeDocType), string.Join(", ", allowedTemplates)));
            }

            ITemplate defaultTemplate = GetDefaultTemplate(docTypeAttr, typeDocType, allowedTemplates);

            if (defaultTemplate != null)
            {
                contentType.SetDefaultTemplate(defaultTemplate);
            }
            else if (contentType.AllowedTemplates.Count() == 1) // if only one template is defined for this doc type -> make it default template for this doc type
            {
                contentType.SetDefaultTemplate(contentType.AllowedTemplates.First());
            }
        }
开发者ID:revolution42,项目名称:uSiteBuilder,代码行数:35,代码来源:DocumentTypeManager.cs

示例5: SetDefaultTemplateAndCreateIfNotExists

        /// <summary>
        /// Creates a View if specified in the attribute
        /// </summary>
        /// <param name="fileService">The file service.</param>
        /// <param name="masterTemplate">The parent master page or MVC layout.</param>
        /// <param name="templateLocation">The template location.</param>
        /// <param name="type">The type.</param>
        /// <param name="contentType">Type of the content.</param>
        private static void SetDefaultTemplateAndCreateIfNotExists(IFileService fileService, string masterTemplate, string templateLocation, Type type, IContentType contentType)
        {
            var templateAlias = String.IsNullOrEmpty(masterTemplate) ? contentType.Alias : masterTemplate;
            var currentTemplate = fileService.GetTemplate(templateAlias) as Template;
            if (currentTemplate == null)
            {
                currentTemplate = CreateTemplateIfNotExists(fileService, contentType.Name, contentType.Alias, masterTemplate, type, templateLocation);
            }

            AddToAllowedTemplates(currentTemplate, contentType);
            contentType.SetDefaultTemplate(currentTemplate);

            //TODO: in Umbraco 7.1 it will be possible to set the master template of the newly created template
            //https://github.com/umbraco/Umbraco-CMS/pull/294
        }
开发者ID:east-sussex-county-council,项目名称:Escc.Umbraco.Inception,代码行数:23,代码来源:UmbracoCodeFirstInitializer.cs

示例6: CreateMatchingView

        /// <summary>
        /// Creates a View if specified in the attribute
        /// </summary>
        /// <param name="fileService"></param>
        /// <param name="attribute"></param>
        /// <param name="type"></param>
        /// <param name="newContentType"></param>
        private static void CreateMatchingView(IFileService fileService, UmbracoContentTypeAttribute attribute, Type type, IContentType newContentType)
        {
            var currentTemplate = fileService.GetTemplate(attribute.ContentTypeAlias) as Template;
            if (currentTemplate == null)
            {
                string templatePath;
                if (string.IsNullOrEmpty(attribute.TemplateLocation))
                {
                    templatePath = string.Format(CultureInfo.InvariantCulture, "~/Views/{0}.cshtml", attribute.ContentTypeAlias);
                }
                else
                {
                    templatePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}.cshtml",
                        attribute.TemplateLocation,                                     // The template location
                        attribute.TemplateLocation.EndsWith("/") ? string.Empty : "/",  // Ensure the template location ends with a "/"
                        attribute.ContentTypeAlias);                                    // The alias
                }

                currentTemplate = new Template(templatePath, attribute.ContentTypeName, attribute.ContentTypeAlias);
                CreateViewFile(attribute.MasterTemplate, currentTemplate, type, fileService);
            }

            newContentType.AllowedTemplates = new ITemplate[] { currentTemplate };
            newContentType.SetDefaultTemplate(currentTemplate);

            //TODO: in Umbraco 7.1 it will be possible to set the master template of the newly created template
            //https://github.com/umbraco/Umbraco-CMS/pull/294
        }
开发者ID:strippedsharpgist,项目名称:Umbraco-Inception,代码行数:35,代码来源:UmbracoCodeFirstInitializer.cs


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