Permalink
Browse files

Refactored VirtualPath provider, moved to .NET 3.5 ServiceStack.dll t…

…o share with Markdown View Engine as well.

Added View/Template on HttpResult to change the view/template displayed at runtime.
  • Loading branch information...
1 parent b4c9b48 commit 5f3b77b6315ac3cd4f1dc0715b1f37ddb1d11f79 @mythz mythz committed Aug 20, 2012
Showing with 1,538 additions and 301 deletions.
  1. +15 −0 lib/ServiceStack.Text.XML
  2. BIN lib/ServiceStack.Text.dll
  3. +31 −0 src/ServiceStack.Common/RequestContextExtensions.cs
  4. +1 −0 src/ServiceStack.Common/ServiceStack.Common.csproj
  5. +0 −2 src/ServiceStack.Common/Web/CompressedResult.cs
  6. +0 −3 src/ServiceStack.Common/Web/HttpError.cs
  7. +14 −10 src/ServiceStack.Common/Web/HttpResult.cs
  8. +0 −5 src/ServiceStack.Interfaces/ServiceHost/IHttpResult.cs
  9. +13 −12 ...eStack.Razor/{ServiceStack/ServiceStackCSharpRazorBuildProvider.cs → CSharpRazorBuildProvider.cs}
  10. +42 −50 src/ServiceStack.Razor/RazorFormat.cs
  11. +1 −16 src/ServiceStack.Razor/ServiceStack.Razor.csproj
  12. +1 −1 src/ServiceStack.Razor/Templating/TemplateService.ServiceStack.cs
  13. +1 −1 src/ServiceStack.ServiceInterface/ServiceBase.cs
  14. +15 −0 src/ServiceStack/ServiceStack.csproj
  15. +148 −0 src/ServiceStack/VirtualPath/AbstractVirtualDirectoryBase.cs
  16. +92 −0 src/ServiceStack/VirtualPath/AbstractVirtualFileBase.cs
  17. +81 −0 src/ServiceStack/VirtualPath/AbstractVirtualPathProviderBase.cs
  18. +101 −0 src/ServiceStack/VirtualPath/FileSystemVirtualDirectory.cs
  19. +44 −0 src/ServiceStack/VirtualPath/FileSystemVirtualFile.cs
  20. +50 −0 src/ServiceStack/VirtualPath/FileSystemVirtualPathProvider.cs
  21. +20 −0 src/ServiceStack/VirtualPath/IVirtualDirectory.cs
  22. +15 −0 src/ServiceStack/VirtualPath/IVirtualFile.cs
  23. +14 −0 src/ServiceStack/VirtualPath/IVirtualNode.cs
  24. +30 −0 src/ServiceStack/VirtualPath/IVirtualPathProvider.cs
  25. +66 −0 src/ServiceStack/VirtualPath/MultiVirtualPathProvider.cs
  26. +144 −0 src/ServiceStack/VirtualPath/ResourceVirtualDirectory.cs
  27. +64 −0 src/ServiceStack/VirtualPath/ResourceVirtualFile.cs
  28. +53 −0 src/ServiceStack/VirtualPath/ResourceVirtualPathProvider.cs
  29. +44 −0 src/ServiceStack/VirtualPath/VirtualPathExtension.cs
  30. +46 −9 src/ServiceStack/WebHost.EndPoints/EndpointHostConfig.cs
  31. +41 −1 src/ServiceStack/WebHost.EndPoints/Extensions/HttpRequestExtensions.cs
  32. +115 −55 src/ServiceStack/WebHost.EndPoints/Formats/MarkdownFormat.cs
  33. +70 −24 src/ServiceStack/WebHost.EndPoints/Support/Markdown/Evaluator.cs
  34. +23 −5 src/ServiceStack/WebHost.EndPoints/Support/Markdown/MarkdownPage.cs
  35. +9 −6 src/ServiceStack/WebHost.EndPoints/Support/Markdown/TemplateExtensions.cs
  36. +3 −2 src/ServiceStack/WebHost.EndPoints/Support/Markdown/TextBlock.cs
  37. +15 −4 tests/RazorRockstars.Console/AppHost.cs
  38. +30 −29 tests/RazorRockstars.Console/NoModelNoController.cshtml
  39. +13 −1 tests/RazorRockstars.Console/RazorRockstars.Console.csproj
  40. +29 −27 tests/RazorRockstars.Console/TypedModelNoController.cshtml
  41. +1 −1 tests/RazorRockstars.Console/Views/Shared/HtmlReport.cshtml
  42. +39 −33 tests/RazorRockstars.Console/Views/Shared/SimpleLayout.cshtml
  43. +1 −1 tests/ServiceStack.RazorHostTests/Global.asax.cs
  44. +2 −2 tests/ServiceStack.RazorHostTests/ServiceStack.RazorHostTests.csproj
  45. +1 −1 tests/ServiceStack.RazorHostTests/Web.config
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
Binary file not shown.
@@ -0,0 +1,31 @@
+using ServiceStack.ServiceHost;
+
+namespace ServiceStack.Common
+{
+ public static class RequestContextExtensions
+ {
+ /// <summary>
+ /// Store an entry in the IHttpRequest.Items Dictionary
+ /// </summary>
+ public static void SetItem(this IRequestContext requestContext, string key, object value)
+ {
+ if (requestContext == null) return;
+ var httpReq = requestContext.Get<IHttpRequest>();
+ if (httpReq != null)
+ httpReq.Items[key] = value;
+ }
+
+ /// <summary>
+ /// Get an entry from the IHttpRequest.Items Dictionary
+ /// </summary>
+ public static object GetItem(this IRequestContext requestContext, string key)
+ {
+ if (requestContext == null) return null;
+ object value = null;
+ var httpReq = requestContext.Get<IHttpRequest>();
+ if (httpReq != null)
+ httpReq.Items.TryGetValue(key, out value);
+ return value;
+ }
+ }
+}
@@ -457,6 +457,7 @@
<Compile Include="Web\MimeTypes.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="RequestContextExtensions.cs" />
<Compile Include="Web\SerializationContext.cs">
<SubType>Code</SubType>
</Compile>
@@ -30,8 +30,6 @@ public object Response
set { throw new NotImplementedException(); }
}
- public string TemplateName { get; set; }
-
public IContentTypeWriter ResponseFilter { get; set; }
public IRequestContext RequestContext { get; set; }
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net;
-using ServiceStack.Common.Utils;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface.ServiceModel;
@@ -59,8 +58,6 @@ public HttpError(string message, Exception innerException) : base(message, inner
public object Response { get; set; }
- public string TemplateName { get; set; }
-
public IContentTypeWriter ResponseFilter { get; set; }
public IRequestContext RequestContext { get; set; }
@@ -1,4 +1,4 @@
-#if !SILVERLIGHT
+#if !SILVERLIGHT
using System;
using System.Collections.Generic;
using System.IO;
@@ -35,7 +35,7 @@ public HttpResult(HttpStatusCode statusCode, string statusDescription)
}
public HttpResult(object response, HttpStatusCode statusCode)
- : this(response, null, statusCode) {}
+ : this(response, null, statusCode) { }
public HttpResult(object response, string contentType, HttpStatusCode statusCode)
{
@@ -64,7 +64,7 @@ public HttpResult(FileInfo fileResponse, bool asAttachment, string contentType)
"attachment; " +
"filename=\"" + fileResponse.Name + "\"; " +
"size=" + fileResponse.Length + "; " +
- "creation-date=" + fileResponse.CreationTimeUtc.ToString("R").Replace(",","") + "; " +
+ "creation-date=" + fileResponse.CreationTimeUtc.ToString("R").Replace(",", "") + "; " +
"modification-date=" + fileResponse.LastWriteTimeUtc.ToString("R").Replace(",", "") + "; " +
"read-date=" + fileResponse.LastAccessTimeUtc.ToString("R").Replace(",", "");
@@ -109,7 +109,7 @@ public string Location
{
if (StatusCode == HttpStatusCode.OK)
StatusCode = HttpStatusCode.Redirect;
-
+
this.Headers[HttpHeaders.Location] = value;
}
}
@@ -151,7 +151,7 @@ public void SetCookie(string name, string value, DateTime expiresAt, string path
public void DeleteCookie(string name)
{
var cookie = string.Format("{0}=;expires={1};path=/", name, DateTime.UtcNow.AddDays(-1).ToString("R"));
- this.Headers[HttpHeaders.SetCookie] = cookie;
+ this.Headers[HttpHeaders.SetCookie] = cookie;
}
public IDictionary<string, string> Options
@@ -169,7 +169,9 @@ public void DeleteCookie(string name)
public IRequestContext RequestContext { get; set; }
- public string TemplateName { get; set; }
+ public string View { get; set; }
+
+ public string Template { get; set; }
public void WriteTo(Stream responseStream)
{
@@ -216,22 +218,24 @@ public void WriteTo(Stream responseStream)
return;
}
+ if (View != null)
+ RequestContext.SetItem("View", View);
+ if (Template != null)
+ RequestContext.SetItem("Template", Template);
+
ResponseFilter.SerializeToStream(this.RequestContext, this.Response, responseStream);
}
public static HttpResult Status201Created(object response, string newLocationUri)
{
- return new HttpResult(response)
- {
+ return new HttpResult(response) {
StatusCode = HttpStatusCode.Created,
Headers =
{
{ HttpHeaders.Location, newLocationUri },
}
};
}
-
-
}
}
#endif
@@ -31,11 +31,6 @@ public interface IHttpResult : IHasOptions
object Response { get; set; }
/// <summary>
- /// A specific template, if not the default (for HTML, Markdown, etc. ContentTypes)
- /// </summary>
- string TemplateName { get; set; }
-
- /// <summary>
/// if not provided, get's injected by ServiceStack
/// </summary>
IContentTypeWriter ResponseFilter { get; set; }
@@ -1,15 +1,16 @@
//Orignally from: https://github.com/NancyFx/Nancy/blob/master/src/Nancy.ViewEngines.Razor.BuildProviders/NancyCSharpRazorBuildProvider.cs
-namespace ServiceStack.Razor.ServiceStack
-{
- using System;
- using System.CodeDom;
- using System.CodeDom.Compiler;
- using System.Globalization;
- using System.Web.Compilation;
- using System.Web.Razor;
- [BuildProviderAppliesTo(BuildProviderAppliesTo.Code | BuildProviderAppliesTo.Web)]
- public class ServiceStackCSharpRazorBuildProvider : BuildProvider
+using System;
+using System.CodeDom;
+using System.CodeDom.Compiler;
+using System.Globalization;
+using System.Web.Compilation;
+using System.Web.Razor;
+
+namespace ServiceStack.Razor
+{
+ [BuildProviderAppliesTo(BuildProviderAppliesTo.Code | BuildProviderAppliesTo.Web)]
+ public class CSharpRazorBuildProvider : BuildProvider
{
private readonly RazorEngineHost host;
@@ -18,9 +19,9 @@ public class ServiceStackCSharpRazorBuildProvider : BuildProvider
private CodeCompileUnit generatedCode;
/// <summary>
- /// Initializes a new instance of the <see cref="ServiceStackCSharpRazorBuildProvider"/> class.
+ /// Initializes a new instance of the <see cref="CSharpRazorBuildProvider"/> class.
/// </summary>
- public ServiceStackCSharpRazorBuildProvider()
+ public CSharpRazorBuildProvider()
{
this.compilerType = this.GetDefaultCompilerTypeForLanguage("C#");
Oops, something went wrong.

0 comments on commit 5f3b77b

Please sign in to comment.