本文整理汇总了C#中IFileService.GetTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# IFileService.GetTemplate方法的具体用法?C# IFileService.GetTemplate怎么用?C# IFileService.GetTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileService
的用法示例。
在下文中一共展示了IFileService.GetTemplate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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
}
示例3: 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
示例4: 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
示例5: 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
}