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

C# Managers.RazorPage类代码示例

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

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



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

示例1: InvalidatePage

        public virtual void InvalidatePage(RazorPage page, bool compile = true)
        {
            if (page.IsValid || page.IsCompiling)
            {
                lock (page.SyncRoot)
                {
                    page.IsValid = false;
                }
            }

            if (compile)
                PrecompilePage(page);
        }
开发者ID:tystol,项目名称:ServiceStack,代码行数:13,代码来源:RazorViewManager.cs


示例2: InvalidatePage

        public virtual void InvalidatePage(RazorPage page)
        {
            if (page.IsValid || page.IsCompiling)
            {
                lock (page.SyncRoot)
                {
                    page.IsValid = false;
                }
            }

            if (Config.PrecompilePages)
                PrecompilePage(page);
        }
开发者ID:CITnDev,项目名称:ServiceStack,代码行数:13,代码来源:RazorViewManager.cs


示例3: TrackPage

        public virtual RazorPage TrackPage(IVirtualFile file)
        {
            //get the base type.
            var pageBaseType = this.Config.PageBaseType;

            var transformer = new RazorViewPageTransformer(pageBaseType);

            //create a RazorPage
            var page = new RazorPage
            {
                PageHost = new RazorPageHost(PathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>()),
                IsValid = false,
                File = file
            };

            //add it to our pages dictionary.
            AddPage(page);
            
            return page;
        }
开发者ID:nustack,项目名称:ServiceStack,代码行数:20,代码来源:RazorViewManager.cs


示例4: AddPage

        protected virtual RazorPage AddPage(RazorPage page)
        {
            var pagePath = GetDictionaryPagePath(page.PageHost.File);

            this.Pages[pagePath] = page;

            //Views should be uniquely named and stored in any deep folder structure
            if (pagePath.StartsWithIgnoreCase("/views/"))
            {
                var viewName = pagePath.SplitOnLast('.').First().SplitOnLast('/').Last();
                ViewNamesMap[viewName] = pagePath;
            }

            return page;
        }
开发者ID:tystol,项目名称:ServiceStack,代码行数:15,代码来源:RazorViewManager.cs


示例5: CreateRazorPageInstance

        private IRazorView CreateRazorPageInstance(IHttpRequest httpReq, IHttpResponse httpRes, object dto, RazorPage razorPage)
        {
            EnsureCompiled(razorPage, httpRes);

            //don't proceed any further, the background compiler found there was a problem compiling the page, so throw instead
            if (razorPage.CompileException != null)
            {
                throw razorPage.CompileException;
            }

            //else, EnsureCompiled() ensures we have a page type to work with so, create an instance of the page
            var page = (IRazorView) razorPage.ActivateInstance();

            page.Init(viewEngine: this, httpReq: httpReq, httpRes: httpRes);

            //deserialize the model.
            PrepareAndSetModel(page, httpReq, dto);
        
            return page;
        }
开发者ID:yeurch,项目名称:ServiceStack,代码行数:20,代码来源:RazorPageResolver.cs


示例6: EnsureCompiled

        public void EnsureCompiled(RazorPage page, IHttpResponse response)
        {
            if (page == null) return;
            if (page.IsValid) return;

            var type = page.PageHost.Compile();

            page.PageType = type;

            page.IsValid = true;
        }
开发者ID:yeurch,项目名称:ServiceStack,代码行数:11,代码来源:RazorPageResolver.cs


示例7: PrecompilePage

        protected virtual Task<RazorPage> PrecompilePage(RazorPage page)
        {
            page.MarkedForCompilation = true;

            var task = Task.Factory.StartNew(() =>
            {
                try
                {
                    EnsureCompiled(page);

                    if (page.CompileException != null)
                        Log.ErrorFormat("Precompilation of Razor page '{0}' failed: {1}", page.File.Name, page.CompileException.Message);
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Precompilation of Razor page '{0}' failed: {1}", page.File.Name, ex.Message);
                }
                return page;
            });

            if (startupPrecompilationTasks != null)
                startupPrecompilationTasks.Add(task);

            return task;
        }
开发者ID:Girishdhote,项目名称:ServiceStack,代码行数:25,代码来源:RazorViewManager.cs


