Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / WebFormViewEngine.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\r
5  * This software is subject to the Microsoft Public License (Ms-PL). \r
6  * A copy of the license can be found in the license.htm file included \r
7  * in this distribution.\r
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc {\r
14     using System.Diagnostics.CodeAnalysis;\r
15     using System.Net;\r
16     using System.Web;\r
17 \r
18     public class WebFormViewEngine : VirtualPathProviderViewEngine {\r
19 \r
20         private IBuildManager _buildManager;\r
21 \r
22         public WebFormViewEngine() {\r
23             MasterLocationFormats = new[] {\r
24                 "~/Views/{1}/{0}.master",\r
25                 "~/Views/Shared/{0}.master"\r
26             };\r
27 \r
28             AreaMasterLocationFormats = new[] {\r
29                 "~/Areas/{2}/Views/{1}/{0}.master",\r
30                 "~/Areas/{2}/Views/Shared/{0}.master",\r
31             };\r
32 \r
33             ViewLocationFormats = new[] {\r
34                 "~/Views/{1}/{0}.aspx",\r
35                 "~/Views/{1}/{0}.ascx",\r
36                 "~/Views/Shared/{0}.aspx",\r
37                 "~/Views/Shared/{0}.ascx"\r
38             };\r
39 \r
40             AreaViewLocationFormats = new[] {\r
41                 "~/Areas/{2}/Views/{1}/{0}.aspx",\r
42                 "~/Areas/{2}/Views/{1}/{0}.ascx",\r
43                 "~/Areas/{2}/Views/Shared/{0}.aspx",\r
44                 "~/Areas/{2}/Views/Shared/{0}.ascx",\r
45             };\r
46 \r
47             PartialViewLocationFormats = ViewLocationFormats;\r
48             AreaPartialViewLocationFormats = AreaViewLocationFormats;\r
49         }\r
50 \r
51         internal IBuildManager BuildManager {\r
52             get {\r
53                 if (_buildManager == null) {\r
54                     _buildManager = new BuildManagerWrapper();\r
55                 }\r
56                 return _buildManager;\r
57             }\r
58             set {\r
59                 _buildManager = value;\r
60             }\r
61         }\r
62 \r
63         protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath) {\r
64             return new WebFormView(partialPath, null);\r
65         }\r
66 \r
67         protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath) {\r
68             return new WebFormView(viewPath, masterPath);\r
69         }\r
70 \r
71         [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",\r
72             Justification = "Exceptions are interpreted as indicating that the file does not exist.")]\r
73         protected override bool FileExists(ControllerContext controllerContext, string virtualPath) {\r
74             try {\r
75                 object viewInstance = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(object));\r
76                 return viewInstance != null;\r
77             }\r
78             catch (HttpException he) {\r
79                 if (he is HttpParseException) {\r
80                     // The build manager found something, but instantiation failed due to a runtime lookup failure\r
81                     throw;\r
82                 }\r
83 \r
84                 if (he.GetHttpCode() == (int)HttpStatusCode.NotFound) {\r
85                     // If BuildManager returns a 404 (Not Found) that means that a file did not exist.\r
86                     // If the view itself doesn't exist, then this method should report that rather than throw an exception.\r
87                     if (!base.FileExists(controllerContext, virtualPath)) {\r
88                         return false;\r
89                     }\r
90                 }\r
91 \r
92                 // All other error codes imply other errors such as compilation or parsing errors\r
93                 throw;\r
94             }\r
95         }\r
96 \r
97     }\r
98 }\r