Last active
December 10, 2015 02:09
Revisions
-
synhershko revised this gist
Jan 14, 2013 . 2 changed files with 19 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,8 @@ protected override NancyInternalConfiguration InternalConfiguration { get { return NancyInternalConfiguration .WithOverrides(x => x.ViewLocationProvider = typeof (RavenViewLocationProvider)) .WithIgnoredAssembly(asm => asm.FullName.StartsWith("RavenDB", StringComparison.InvariantCulture)); // or override ConfigureApplicationContainer to set AutoRegister to false } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ namespace NSemble.Core.Nancy { public class RavenViewLocationProvider : IViewLocationProvider { private readonly IViewLocationProvider defaultViewLocationProvider; @@ -24,18 +24,31 @@ public RavenViewLocationProvider(IRootPathProvider rootPathProvider, IFileSystem public IEnumerable<ViewLocationResult> GetLocatedViews(IEnumerable<string> supportedViewExtensions) { var sb = new StringBuilder(); // Make sure to only load saved views with supported extensions foreach (var s in supportedViewExtensions) { if (sb.Length > 0) sb.Append("|"); sb.Append("*."); sb.Append(s); } ViewTemplate[] views = null; using (var session = NSembleModule.DocumentStore.OpenSession()) { // It's probably safe to assume we will have no more than 1024 views, so no reason to bother with paging views = session.Advanced.LoadStartingWith<ViewTemplate>(Constants.RavenViewDocumentPrefix, sb.ToString(), 0, 1024); } // Read the views from the default location IEnumerable<ViewLocationResult> defaultViews = defaultViewLocationProvider.GetLocatedViews(supportedViewExtensions); if (views.Length == 0) return defaultViews; var ret = new HashSet<ViewLocationResult>(from v in views where supportedViewExtensions.Contains(v.Extension) select new ViewLocationResult( v.Location, v.Name, -
synhershko created this gist
Dec 23, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ protected override NancyInternalConfiguration InternalConfiguration { get { return NancyInternalConfiguration .WithOverrides(x => x.ViewLocationProvider = typeof (RavenViewLocationProvider)) .WithIgnoredAssembly(asm => asm.FullName.StartsWith("RavenDB", StringComparison.InvariantCulture)); // or override ConfigureApplicationContainer to set AutoRegister to false } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using NSemble.Core.Models; using Nancy; using Nancy.ViewEngines; namespace NSemble.Core.Nancy { public class RavenViewLocationProvider : IViewLocationProvider { private readonly IViewLocationProvider defaultViewLocationProvider; public RavenViewLocationProvider(IRootPathProvider rootPathProvider) { defaultViewLocationProvider = new FileSystemViewLocationProvider(rootPathProvider); } public RavenViewLocationProvider(IRootPathProvider rootPathProvider, IFileSystemReader fileSystemReader) { defaultViewLocationProvider = new FileSystemViewLocationProvider(rootPathProvider, fileSystemReader); } public IEnumerable<ViewLocationResult> GetLocatedViews(IEnumerable<string> supportedViewExtensions) { ViewTemplate[] views = null; using (var session = NSembleModule.DocumentStore.OpenSession()) { views = session.Advanced.LoadStartingWith<ViewTemplate>(Constants.RavenViewDocumentPrefix, null, 0, 1024); } IEnumerable<ViewLocationResult> defaultViews = defaultViewLocationProvider.GetLocatedViews(supportedViewExtensions); if (views.Length == 0) return defaultViews; var ret = new HashSet<ViewLocationResult>(from v in views where supportedViewExtensions.Contains(v.Extension) select new ViewLocationResult( v.Location, v.Name, v.Extension, () => new StringReader(v.Contents))); foreach (var v in defaultViews) ret.Add(v); return ret; } } }