示例8: AddPage

        protected virtual RazorPage AddPage(RazorPage page, string pagePath = null)
        {
            pagePath = pagePath != null
                ? GetDictionaryPagePath(pagePath)
                : GetDictionaryPagePath(page.PageHost.File);

            Pages[pagePath] = page;

            //Views should be uniquely named and stored in any deep folder structure
            if (pagePath.StartsWithIgnoreCase("views/") && !pagePath.EndsWithIgnoreCase(DefaultLayoutFile))
            {
                var viewName = pagePath.SplitOnLast('.').First().SplitOnLast('/').Last();
                ViewNamesMap[viewName] = pagePath;
            }

            return page;
        }
开发者ID:Girishdhote,项目名称:ServiceStack,代码行数:17,代码来源:RazorViewManager.cs


示例9: TrackPage

        public virtual RazorPage TrackPage(IVirtualFile file)
        {
            //get the base type.
            var pageBaseType = this.Config.PageBaseType;

            var transformer = new RazorViewPageTransformer(pageBaseType);

            //create a RazorPage
            var page = new RazorPage
            {
                PageHost = CreatePageHost(file, transformer),
                IsValid = false,
                File = file,
                VirtualPath = file.VirtualPath,
            };

            //add it to our pages dictionary.
            AddPage(page);

            if (Config.PrecompilePages.GetValueOrDefault())
                PrecompilePage(page);

            return page;
        }
开发者ID:Girishdhote,项目名称:ServiceStack,代码行数:24,代码来源:RazorViewManager.cs


示例10: CreateRazorPageInstance

        private IRazorView CreateRazorPageInstance(IRequest httpReq, IResponse httpRes, object dto, RazorPage razorPage)
        {
            viewManager.EnsureCompiled(razorPage);

            //don't proceed any further, the background compiler found there was a problem compiling the page, so throw instead
            if (razorPage.CompileException != null)
            {
                if (Text.Env.IsMono)
                {
                    //Additional debug info Working around not displaying default exception in IHttpAsyncHandler
                    var errors = razorPage.CompileException.Results.Errors;
                    for (var i = 0; i < errors.Count; i++)
                    {
                        var error = errors[i];
                        Log.Debug("{0} Line: {1}:{2}:".Fmt(error.FileName, error.Line, error.Column));
                        Log.Debug("{0}: {1}".Fmt(error.ErrorNumber, error.ErrorText));
                    }
                } 
                throw razorPage.CompileException;
            }

            //else, EnsureCompiled() ensures we have a page type to work with so, create an instance of the page
            var page = (IRazorView)razorPage.ActivateInstance();

            page.Init(viewEngine: this, httpReq: httpReq, httpRes: httpRes);

            //deserialize the model.
            PrepareAndSetModel(page, httpReq, dto);

            return page;
        }
开发者ID:BilliamBrown,项目名称:ServiceStack,代码行数:31,代码来源:RazorPageResolver.cs


示例11: ExecuteRazorPageWithLayout

        private Tuple<IRazorView, string> ExecuteRazorPageWithLayout(RazorPage razorPage, IRequest httpReq, IResponse httpRes, object model, IRazorView pageInstance, Func<string> layout)
        {
            using (var ms = new MemoryStream())
            {
                using (var childWriter = new StreamWriter(ms, UTF8EncodingWithoutBom))
                {
                    //child page needs to execute before master template to populate ViewBags, sections, etc
                    try
                    {
                        pageInstance.WriteTo(childWriter);
                    }
                    catch (StopExecutionException ignore) {}

                    if (httpRes.IsClosed)
                        return null;

                    var childBody = ms.ToArray().FromUtf8Bytes();

                    var layoutName = layout();
                    if (!string.IsNullOrEmpty(layoutName))
                    {
                        var layoutPage = viewManager.GetLayoutPage(layoutName, razorPage, httpReq, model);
                        if (layoutPage != null)
                        {
                            var layoutView = CreateRazorPageInstance(httpReq, httpRes, model, layoutPage);
                            layoutView.SetChildPage(pageInstance, childBody);
                            return ExecuteRazorPageWithLayout(layoutPage, httpReq, httpRes, model, layoutView, () => layoutView.Layout);
                        }
                    }

                    return Tuple.Create(pageInstance, childBody);
                }
            }
        }
