本文整理汇总了C#中ITemplateKey类的典型用法代码示例。如果您正苦于以下问题:C# ITemplateKey类的具体用法?C# ITemplateKey怎么用?C# ITemplateKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITemplateKey类属于命名空间,在下文中一共展示了ITemplateKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KeysHaveEqualModifiedTime
private bool KeysHaveEqualModifiedTime(ITemplateKey key1, ITemplateKey key2)
{
var keyWithTime1 = (FullPathWithModifiedTimeTemplateKey)key1;
var keyWithTime2 = (FullPathWithModifiedTimeTemplateKey)key2;
return keyWithTime1.ModifiedTime == keyWithTime2.ModifiedTime;
}
示例2: AddDynamic
public void AddDynamic(ITemplateKey key, ITemplateSource source)
{
// You can disable dynamic templates completely, but
// then all convenience methods (Compile and RunCompile) with
// a TemplateSource will no longer work (they are not really needed anyway).
throw new NotImplementedException("dynamic templates are not supported!");
}
示例3: AddDynamic
public void AddDynamic(ITemplateKey key, ITemplateSource source)
{
if (!_templates.ContainsKey(key))
{
_templates.Add(key, source);
}
}
示例4: GetKey
/// <summary>
/// Get the given key.
/// </summary>
/// <param name="name"></param>
/// <param name="resolveType"></param>
/// <param name="context"></param>
/// <returns></returns>
public ITemplateKey GetKey(string name, ResolveType resolveType, ITemplateKey context)
{
if (File.Exists (name))
{
return new FullPathTemplateKey(name, name, resolveType, context);
}
else
{
var resolved = layoutRoots.Select(l =>
{
var p = Path.Combine(l, name);
if (File.Exists(p))
{
return p;
}
else if (File.Exists(p + ".cshtml"))
{
return p + ".cshtml";
}
else
{
return null;
}
}).Where(l => l != null).FirstOrDefault();
if (resolved == null)
{
throw new InvalidOperationException(string.Format("Could not resolve template {0}", name));
}
else
{
return new FullPathTemplateKey(name, resolved, resolveType, context);
}
}
}
示例5: GetKey
public ITemplateKey GetKey(string name, ResolveType resolveType, ITemplateKey context)
{
if (ManifestResourceHelper.checkExistsManifestResource(name))
{
return new ResourcePathTemplateKey(name, name, resolveType, context);
}
var existsResourceNames = layoutRoots.Select(m =>
{
string resourcePath = string.Format(m, name);
if (ManifestResourceHelper.checkExistsManifestResource(resourcePath))
{
return resourcePath;
}
resourcePath += ".cshtml";
if (ManifestResourceHelper.checkExistsManifestResource(resourcePath))
{
return resourcePath;
}
return null;
});
var resourceName = existsResourceNames.Where(m => !string.IsNullOrEmpty(m)).FirstOrDefault();
if (resourceName == null)
{
throw new InvalidOperationException(string.Format("Could not resolve template {0}", name));
}
return new ResourcePathTemplateKey(name, resourceName, resolveType, context);
}
示例6: GetKey
/// <summary>
/// Get the given key.
/// </summary>
/// <param name="name"></param>
/// <param name="resolveType"></param>
/// <param name="context"></param>
/// <returns></returns>
public new ITemplateKey GetKey(string name, ResolveType resolveType, ITemplateKey context)
{
var fullPath = ResolveFilePath(name);
var modifiedTime = File.GetLastWriteTimeUtc(fullPath);
return new FullPathWithModifiedTimeTemplateKey(name, fullPath, modifiedTime, resolveType, context);
}
示例7: GetKey
public ITemplateKey GetKey(string name, ResolveType resolveType, ITemplateKey context)
{
// If you can have different templates with the same name depending on the
// context or the resolveType you need your own implementation here!
// Otherwise you can just use NameOnlyTemplateKey.
return new NameOnlyTemplateKey(name, resolveType, context);
}
示例8: CacheTemplateHelper
private void CacheTemplateHelper(ICompiledTemplate template, ITemplateKey templateKey, Type modelTypeKey)
{
var uniqueKey = templateKey.GetUniqueKeyString();
_cache.AddOrUpdate(uniqueKey, key =>
{
// new item added
_assemblies.Add(template.TemplateAssembly);
var dict = new ConcurrentDictionary<Type, ICompiledTemplate>();
dict.AddOrUpdate(modelTypeKey, template, (t, old) => {
throw new Exception("Expected the dictionary to be empty."); });
return dict;
}, (key, dict) =>
{
dict.AddOrUpdate(modelTypeKey, t =>
{
// new item added (template was not compiled with the given type).
_assemblies.Add(template.TemplateAssembly);
return template;
}, (t, old) =>
{
// item was already added before
return template;
});
return dict;
});
}
示例9: Resolve
public ITemplateSource Resolve(ITemplateKey key)
{
if (_templates.ContainsKey(key))
{
return _templates[key];
}
var templatePath = Path.Combine(includesPath, key.Name);
var templateExists = fileSystem.File.Exists(templatePath);
if (!templateExists)
{
foreach (var ext in new[] { ".cshtml", ".html", ".htm" })
{
var testPath = String.Concat(templatePath, ext);
templateExists = fileSystem.File.Exists(testPath);
if (templateExists)
{
templatePath = testPath;
break;
}
}
}
var template = templateExists ? fileSystem.File.ReadAllText(templatePath) : String.Empty;
return new LoadedTemplateSource(template, null);
}
示例10: Compile
/// <summary>
/// Compiles the specified template.
/// </summary>
/// <param name="key">The string template.</param>
/// <param name="modelType">The model type.</param>
public ICompiledTemplate Compile(ITemplateKey key, Type modelType)
{
Contract.Requires(key != null);
var source = Resolve(key);
var result = CreateTemplateType(source, modelType);
return new CompiledTemplate(result.Item2, key, source, result.Item1, modelType);
}
示例11: Resolve
//методы
public ITemplateSource Resolve(ITemplateKey key)
{
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _templateFolder, key.Name);
string template = File.ReadAllText(filePath);
// Provide a non-null file to improve debugging
return new LoadedTemplateSource(template, filePath);
}
示例12: CompiledTemplate
public CompiledTemplate(CompilationData tempFiles, ITemplateKey key, ITemplateSource source, Type templateType, Type modelType)
{
_tempFiles = tempFiles;
_key = key;
_source = source;
_templateType = templateType;
_modelType = modelType;
}
示例13: InternalTemplateService
public InternalTemplateService(RazorEngineCore service, ITemplateKey template)
{
Contract.Requires(service != null);
Contract.Requires(template != null);
_service = service;
_template = template;
}
示例14: Resolve
public ITemplateSource Resolve(ITemplateKey key)
{
ResourcePathTemplateKey resourcePathTemplateKey = key as ResourcePathTemplateKey;
if (resourcePathTemplateKey == null)
{
throw new NotSupportedException("You can only use ResourcePathTemplateKey with this manager");
}
return new LoadedTemplateSource(ManifestResourceHelper.getManifestResourceString(resourcePathTemplateKey.ResourcePath),
resourcePathTemplateKey.ResourcePath);
}
示例15: Resolve
/// <summary>
/// Resolve the given key
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public ITemplateSource Resolve(ITemplateKey key)
{
var full = key as FullPathTemplateKey;
if (full == null)
{
throw new NotSupportedException("You can only use FullPathTemplateKey with this manager");
}
var template = File.ReadAllText(full.FullPath);
return new LoadedTemplateSource(template, full.FullPath);
}