• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ViewLocationResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ViewLocationResult的典型用法代码示例。如果您正苦于以下问题:C# ViewLocationResult类的具体用法?C# ViewLocationResult怎么用?C# ViewLocationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ViewLocationResult类属于命名空间,在下文中一共展示了ViewLocationResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: RenderView

        public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            var template = renderContext.ViewCache.GetOrAdd(viewLocationResult, result =>
            {
                try
                {
                    var context = new NancyVeilContext(renderContext, Extensions);
                    var engine = new VeilEngine(context);
                    Type modelType = model == null ? typeof(object) : model.GetType();
                    return engine.CompileNonGeneric(viewLocationResult.Extension, result.Contents(), modelType);
                }
                catch (Exception e)
                {
                    return CreateErrorPage(e);
                }
            });

            var response = new HtmlResponse();
            response.ContentType = "text/html; charset=utf-8";
            response.Contents = s =>
            {
                var writer = new StreamWriter(s, Encoding.UTF8);
                template(writer, model);
                writer.Flush();
            };
            return response;
        }
开发者ID:namics,项目名称:TerrificNet,代码行数:27,代码来源:VeilViewEngine.cs


示例2: Include_should_look_for_a_partial

        public void Include_should_look_for_a_partial()
        {
            // Set up the view startup context
            string partialPath = Path.Combine(Environment.CurrentDirectory, @"TestViews\_partial.liquid");

            // Set up a ViewLocationResult that the test can use
            var testLocation = new ViewLocationResult(
                Environment.CurrentDirectory,
                "test",
                "liquid",
                () => new StringReader(@"<h1>Including a partial</h1>{% include 'partial' %}")
            );

            var partialLocation = new ViewLocationResult(
                partialPath,
                "partial",
                "liquid",
                () => new StringReader(File.ReadAllText(partialPath))
            );

            var currentStartupContext = CreateContext(new [] {testLocation, partialLocation});

            this.engine = new DotLiquidViewEngine(new LiquidNancyFileSystem(currentStartupContext));

            // Given
            var stream = new MemoryStream();

            // When
            var response = this.engine.RenderView(testLocation, null, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Including a partial</h1>Some template.");
        }
开发者ID:JohanObrink,项目名称:Nancy,代码行数:34,代码来源:DotLiquidViewEngineFixture.cs


示例3: GetTemplateFromFile

 public static Template GetTemplateFromFile(ViewLocationResult path)
 {
     // can't cache anything here since template depends on current context
     var contents = path.Contents;
     var template = Template.Parse(contents);
     return template;
 }
开发者ID:rajendra1809,项目名称:VirtoCommerce,代码行数:7,代码来源:DotLiquidView.cs


示例4: RenderView

        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
        /// <param name="model">The model that should be passed into the view</param>
        /// <param name="renderContext"></param>
        /// <returns>A delegate that can be invoked with the <see cref="Stream"/> that the view should be rendered to.</returns>
        public Action<Stream> RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            return stream =>{

                var templateManagerProvider =
                    new TemplateManagerProvider()
                        .WithLoader(new TemplateLoader(viewLocationResult.Contents.Invoke()));

                var templateManager =
                    templateManagerProvider.GetNewManager();

                var template = renderContext.ViewCache.GetOrAdd(
                    viewLocationResult,
                    x => templateManager.GetTemplate(string.Empty));

                var context = new Dictionary<string, object> { { "Model", model } };
                var reader = template.Walk(templateManager, context);

                var writer =
                    new StreamWriter(stream);

                writer.Write(reader.ReadToEnd());
                writer.Flush();
            };
        }
开发者ID:nuxleus,项目名称:Nancy,代码行数:32,代码来源:NDjangoViewEngine.cs


示例5: Should_be_able_to_render_view_with_partial_to_stream

        public void Should_be_able_to_render_view_with_partial_to_stream()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "cshtml",
                () => new StringReader(@"@{var x = ""test"";}<h1>Hello Mr. @x</h1> @Html.Partial(""partial.cshtml"")")
            );

            var partialLocation = new ViewLocationResult(
                string.Empty,
                "partial.cshtml",
                "cshtml",
                () => new StringReader(@"this is partial")
            );

            A.CallTo(() => this.renderContext.LocateView("partial.cshtml",null)).Returns(partialLocation);

            var stream = new MemoryStream();

            // When
            var response = this.engine.RenderView(location, null,this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Hello Mr. test</h1> this is partial");
        }