开发者ID:BilliamBrown,项目名称:ServiceStack,代码行数:34,代码来源:RazorPageResolver.cs


示例12: ResolveAndExecuteRazorPage

        public IRazorView ResolveAndExecuteRazorPage(IHttpRequest httpReq, IHttpResponse httpRes, object model, RazorPage razorPage=null)
        {
            var viewName = httpReq.GetItem(ViewKey) as string;
            if (razorPage == null && viewName != null)
            {
                razorPage = this.viewManager.GetPageByName(viewName);
            }
            else
            {
                razorPage = razorPage
                    ?? this.viewManager.GetPageByName(httpReq.OperationName) //Request DTO
                    ?? this.viewManager.GetPage(httpReq, model);  // Response DTO
            }

            if (razorPage == null)
            {
                httpRes.StatusCode = (int)HttpStatusCode.NotFound;
                return null;
            }
            
            using (var writer = new StreamWriter(httpRes.OutputStream, UTF8EncodingWithoutBom))
            {
                var page = CreateRazorPageInstance(httpReq, httpRes, model, razorPage);

                var includeLayout = !(httpReq.GetParam(QueryStringFormatKey) ?? "").Contains(NoTemplateFormatValue);
                if (includeLayout)
                {
                    using (var ms = new MemoryStream())
                    using (var childWriter = new StreamWriter(ms, UTF8EncodingWithoutBom))
                    {
                        //child page needs to execute before master template to populate ViewBags, sections, etc
                        page.WriteTo(childWriter);

                        var layout = httpReq.GetItem(LayoutKey) as string
                            ?? page.Layout
                            ?? DefaultLayoutName;

                        var childBody = ms.ToArray().FromUtf8Bytes();
                        var layoutPage = this.viewManager.GetPageByName(layout, httpReq, model);
                        if (layoutPage != null)
                        {
                            var layoutView = CreateRazorPageInstance(httpReq, httpRes, model, layoutPage);

                            layoutView.SetChildPage(page, childBody);
                            layoutView.WriteTo(writer);
                            return layoutView;
                        }

                        writer.Write(childBody);
                        return page;
                    }
                }

                page.WriteTo(writer);
                return page;
            }
        }
开发者ID:manuelnelson,项目名称:ServiceStack,代码行数:57,代码来源:RazorPageResolver.cs


示例13: TrackPage

        public virtual RazorPage TrackPage(Type pageType)
        {
            var pageBaseType = this.Config.PageBaseType;
            var transformer = new RazorViewPageTransformer(pageBaseType);

            var pagePath = pageType.FirstAttribute<VirtualPathAttribute>().VirtualPath.TrimStart('~');
            var file = GetVirtualFile(pagePath);
            
            var page = new RazorPage
            {
                PageHost = file != null ? new RazorPageHost(PathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>()) : null,
                PageType = pageType,
                IsValid = true,
                File = file,
                VirtualPath = pagePath,
            };

            AddPage(page, pagePath);
            return page;
        }
开发者ID:BilliamBrown,项目名称:ServiceStack,代码行数:20,代码来源:RazorViewManager.cs


示例14: RenderToHtml

 public string RenderToHtml(RazorPage razorPage, object model = null, string layout = null)
 {
     IRazorView razorView;
     return RenderToHtml(razorPage, out razorView, model: model, layout: layout);
 }
开发者ID:0815sugo,项目名称:ServiceStack,代码行数:5,代码来源:RazorFormat.cs


示例15: TrackPage

 public virtual RazorPage TrackPage(Type pageType)
 {
     var pagePath = pageType.FirstAttribute<VirtualPathAttribute>().VirtualPath.TrimStart('~');
     var page = new RazorPage { PageType = pageType, IsValid = true };
     
     AddPage(page, pagePath);
     return page;
 }
开发者ID:Tyst,项目名称:ServiceStack,代码行数:8,代码来源:RazorViewManager.cs


