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


C# IFileService.SaveTemplate方法代码示例

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


在下文中一共展示了IFileService.SaveTemplate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CreateTemplateIfNotExists

        /// <summary>
        /// Creates an Umbraco template and associated view file.
        /// </summary>
        /// <param name="fileService">The file service.</param>
        /// <param name="displayName">The display name of the Umbraco template.</param>
        /// <param name="templateAlias">Alias of the template, also used as the name of the view file.</param>
        /// <param name="masterTemplate">The master page or MVC to inherit from.</param>
        /// <param name="type">An Inception type name used in the generated view file.</param>
        /// <param name="customDirectoryPath">The custom directory path if not ~/Views/.</param>
        /// <returns></returns>
        private static Template CreateTemplateIfNotExists(IFileService fileService, string displayName, string templateAlias, string masterTemplate=null, Type type=null, string customDirectoryPath=null)
        {
            var template = fileService.GetTemplate(templateAlias) as Template;
            if (template == null)
            {
                var defaultDirectoryPath = "~/Views/";
                var defaultFilePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}.cshtml", defaultDirectoryPath, templateAlias);

                string filePath;
                if (string.IsNullOrEmpty(customDirectoryPath))
                {
                    filePath = defaultFilePath;
                }
                else
                {
                    filePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}.cshtml",
                        customDirectoryPath, // The template location
                        customDirectoryPath.EndsWith("/") ? string.Empty : "/", // Ensure the template location ends with a "/"
                        templateAlias); // The alias
                }

                string physicalViewFileLocation = HostingEnvironment.MapPath(filePath);
                if (System.IO.File.Exists(physicalViewFileLocation))
                {
                    // If we create the template record in the database Umbraco will create a view file regardless, overwriting what's there. 
                    // If the MVC view is already there we can protect it by making a temporary copy which can then be moved back to the original location. 
                    System.IO.File.Copy(physicalViewFileLocation, physicalViewFileLocation + ".temp");

                    template = new Template(defaultDirectoryPath, displayName, templateAlias);
                    fileService.SaveTemplate(template, 0);

                    if (System.IO.File.Exists(physicalViewFileLocation) && System.IO.File.Exists(physicalViewFileLocation + ".temp"))
                    {
                        System.IO.File.Delete(physicalViewFileLocation);
                        System.IO.File.Move(physicalViewFileLocation + ".temp", physicalViewFileLocation);
                    }
                }
                else
                {
                    template = new Template(filePath, displayName, templateAlias);
                    CreateViewFile(masterTemplate, template, type, fileService);
                    fileService.SaveTemplate(template, 0);
                }
            }
            return template;
        }
开发者ID:east-sussex-county-council,项目名称:Escc.Umbraco.Inception,代码行数:56,代码来源:UmbracoCodeFirstInitializer.cs

示例3: CreateViewFile

        private static void CreateViewFile(string alias, string master, Template template, Type type, IFileService fileService)
        {
            string physicalView = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, ViewsFolder + "\\" + alias + ".cshtml");

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("@inherits Umbraco.Web.Mvc.UmbracoTemplatePage");
            sb.AppendLine("@*@using Qite.Umbraco.CodeFirst.Extensions;*@");
            sb.AppendLine("@{");
            sb.AppendLine("\tLayout = \"" + master + ".cshtml\";");
            sb.AppendLine("\t//" + type.Name + " model = Model.Content.ConvertToRealModel<" + type.Name + ">();");
            sb.AppendLine("}");

            using (StreamWriter sw = System.IO.File.CreateText(physicalView))
            {
                sw.Write(sb.ToString());
            }

            template.Content = sb.ToString();
            //This code doesn't work because template.MasterTemplateId is defined internal
            //I'll do a pull request to change this
            //TemplateNode rootTemplate = fileService.GetTemplateNode(master);
            //template.MasterTemplateId = new Lazy<int>(() => { return rootTemplate.Template.Id; });
            fileService.SaveTemplate(template, 0);
        }
开发者ID:JimBobSquarePants,项目名称:Umbraco-Inception,代码行数:24,代码来源:UmbracoCodeFirstInitializer.cs

示例4: CreateViewFile

        private static void CreateViewFile(string masterTemplate, Template template, Type type, IFileService fileService)
        {
            string physicalViewFileLocation = HostingEnvironment.MapPath(template.Path);
            if (string.IsNullOrEmpty(physicalViewFileLocation))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Failed to {0} to a physical location", template.Path));
            }

            var templateContent = CreateDefaultTemplateContent(masterTemplate, type);
            template.Content = templateContent;

            using (var sw = System.IO.File.CreateText(physicalViewFileLocation))
            {
                sw.Write(templateContent);
            }

            //This code doesn't work because template.MasterTemplateId is defined internal
            //I'll do a pull request to change this
            //TemplateNode rootTemplate = fileService.GetTemplateNode(master);
            //template.MasterTemplateId = new Lazy<int>(() => { return rootTemplate.Template.Id; });
            fileService.SaveTemplate(template, 0);

            //    //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,代码行数:25,代码来源:UmbracoCodeFirstInitializer.cs


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