Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebApplication/MVC2/HeuristicLabWeb.PluginHost/HLWebPluginHost/PluginLib/PluginViewEngine.cs @ 5182

Last change on this file since 5182 was 4604, checked in by dkahn, 14 years ago

#1198 Imported new Plugin Host solution for the new MVC2 based web application

File size: 1.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using System.Diagnostics;
7
8namespace HLWebPluginHost.PluginLib {
9
10  /// <summary>
11  /// This implementation of the view engine takes view inside of plugins into account and removes the need to provide the full
12  /// path of a view from within a controller inside a view.
13  /// Use Global.asax to register this engine to the framework
14  /// </summary>
15  public class PluginViewEngine : System.Web.Mvc.WebFormViewEngine {
16    public PluginViewEngine(string[] viewLocations)
17      : base() {
18      string[] tempArray = new string[ViewLocationFormats.Length + viewLocations.Length];
19      ViewLocationFormats.CopyTo(tempArray, 0);
20
21      for (int i = 0; i < viewLocations.Length; i++) {
22
23        tempArray[ViewLocationFormats.Length + i] = viewLocations[i];
24      }
25
26      ViewLocationFormats = tempArray;
27
28      PartialViewLocationFormats = ViewLocationFormats;
29    }
30
31    private bool IsAppResourcePath(string virtualPath) {
32
33      String checkPath = VirtualPathUtility.ToAppRelative(virtualPath);
34      return checkPath.StartsWith("~/Plugins/", StringComparison.InvariantCultureIgnoreCase);
35    }
36
37    //If we have a virtual path, we need to override the super class behavior,
38    //its implementation ignores custom VirtualPathProviders, unlike the super's super class.
39    //This code basically just reimplements the super-super class (VirtualPathProviderViewEngine) behavior for virtual paths.
40    protected override bool FileExists(ControllerContext controllerContext, string virtualPath) {
41
42      if (IsAppResourcePath(virtualPath)) {
43
44        return System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists(virtualPath);
45      } else
46        return base.FileExists(controllerContext, virtualPath);
47    }
48  }
49}
Note: See TracBrowser for help on using the repository browser.