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


C# TemplateService.Run方法代码示例

本文整理汇总了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);
                    }
                }
            }
        }
开发者ID:NuGet,项目名称:NuGet.Operations,代码行数:56,代码来源:GenerateCommand.cs

示例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;
            }
        }
开发者ID:ramkumar013,项目名称:ECMS,代码行数:23,代码来源:ViewHelper.cs

示例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);
                });
            }
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:53,代码来源:Release_3_0_TestFixture.cs

示例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.");
            }
        }
开发者ID:SaintLoong,项目名称:RazorEngineNET4.0,代码行数:16,代码来源:TemplateServiceTestFixture.cs

示例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.");
            }
        }
开发者ID:SaintLoong,项目名称:RazorEngineNET4.0,代码行数:14,代码来源:TemplateServiceTestFixture.cs


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