本文整理汇总了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);
}
示例2: InvalidatePage
public virtual void InvalidatePage(RazorPage page)
{
if (page.IsValid || page.IsCompiling)
{
lock (page.SyncRoot)
{
page.IsValid = false;
}
}
if (Config.PrecompilePages)
PrecompilePage(page);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
}
示例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;
}
示例14: RenderToHtml
public string RenderToHtml(RazorPage razorPage, object model = null, string layout = null)
{
IRazorView razorView;
return RenderToHtml(razorPage, out razorView, model: model, layout: layout);
}
示例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;
}