示例16: EnsureCompiled

        public virtual void EnsureCompiled(RazorPage page)
        {
            if (page == null) return;
            if (page.IsValid) return;

            lock (page.SyncRoot)
            {
                if (page.IsValid) return;

                var compileTimer = System.Diagnostics.Stopwatch.StartNew();
                try
                {
                    page.IsCompiling = true;
                    page.CompileException = null;

                    var type = page.PageHost.Compile();

                    page.PageType = type;

                    page.IsValid = true;

                    compileTimer.Stop();
                    Log.DebugFormat("Compiled Razor page '{0}' in {1}ms.", page.File.Name, compileTimer.ElapsedMilliseconds);
                }
                catch (HttpCompileException ex)
                {
                    page.CompileException = ex;
                }
                finally
                {
                    page.IsCompiling = false;
                    page.MarkedForCompilation = false;
                }
            }
        }
开发者ID:tystol,项目名称:ServiceStack,代码行数:35,代码来源:RazorViewManager.cs


示例17: ProcessRazorPage

 public void ProcessRazorPage(IRequest httpReq, RazorPage contentPage, object model, IResponse httpRes)
 {
     PageResolver.ExecuteRazorPage(httpReq, httpRes, model, contentPage);
 }
开发者ID:jin29neci,项目名称:ServiceStack,代码行数:4,代码来源:RazorFormat.cs


示例18: RenderToHtml

 public string RenderToHtml(RazorPage razorPage, object model = null, string layout = null)
 {
     IRazorView razorView;
     var result = RenderToHtml(razorPage, out razorView, model: model, layout: layout);
     using (razorView)
     {
         return result;
     }
 }
开发者ID:jin29neci,项目名称:ServiceStack,代码行数:9,代码来源:RazorFormat.cs


示例19: GetLayoutPage

        public virtual RazorPage GetLayoutPage(string layoutName, RazorPage page, IRequest request, object dto)
        {
            var layoutFile = Path.ChangeExtension(layoutName, Config.RazorFileExtension);
            // layoutName may or may not contain the .cshtml extension, the below forces it not to.
            layoutName = Path.GetFileNameWithoutExtension(layoutFile);

            var contextRelativePath = page.VirtualPath;
            string contextParentDir = contextRelativePath;
            do
            {
                contextParentDir = (contextParentDir ?? "").SplitOnLast('/').First();

                var path = CombinePaths(contextParentDir, layoutFile);
                var layoutPage = GetPage(path);
                if (layoutPage != null)
                    return layoutPage;

            } while (!string.IsNullOrEmpty(contextParentDir) && contextParentDir.Contains('/'));

            if (layoutName != RazorPageResolver.DefaultLayoutName)
                return GetViewPage(layoutName);

            return GetPage(CombinePaths("/views/shared/", layoutFile))
                   ?? GetPage(CombinePaths("/views/", layoutFile)); //backwards compatibility fallback
        }
开发者ID:Girishdhote,项目名称:ServiceStack,代码行数:25,代码来源:RazorViewManager.cs


示例20: ResolveAndExecuteRazorPage

        public IRazorView ResolveAndExecuteRazorPage(IHttpRequest httpReq, IHttpResponse httpRes, object model, RazorPage razorPage=null)
        {
            razorPage = razorPage ?? FindRazorPage(httpReq, model);

            if (razorPage == null)
            {
                httpRes.StatusCode = (int)HttpStatusCode.NotFound;
                return null;
            }

            using (var writer = new StreamWriter(httpRes.OutputStream, UTF8EncodingWithoutBom))
            {
                var page = CreateRazorPageInstance(httpReq, httpRes, model, razorPage);

                var includeLayout = !(httpReq.GetParam(QueryStringFormatKey) ?? "").Contains(NoTemplateFormatValue);
                if (includeLayout)
                {
                    var result = ExecuteRazorPageWithLayout(httpReq, httpRes, model, page, () =>
                    {
                        return httpReq.GetItem(LayoutKey) as string
                                       ?? page.Layout
                                       ?? DefaultLayoutName;
                    });

                    writer.Write(result.Item2);
                    return result.Item1;
                }

                page.WriteTo(writer);
                return page;
            }
        }
开发者ID:yeurch,项目名称:ServiceStack,代码行数:32,代码来源:RazorPageResolver.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Redis.PooledRedisClientManager类代码示例发布时间:2022-05-26
下一篇:
C# Expression.TestType类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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