开发者ID:rspacjer,项目名称:Nancy,代码行数:28,代码来源:RazorViewCompilerFixture.cs


示例6: Should_return_Markdown

        public void Should_return_Markdown()
        {
            // Given
            const string markdown = @"#Header1
##Header2
###Header3
Hi there!
> This is a blockquote.";

            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "md",
                () => new StringReader(markdown)
            );

            var html = this.viewEngine.ConvertMarkdown(location);

            var stream = new MemoryStream();

            A.CallTo(() => this.renderContext.ViewCache.GetOrAdd(location, A<Func<ViewLocationResult, string>>.Ignored))
             .Returns(html);

            // When
            var response = this.viewEngine.RenderView(location, null, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            var result = ReadAll(stream);
            result.ShouldEqual(html);
        }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:31,代码来源:MarkdownViewEngineFixture.cs


示例7: GetExtraParameters

        public virtual IDictionary<string, object> GetExtraParameters(ViewLocationResult viewLocationResult)
        {
            var extra = new Dictionary<string, object>();
            foreach (var filter in Filters)
            {
                filter.ExtraParameters(viewLocationResult, extra);
            }

            return extra;
        }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:10,代码来源:DefaultDescriptorBuilder.cs


示例8: RenderView

        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
        /// <param name="model">The model that should be passed into the view</param>
        /// <returns>A response.</returns>
        public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            return new HtmlResponse(contents: s =>
                {
                    var writer = new StreamWriter(s);
                    var templateContents = renderContext.ViewCache.GetOrAdd(viewLocationResult, vr => vr.Contents.Invoke().ReadToEnd());

                    writer.Write(this.viewEngine.Render(templateContents, model, new NancyViewEngineHost(renderContext)));
                    writer.Flush();
                });
        }
开发者ID:RobertTheGrey,项目名称:Nancy,代码行数:17,代码来源:SuperSimpleViewEngineWrapper.cs


示例9: RenderView

 public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
 {
     System.Diagnostics.Debug.WriteLine("test");
     return new HtmlResponse(
         contents: stream =>
         {
             var templateFactory = renderContext.ViewCache.GetOrAdd(
                 viewLocationResult, x => GetTemplateFactory(viewLocationResult));
             RenderTemplateFromTemplateFactory(templateFactory, stream, model, renderContext.Context);
         }
     );
 }
开发者ID:NHaml,项目名称:Nancy.ViewEngines.NHaml,代码行数:12,代码来源:NHamlViewEngine.cs


示例10: RenderView

        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
        /// <param name="model">The model that should be passed into the view</param>
        /// <returns>A delegate that can be invoked with the <see cref="Stream"/> that the view should be rendered to.</returns>
        public Action<Stream> RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            Interlocked.CompareExchange(ref this.viewEngine, new SuperSimpleViewEngine(new NancyViewEngineHost(renderContext)), null);

            return s =>
            {
                var writer = new StreamWriter(s);
                var templateContents = renderContext.ViewCache.GetOrAdd(viewLocationResult, vr => vr.Contents.Invoke().ReadToEnd());

                writer.Write(this.viewEngine.Render(templateContents, model));
                writer.Flush();
            };
        }
开发者ID:nuxleus,项目名称:Nancy,代码行数:19,代码来源:SuperSimpleViewEngineWrapper.cs


示例11: ConvertMarkdown

        /// <summary>
        /// Converts the markdown.
        /// </summary>
        /// <returns>
        /// HTML converted from markdown
        /// </returns>
        /// <param name='viewLocationResult'>
        /// View location result.
        /// </param>
        public string ConvertMarkdown(ViewLocationResult viewLocationResult)
        {
            string content =
                viewLocationResult.Contents().ReadToEnd();

            if (content.StartsWith("<!DOCTYPE html>"))
            {
                return MarkdownViewengineRender.RenderMasterPage(content);
            }

            var parser = new Markdown();
            var html = parser.Transform(content);
            return ParagraphSubstitution.Replace(html, "$1");
        }
