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


C# TemplateService.Compile方法代码示例

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


在下文中一共展示了TemplateService.Compile方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Issue11_TemplateServiceShouldCompileModellessTemplate

        public void Issue11_TemplateServiceShouldCompileModellessTemplate()
        {
            using (var service = new TemplateService())
            {
                const string template = "<h1>Hello World</h1>";

                service.Compile(template, null, "issue11");
            }
        }
开发者ID:rmeshksar,项目名称:RazorEngine,代码行数:9,代码来源:Release_3_0_TestFixture.cs

示例2: 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

示例3: Issue7_ViewBagShouldPersistThroughLayout

        public void Issue7_ViewBagShouldPersistThroughLayout()
        {
            using (var service = new TemplateService())
            {
                const string layoutTemplate = "<h1>@ViewBag.Title</h1>@RenderSection(\"Child\")";
                const string childTemplate = "@{ Layout =  \"Parent\"; ViewBag.Title = \"Test\"; }@section Child {}";

                service.Compile(layoutTemplate, null, "Parent");

                string result = service.Parse(childTemplate, null, null, null);

                Assert.That(result.StartsWith("<h1>Test</h1>"));
            }
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:14,代码来源:Release_3_0_TestFixture.cs

示例4: CompiledRazorView_Should_Render_Compiled_Template_When_TemplateService_Is_Provided

        public void CompiledRazorView_Should_Render_Compiled_Template_When_TemplateService_Is_Provided()
        {
            var templateService = new TemplateService();
            templateService.Compile("@model object\r\nHello World!", "test");

            var view = new CompiledRazorView("test", templateService);
            var context = new Mock<ViewContext>();
            context.Setup(c => c.ViewData).Returns(new ViewDataDictionary(new object()));
            using (var writer = new StringWriter())
            {
                view.Render(context.Object, writer);
                var content = writer.GetStringBuilder().ToString();
                Assert.Equal("Hello World!", content);
            }
        }
开发者ID:pmarflee,项目名称:postal,代码行数:15,代码来源:CompiledRazorViewTests.cs

示例5: Issue6_ModelShouldBePassedToLayout

        public void Issue6_ModelShouldBePassedToLayout()
        {
            using (var service = new TemplateService())
            {
                const string layoutTemplate = "<h1>@Model.PageTitle</h1> @RenderSection(\"Child\")";
                const string childTemplate = "@{ Layout = \"Parent\"; }@section Child {<h2>@Model.PageDescription</h2>}";
                const string expected = "<h1>Test Page</h1> <h2>Test Page Description</h2>";

                var model = new {
                                    PageTitle = "Test Page",
                                    PageDescription = "Test Page Description"
                                };

                var type = model.GetType();

                service.Compile(layoutTemplate, type, "Parent");

                string result = service.Parse(childTemplate, model, null, null);

                Assert.That(result == expected, "Result does not match expected: " + result);
            }
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:22,代码来源:Release_3_0_TestFixture.cs

示例6: AssertViewCanBeCompiled

        private void AssertViewCanBeCompiled(string content, string viewPath, TemplateService processor)
        {
            try
            {
                processor.Compile(content, null, viewPath);
            }
            catch (TemplateCompilationException ex)
            {
                var message = new StringBuilder()
                    .AppendFormat("The view: {0} cannot be compiled because of the following errors:", viewPath);

                foreach (var error in ex.Errors)
                {
                    if (!error.IsWarning)
                    {
                        message.AppendLine().AppendFormat(
                            CultureInfo.InvariantCulture,
                            "Error: {0} - {1}",
                            error.ErrorNumber,
                            error.ErrorText);
                    }
                }

                Assert.Fail(message.ToString());
            }
        }
开发者ID:RichiL,项目名称:feather-widgets,代码行数:26,代码来源:ViewsCompilationTests.cs

示例7: Issue93_SectionParsing

        public void Issue93_SectionParsing()
        {
            using (var service = new TemplateService())
            {
                string parent = @"@RenderSection(""MySection"", false)";
                string section_test_1 = "@{ Layout = \"ParentLayout\"; }@section MySection { My section content }";
                string section_test_2 = "@{ Layout = \"ParentLayout\"; }@section MySection {\nMy section content\n}";
                string section_test_3 = "@{ Layout = \"ParentLayout\"; }@section MySection {\nMy section content\na}";
                string expected_1 = " My section content ";
                string expected_2 = "\nMy section content\n";
                string expected_3 = "\nMy section content\na";
                service.Compile(parent, null, "ParentLayout");

                var result_1 = service.Parse(section_test_1, null, null, null);
                var result_2 = service.Parse(section_test_2, null, null, null);
                var result_3 = service.Parse(section_test_3, null, null, null);

                Assert.AreEqual(expected_1, result_1);
                Assert.AreEqual(expected_2, result_2);
                Assert.AreEqual(expected_3, result_3);
            }
        }
开发者ID:rmeshksar,项目名称:RazorEngine,代码行数:22,代码来源:Release_3_6_TestFixture.cs

示例8: Issue21_SubclassModelShouldBeSupportedInLayout

        public void Issue21_SubclassModelShouldBeSupportedInLayout()
        {
            using (var service = new TemplateService())
            {
                const string parent = "@model RazorEngine.Tests.TestTypes.Person\n<h1>@Model.Forename</h1>@RenderSection(\"Child\")";
                service.Compile(parent, null, "Parent");

                const string child = "@{ Layout = \"Parent\"; }\[email protected] Child { <h2>@Model.Department</h2> }";
                const string expected = "<h1>Matt</h1> <h2>IT</h2> ";

                var model = new Employee
                {
                    Age = 27,
                    Department = "IT",
                    Forename = "Matt",
                    Surname = "Abbott"
                };

                string result = service.Parse(child, model, null, null);

                Assert.That(result == expected, "Result does not match expected: " + result);
            }
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:23,代码来源:Release_3_0_TestFixture.cs

示例9: RenderPageTemplate

        public string RenderPageTemplate(int? pageTemplateId, PageRenderModel model)
        {
            var pageTemplate = GetById(pageTemplateId);
            var config = _templateServices.GetConfig();
            using (var templateService = new TemplateService(config))
            {
                /*
                 * Get default master template for all content
                 * This template is used for including some scripts or html for all page contents and file contents
                */
                var defaultTemplate = GetDefaultTemplate();
                var template = defaultTemplate.Content;
                template = CurlyBracketParser.ParseProperties(template);
                template = CurlyBracketParser.ParseRenderBody(template);

                var layout = TemplateServices.GetTemplateCacheName(defaultTemplate.Name, defaultTemplate.Created,
                                                                   defaultTemplate.Updated);
                if (Razor.Resolve(layout) == null)
                {
                    templateService.Compile(template, typeof(PageRenderModel), layout);
                }

                /*
                 * Loop all the parent template to compile and render layout
                */
                if (pageTemplate != null)
                {
                    // Using hierarchy to load all parent templates
                    var pageTemplates =
                        _pageTemplateRepository.GetAll().Where(t => pageTemplate.Hierarchy.Contains(t.Hierarchy))
                        .OrderBy(t => t.Hierarchy)
                        .Select(t => new
                        {
                            t.Content,
                            t.Name,
                            t.Updated,
                            t.Created
                        });
                    if (pageTemplates.Any())
                    {
                        foreach (var item in pageTemplates)
                        {
                            //Convert curly bracket properties to razor syntax
                            template = CurlyBracketParser.ParseProperties(item.Content);

                            //Insert master page for child template and parsing
                            template = InsertMasterPage(template, layout);
                            template = FormatMaster(template);
                            template = templateService.Parse(template, model, null, null);
                            template = ReformatMaster(template);

                            //This used for re-cache the template
                            layout = TemplateServices.GetTemplateCacheName(item.Name, item.Created, item.Updated);

                            //Convert {RenderBody} to @RenderBody() for next rendering
                            template = CurlyBracketParser.ParseRenderBody(template);
                            if (Razor.Resolve(layout) == null)
                            {
                                templateService.Compile(template, typeof(PageRenderModel), layout);
                            }
                        }
                    }
                }
                return template;
            }
        }
开发者ID:gulelat,项目名称:pxhotel,代码行数:66,代码来源:PageTemplateServices.cs

示例10: ProcessSubContent

        private void ProcessSubContent(Match match, TemplateService service, dynamic model)
        {
            var subName = match.Groups[1].Value;
            string subContent;
            if (this.Cache.TryGetValue(subName, out subContent))
            {
                // Process inputs
                subContent = this.ProcessInputs(subContent);

                // Recursively process it and add to the service
                ProcessContent(subContent, service, model);

                // Compile the template
                service.Compile(subContent, typeof(AssetHeader), subName);
            }
        }
开发者ID:MatthewNichols,项目名称:misakai-baker,代码行数:16,代码来源:RazorViewEngine.cs

示例11: 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

示例12: 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

示例13: Compile

        public void Compile(Type model)
        {
            Contract.Requires(model != null);

            if (String.IsNullOrWhiteSpace(Subject))
                throw new ArgumentNullException("Subject");
            if (String.IsNullOrWhiteSpace(Email))
                throw new ArgumentNullException("Email");
            if (String.IsNullOrWhiteSpace(MailFrom))
                throw new ArgumentNullException("MailFrom");
            if (String.IsNullOrWhiteSpace(NameFrom))
                throw new ArgumentNullException("NameFrom");

            templateService = new TemplateService(new TemplateServiceConfiguration
            {
                BaseTemplateType = typeof(IrisTemplateBase<>)
            });

            templateService.Compile(Subject, model, "Subject");
            templateService.Compile(Email, model, "Email");
            templateService.Compile(MailFrom, model, "MailFrom");
            templateService.Compile(NameFrom, model, "NameFrom");
            templateService.Compile(HtmlBody, model, "HtmlBody");

            if (ReplyTo != null)
                templateService.Compile(ReplyTo, model, "ReplyTo");
            if (TextBody != null)
                templateService.Compile(TextBody, model, "TxtBody");
        }
开发者ID:Aestek,项目名称:IrisMailer,代码行数:29,代码来源:TemplateMessage.cs

示例14: Compile

 public void Compile(string template, Type type, string cacheName)
 {
     var config = GetConfig();
     var templateService = new TemplateService(config);
     templateService.Compile(template, type, cacheName);
 }
开发者ID:gulelat,项目名称:pxhotel,代码行数:6,代码来源:TemplateServices.cs


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