當前位置: 首頁>>代碼示例>>C#>>正文


C# Managers.RazorPage類代碼示例

本文整理匯總了C#中ServiceStack.Razor.Managers.RazorPage的典型用法代碼示例。如果您正苦於以下問題:C# RazorPage類的具體用法?C# RazorPage怎麽用?C# RazorPage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RazorPage類屬於ServiceStack.Razor.Managers命名空間,在下文中一共展示了RazorPage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的ServiceStack.Razor.Managers.RazorPage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。