Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / class / System.Web.Mvc / 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             ViewLocationFormats = new[] {\r
29                 "~/Views/{1}/{0}.aspx",\r
30                 "~/Views/{1}/{0}.ascx",\r
31                 "~/Views/Shared/{0}.aspx",\r
32                 "~/Views/Shared/{0}.ascx"\r
33             };\r
34 \r
35             PartialViewLocationFormats = ViewLocationFormats;\r
36         }\r
37 \r
38         internal IBuildManager BuildManager {\r
39             get {\r
40                 if (_buildManager == null) {\r
41                     _buildManager = new BuildManagerWrapper();\r
42                 }\r
43                 return _buildManager;\r
44             }\r
45             set {\r
46                 _buildManager = value;\r
47             }\r
48         }\r
49 \r
50         protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath) {\r
51             return new WebFormView(partialPath, null);\r
52         }\r
53 \r
54         protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath) {\r
55             return new WebFormView(viewPath, masterPath);\r
56         }\r
57 \r
58         [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",\r
59             Justification = "Exceptions are interpreted as indicating that the file does not exist.")]\r
60         protected override bool FileExists(ControllerContext controllerContext, string virtualPath) {\r
61             try {\r
62                 object viewInstance = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(object));\r
63 \r
64                 return viewInstance != null;\r
65             }\r
66             catch (HttpException he) {\r
67                 if (he.GetHttpCode() == (int)HttpStatusCode.NotFound) {\r
68                     // If BuildManager returns a 404 (Not Found) that means the file did not exist\r
69                     return false;\r
70                 }\r
71                 else {\r
72                     // All other error codes imply other errors such as compilation or parsing errors\r
73                     throw;\r
74                 }\r
75             }\r
76             catch {\r
77                 return false;\r
78             }\r
79         }\r
80     }\r
81 }\r