本文整理汇总了C#中TemplateService.Run方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateService.Run方法的具体用法?C# TemplateService.Run怎么用?C# TemplateService.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TemplateService
的用法示例。
在下文中一共展示了TemplateService.Run方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnExecute
protected override async Task OnExecute()
{
var dc = GetDatacenter(required: true);
var service = dc.GetService(Service);
if (service == null)
{
await Console.WriteErrorLine(Strings.Config_GenerateCommand_NoSuchService, Service, dc.FullName);
return;
}
// Get the config template for this service
if (dc.Environment.ConfigTemplates == null)
{
await Console.WriteErrorLine(Strings.Config_GenerateCommand_NoTemplateSource, dc.Environment.FullName);
}
else
{
if (!String.Equals(dc.Environment.ConfigTemplates.Type, FileSystemConfigTemplateSource.AbsoluteAppModelType, StringComparison.OrdinalIgnoreCase))
{
await Console.WriteErrorLine(Strings.Config_GenerateCommand_UnknownConfigTemplateSourceType, dc.Environment.ConfigTemplates.Type);
}
var configSource = new FileSystemConfigTemplateSource(dc.Environment.ConfigTemplates.Value);
var configTemplate = configSource.ReadConfigTemplate(service);
if (String.IsNullOrEmpty(configTemplate))
{
await Console.WriteErrorLine(Strings.Config_GenerateCommand_NoTemplate, service.FullName);
}
else
{
var secrets = await GetEnvironmentSecretStore(Session.CurrentEnvironment);
// Render the template
var engine = new TemplateService(new TemplateServiceConfiguration()
{
BaseTemplateType = typeof(ConfigTemplateBase),
Language = Language.CSharp
});
await Console.WriteInfoLine(Strings.Config_GenerateCommand_CompilingConfigTemplate, service.FullName);
engine.Compile(configTemplate, typeof(object), "configTemplate");
await Console.WriteInfoLine(Strings.Config_GenerateCommand_ExecutingTemplate, service.FullName);
string result = engine.Run("configTemplate", new ConfigTemplateModel(secrets, service), null);
// Write the template
if (String.IsNullOrEmpty(OutputFile))
{
await Console.WriteDataLine(result);
}
else
{
File.WriteAllText(OutputFile, result);
await Console.WriteInfoLine(Strings.Config_GenerateCommand_GeneratedConfig, OutputFile);
}
}
}
}
示例2: Eval
public static string Eval(string expression)
{
try
{
string hashCode = expression.GetHashCode().ToString();
var task = DependencyManager.CachingService.Get<Task>("Task." + hashCode);
if (task != null && !task.IsCompleted)
{
task.Wait();
}
TemplateService service = new TemplateService();
return service.Run(DependencyManager.CachingService.Get<ITemplate>(hashCode), null);
}
catch (Exception ex)
{
ValidUrl validurl = Utility.GetValidUrlFromContext(new HttpContextWrapper(HttpContext.Current));
string url = validurl != null ? validurl.FriendlyUrl + "::" + validurl.Id.ToString() + "::" : string.Empty;
LogEventInfo info = new LogEventInfo(LogLevel.Error, ECMSSettings.DEFAULT_LOGGER, url + ex.ToString());
DependencyManager.Logger.Log(info);
return string.Empty;
}
}
示例3: Issue27_StreamLiningTheITemplateServiceApi_CreateTemplates
public void Issue27_StreamLiningTheITemplateServiceApi_CreateTemplates()
{
string[] razorTemplates;
Type[] templateTypes;
int index;
using (var service = new TemplateService())
{
// Success case
razorTemplates = new string[] { "Template1", "Template2", "Template3" };
templateTypes = new Type[] { null, null, null };
IEnumerable<ITemplate> instances = service.CreateTemplates(razorTemplates, templateTypes, null, false);
index = 0;
foreach (ITemplate instance in instances)
{
string expected = razorTemplates[index];
string result = service.Run(instance, null);
Assert.That(result == expected, "Result does not match expected: " + result);
index++;
}
// No razorTemplates or templateTypes provided
Assert.Throws<ArgumentException>(() =>
{
service.CreateTemplates(null, null, null, false);
});
// Unbalanced razorTemplates/templateTypes (templateTypes to small)
Assert.Throws<ArgumentException>(() =>
{
razorTemplates = new string[] { "Template1", "Template2", "Template3" };
templateTypes = new Type[] { null, null };
service.CreateTemplates(razorTemplates, templateTypes, null, false);
});
// Unbalanced razorTemplates/templateTypes (templateTypes too large)
Assert.Throws<ArgumentException>(() =>
{
razorTemplates = new string[] { "Template1", "Template2", "Template3" };
templateTypes = new Type[] { null, null, null, null };
service.CreateTemplates(razorTemplates, templateTypes, null, false);
});
// Unbalanced razorTemplates/templateTypes (razorTemplates and templateTypes are NULL)
Assert.Throws<ArgumentException>(() =>
{
razorTemplates = new string[] { "Template1", "Template2", null };
templateTypes = new Type[] { null, null, null };
service.CreateTemplates(razorTemplates, templateTypes, null, false);
});
}
}
示例4: TemplateService_CanPrecompileTemplate_WithSimpleModel
public void TemplateService_CanPrecompileTemplate_WithSimpleModel()
{
using (var service = new TemplateService())
{
const string template = "Hello @Model.Forename";
const string expected = "Hello Matt";
var model = new Person { Forename = "Matt" };
service.Compile<Person>(template, "test");
string result = service.Run("test", model);
Assert.That(result == expected, "Result does not match expected.");
}
}
示例5: TemplateService_CanPrecompileTemplate_WithNoModel
public void TemplateService_CanPrecompileTemplate_WithNoModel()
{
using (var service = new TemplateService())
{
const string template = "Hello World";
const string expected = "Hello World";
service.Compile(template, "test");
string result = service.Run("test");
Assert.That(result == expected, "Result does not match expected.");
}
}