/// <summary> /// Gets the source of the requested view. /// </summary> /// <param name="path">The view to get the source for</param> /// <returns>A <see cref="IViewFile"/> instance.</returns> public IViewFile GetViewSource(string path) { var searchPath = ConvertPath(path); IViewFile fileResult; if (this.cachedFiles.TryGetValue(searchPath, out fileResult)) { return(fileResult); } ViewLocationResult result = null; this.padlock.EnterUpgradeableReadLock(); try { result = this.currentlyLocatedViews .FirstOrDefault(v => CompareViewPaths(GetSafeViewPath(v), searchPath)); if (result == null && this.configuration.RuntimeViewDiscovery) { result = this.viewEngineStartupContext.ViewLocator.LocateView(searchPath, GetFakeContext()); this.padlock.EnterWriteLock(); try { this.currentlyLocatedViews.Add(result); } finally { this.padlock.ExitWriteLock(); } } } finally { this.padlock.ExitUpgradeableReadLock(); } if (result == null) { throw new FileNotFoundException(string.Format("Template {0} not found", path), path); } fileResult = new NancyViewFile(result, this.configuration); this.cachedFiles.AddOrUpdate(searchPath, s => fileResult, (s, o) => fileResult); return(fileResult); }
/// <summary> /// Gets the source of the requested view. /// </summary> /// <param name="path">The view to get the source for</param> /// <returns>A <see cref="IViewFile"/> instance.</returns> public IViewFile GetViewSource(string path) { var searchPath = ConvertPath(path); IViewFile fileResult; if (this.cachedFiles.TryGetValue(searchPath, out fileResult)) { return fileResult; } ViewLocationResult result = null; this.padlock.EnterUpgradeableReadLock(); try { result = this.currentlyLocatedViews .FirstOrDefault(v => CompareViewPaths(GetSafeViewPath(v), searchPath)); if (result == null && StaticConfiguration.Caching.EnableRuntimeViewDiscovery) { result = this.viewEngineStartupContext.ViewLocator.LocateView(searchPath, GetFakeContext()); this.padlock.EnterWriteLock(); try { this.currentlyLocatedViews.Add(result); } finally { this.padlock.ExitWriteLock(); } } } finally { this.padlock.ExitUpgradeableReadLock(); } if (result == null) { throw new FileNotFoundException(string.Format("Template {0} not found", path), path); } fileResult = new NancyViewFile(result); this.cachedFiles.AddOrUpdate(searchPath, s => fileResult, (s, o) => fileResult); return fileResult; }