开发者ID:kppullin,项目名称:Nancy,代码行数:23,代码来源:MarkDownViewEngine.cs


示例12: RenderView

        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
        /// <param name="model">The model to be passed into the view</param>
        /// <param name="renderContext"></param>
        /// <returns>A response</returns>
        public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            return new HtmlResponse
            {
                Contents = stream =>
                {
                    var templateName = viewLocationResult.Name;

                    var handlebars = threadLocalHandlebars.Value;
                    handlebars.RegisterTemplate(templateName, () =>
                    {
                        using (var textReader = viewLocationResult.Contents())
                        {
                            return textReader.ReadToEnd();
                        }

                    });
                    foreach (var partial in viewLocator.GetAllCurrentlyDiscoveredViews().Where(x => x.Name.StartsWith("_")))
                    {
                        var partialName = partial.Name.TrimStart('_');
                        handlebars.RegisterPartial(partialName, () =>
                        {
                            using (var textReader = partial.Contents())
                            {
                                return textReader.ReadToEnd();
                            }
                        });
                    }
                    using (var writer = new StreamWriter(stream))
                    {
                        dynamic output;
                        try
                        {
                            output = handlebars.Transform(templateName, model);
                        }
                        catch (Exception)
                        {
                            //TODO: remove this exception handling after a few versions
                            var templateContents = viewLocationResult.Contents().ReadToEnd();
                            if (templateContents.Contains("{{> _") || templateContents.Contains("{{>_"))
                            {
                                throw new Exception(string.Format("Template '{0}' contains and underscore prefixed partial name. This is no longer required. Search for the string '{{>_' or '{{> _' in your template and remove the '_'.", templateName));
                            }
                            throw;
                        }
                        writer.Write(output);
                    }
                }
            };
        }
开发者ID:JenTechSystems,项目名称:Chevron,代码行数:57,代码来源:ChevronViewEngine.cs


示例13: RenderViewSetsPath

        public void RenderViewSetsPath()
        {
            // arrange
            var templateLocator = A.Fake<IViewLocator>();
            var viewCompiler = A.Fake<IViewCompiler>();
            var viewLocationResult = new ViewLocationResult(@"c:\some\fake\path", null);
            A.CallTo(() => templateLocator.GetTemplateContents("test")).Returns(viewLocationResult);
            var engine = new RazorViewEngine(templateLocator, viewCompiler);

            // act
            var result = engine.RenderView("test", null);

            // assert
            result.Location.ShouldEqual(@"c:\some\fake\path");
        }
开发者ID:dineshkummarc,项目名称:Nancy,代码行数:15,代码来源:RazorViewEngineTest.cs


示例14: Render_should_create_valid_nhaml_IViewSource

        public void Render_should_create_valid_nhaml_IViewSource()
        {
            // Given
            var textReader = new StringReader("Hello world");
            var viewLocationResult = new ViewLocationResult("folder", "file", "haml", () => textReader);

            // When
            var template = engine.RenderView(viewLocationResult, null, this.renderContext);
            template.Contents.Invoke(new MemoryStream());

            // Then
            A.CallTo(() => nHamlEngine.GetCompiledTemplate(
                A<NancyNHamlView>.That.Matches(x => x.FilePath == @"folder\file.haml" && x.GetTextReader() == textReader),
                A<Type>.Ignored)).MustHaveHappened();
        }
开发者ID:NHaml,项目名称:Nancy.ViewEngines.NHaml,代码行数:15,代码来源:NHamlViewEngineFixture.cs


示例15: RenderView

        public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            //we already have a view but we still need a view provider
            return new HtmlResponse(contents: stream =>
                {
                    var host = new NancyParrotHost(_modelValueProviderFactory, new NancyPathResolver(renderContext));
                    var parrotWriter = host.CreateWriter();
                    var rendererFactory = host.RendererFactory;
                    var view = new ParrotView(host, rendererFactory, _parrotViewLocator, viewLocationResult.Contents, parrotWriter);
                    var writer = new StreamWriter(stream);
                    
                    view.Render(model, writer);

                    writer.Flush();
                });
        }
开发者ID:ParrotFx,项目名称:Parrot.Nancy,代码行数:16,代码来源:ParrotViewEngine.cs


示例16: DotLiquidView

        public DotLiquidView(ControllerContext controllerContext, IViewLocator locator, ViewLocationResult viewResult, ViewLocationResult masterViewResult)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException("controllerContext");
            }

            if (viewResult == null)
            {
                throw new ArgumentNullException("viewPath");
            }

            _locator = locator;
            this.ViewResult = viewResult;
            this.MasterViewResult = masterViewResult;
        }
开发者ID:alt-soft,项目名称:vc-community,代码行数:16,代码来源:DotLiquidView.cs


示例17: RenderView

        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
        /// <param name="model">The model that should be passed into the view</param>
        /// <param name="renderContext"></param>
        /// <returns>A delegate that can be invoked with the <see cref="Stream"/> that the view should be rendered to.</returns>
        public Action<Stream> RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            return stream =>{
                var provider = new TemplateManagerProvider().WithLoader(new TemplateLoader(renderContext, viewLocationResult));

                var templateManager = provider.GetNewManager();

                var context = new Dictionary<string, object> { { "Model", model } };

                var reader = templateManager.GetTemplate(viewLocationResult.Location).Walk(templateManager, context);

                var writer = new StreamWriter(stream);

                writer.Write(reader.ReadToEnd());
                writer.Flush();
            };
        }
开发者ID:jscoles,项目名称:Nancy,代码行数:24,代码来源:NDjangoViewEngine.cs


示例18: RenderViewShouldReturnCompiledView

        public void RenderViewShouldReturnCompiledView()
        {
            // arrange
            var templateLocator = A.Fake<IViewLocator>();
            var viewCompiler = A.Fake<IViewCompiler>();
            var view = A.Fake<IView>();
            var viewLocationResult = new ViewLocationResult(@"c:\some\fake\path", null);
            A.CallTo(() => templateLocator.GetTemplateContents("test")).Returns(viewLocationResult);
            A.CallTo(() => viewCompiler.GetCompiledView(null)).Returns(view);
            var engine = new RazorViewEngine(templateLocator, viewCompiler);
            var stream = new MemoryStream();

            // act
            var result = engine.RenderView("test", stream);

            // assert
            result.View.ShouldBeSameAs(view);
        }
开发者ID:dineshkummarc,项目名称:Nancy,代码行数:18,代码来源:RazorViewEngineTest.cs


示例19: RenderView

        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
        /// <param name="model">The model that should be passed into the view</param>
        /// <param name="renderContext"></param>
        /// <returns>A response</returns>
        public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            return new HtmlResponse(contents: stream =>
            {
                var provider = new TemplateManagerProvider().WithLoader(new TemplateLoader(renderContext, viewLocationResult));

                var templateManager = provider.GetNewManager();

                var context = new Dictionary<string, object> { { "Model", UnwrapDictionary(model) } };

                var reader = templateManager.GetTemplate(viewLocationResult.Location).Walk(templateManager, context);

                var writer = new StreamWriter(stream, Encoding.UTF8);

                writer.Write(reader.ReadToEnd());
                writer.Flush();
            });
        }
开发者ID:kleinron,项目名称:Nancy,代码行数:25,代码来源:NDjangoViewEngine.cs


示例20: GetCompiledView_should_render_to_stream

        public void GetCompiledView_should_render_to_stream()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                "django",
                new StringReader(@"{% ifequal a a %}<h1>Hello Mr. test</h1>{% endifequal %}")
            );

            var stream = new MemoryStream();

            // When
            var action = engine.RenderView(location, null);
            action.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Hello Mr. test</h1>");
        }
开发者ID:patrik-hagne,项目名称:Nancy,代码行数:18,代码来源:NDjangoViewCompilerFixture.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ViewMode类代码示例发布时间:2022-05-24
下一篇:
C# ViewEngineCollection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap