2009-02-18 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Wed, 18 Feb 2009 23:49:33 +0000 (23:49 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Wed, 18 Feb 2009 23:49:33 +0000 (23:49 -0000)
* System.Web/HttpApplicationFactory.cs: check of global.asax was precompiled.
* System.Web.UI/MasterPage.cs: the items in ContentPlaceHolders are lowercase.
* System.Web.Compilation/TemplateControlCompiler.cs: lowercase place holder names
* System.Web.Compilation/BuildManager.cs: initial support for
precompilation. No 'updatable', please.

svn path=/trunk/mcs/; revision=127352

mcs/class/System.Web/System.Web.Compilation/BuildManager.cs
mcs/class/System.Web/System.Web.Compilation/ChangeLog
mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs
mcs/class/System.Web/System.Web.UI/ChangeLog
mcs/class/System.Web/System.Web.UI/MasterPage.cs
mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/HttpApplicationFactory.cs

index df24ecd233de07e5dbb8266091804167c83c6670..be133683135a477c985342023a69bb6eee47eaf9 100644 (file)
@@ -43,6 +43,7 @@ using System.IO;
 using System.Reflection;
 using System.Text;
 using System.Threading;
+using System.Xml;
 using System.Web;
 using System.Web.Caching;
 using System.Web.Configuration;
@@ -74,6 +75,8 @@ namespace System.Web.Compilation {
                static List <Assembly> referencedAssemblies;
 
                static int buildCount;
+               static bool is_precompiled;
+               static Dictionary<string, PreCompilationData> precompiled;
                
                // This is here _only_ for the purpose of unit tests!
                internal static bool suppressDebugModeMessages;
@@ -139,9 +142,64 @@ namespace System.Web.Compilation {
 #endif
                        referencedAssemblies = new List <Assembly> ();
                        recursionDepth = 0;
+
+                       is_precompiled = File.Exists (Path.Combine (HttpRuntime.AppDomainAppPath, "PrecompiledApp.config"));
+                       if (is_precompiled) {
+                               LoadPrecompilationInfo ();
+                       }
                        LoadVirtualPathsToIgnore ();
                }
 
+               static void LoadPrecompilationInfo ()
+               {
+                       string [] compiled = Directory.GetFiles (HttpRuntime.BinDirectory, "*.compiled");
+                       foreach (string str in compiled) {
+                               LoadCompiled (str);
+                       }
+               }
+
+               static void LoadCompiled (string filename)
+               {
+                       using (XmlTextReader reader = new XmlTextReader (filename)) {
+                               reader.MoveToContent ();
+                               if (reader.Name == "preserve" && reader.HasAttributes) {
+                                       reader.MoveToNextAttribute ();
+                                       string val = reader.Value;
+                                       // 2 -> ashx
+                                       // 3 -> ascx, aspx
+                                       // 6 -> app_code - nothing to do here
+                                       // 8 -> global.asax
+                                       if (reader.Name == "resultType" && (val == "2" || val == "3" || val == "8"))
+                                               LoadPageData (reader);
+                               }
+                       }
+               }
+
+               class PreCompilationData {
+                       public string VirtualPath;
+                       public string AssemblyFileName;
+                       public string TypeName;
+                       public Type Type;
+               }
+
+               static void LoadPageData (XmlTextReader reader)
+               {
+                       PreCompilationData pc_data = new PreCompilationData ();
+
+                       while (reader.MoveToNextAttribute ()) {
+                               string name = reader.Name;
+                               if (name == "virtualPath")
+                                       pc_data.VirtualPath = reader.Value;
+                               else if (name == "assembly")
+                                       pc_data.AssemblyFileName = reader.Value;
+                               else if (name == "type")
+                                       pc_data.TypeName = reader.Value;
+                       }
+                       if (precompiled == null)
+                               precompiled = new Dictionary<string, PreCompilationData> (comparer);
+                       precompiled.Add (pc_data.VirtualPath, pc_data);
+               }
+
                static void AddAssembly (Assembly asm, List <Assembly> al)
                {
                        if (al.Contains (asm))
@@ -577,14 +635,43 @@ namespace System.Web.Compilation {
                        return codeDomProviderType;
                }
 
+               static Type GetPrecompiledType (string virtualPath)
+               {
+                       PreCompilationData pc_data;
+                       if (precompiled.TryGetValue (virtualPath, out pc_data)) {
+                               if (pc_data.Type == null) {
+                                       pc_data.Type = Type.GetType (pc_data.TypeName + ", " + pc_data.AssemblyFileName, true);
+                               }
+                               return pc_data.Type;
+                       }
+                       //Console.WriteLine ("VPath not precompiled: {0}", virtualPath);
+                       return null;
+               }
+
+               internal static Type GetPrecompiledApplicationType ()
+               {
+                       if (!is_precompiled)
+                               return null;
+
+                       Type apptype = GetPrecompiledType (HttpRuntime.AppDomainAppVirtualPath + "/Global.asax");
+                       if (apptype == null)
+                               apptype = GetPrecompiledType (HttpRuntime.AppDomainAppVirtualPath + "/global.asax");
+                       return apptype;
+               }
+
                public static Assembly GetCompiledAssembly (string virtualPath)
                {
                        VirtualPath vp = GetAbsoluteVirtualPath (virtualPath);
                        string vpabsolute = vp.Absolute;
+                       if (is_precompiled) {
+                               Type type = GetPrecompiledType (vpabsolute);
+                               if (type != null)
+                                       return type.Assembly;
+                       }
                        BuildManagerCacheItem bmci = GetCachedItem (vpabsolute);
                        if (bmci != null)
                                return bmci.BuiltAssembly;
-                       
+
                        Build (vp);
                        bmci = GetCachedItem (vpabsolute);
                        if (bmci != null)
@@ -597,6 +684,11 @@ namespace System.Web.Compilation {
                {
                        VirtualPath vp = GetAbsoluteVirtualPath (virtualPath);
                        string vpabsolute = vp.Absolute;
+                       if (is_precompiled) {
+                               Type type = GetPrecompiledType (vpabsolute);
+                               if (type != null)
+                                       return type;
+                       }
                        BuildManagerCacheItem bmci = GetCachedItem (vpabsolute);
                        if (bmci != null) {
                                ReferenceAssemblyInCompilation (bmci);
index b107ea4c310bf81c695cd81dac8b4b830f77c973..3e62df56b9a243f7b13d8b0b29df84caca8407eb 100644 (file)
@@ -1,3 +1,10 @@
+2009-02-18 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * TemplateControlCompiler.cs: lowercase place holder names
+       * BuildManager.cs: initial support for precompilation. No 'updatable',
+       please.
+
+
 2009-02-13  Marek Habersack  <mhabersack@novell.com>
 
        * AspParser.cs: added an event raised when parsing is complete.
index 52557d2d0f5a3509f2dec4adb2cd5255b36f3f12..a94bdf562cae3d4b21e9bc5ff5431424bb4e11ad 100644 (file)
@@ -1569,7 +1569,7 @@ namespace System.Web.Compilation
                        CodeMethodInvokeExpression mcall;
                        foreach (string id in masterPageContentPlaceHolders) {
                                mcall = new CodeMethodInvokeExpression (ilistRef, "Add");
-                               mcall.Parameters.Add (new CodePrimitiveExpression (id));
+                               mcall.Parameters.Add (new CodePrimitiveExpression (id.ToLowerInvariant ()));
                                statements.Add (mcall);
                        }
                }
index 14fd92eb042efa43585a963b8878a22170228174..2b275548cf060de261a38bf16995944e5c7caa18 100644 (file)
@@ -1,3 +1,7 @@
+2009-02-18 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * MasterPage.cs: the items in ContentPlaceHolders are lowercase.
+
 2009-02-18  Marek Habersack  <mhabersack@novell.com>
 
        * TemplateParser.cs: don't initialize PageParserFilter in
index 701e6fff796de36a5a6b50e86848e03d6d09a682..6f574cef5df4214e8ba3f539cbaa54f8be4a2a3c 100644 (file)
@@ -126,7 +126,7 @@ namespace System.Web.UI
                        List <string> placeholders = masterPage.placeholders;
                        if (contentTemplateCollection != null && placeholders != null && placeholders.Count > 0) {
                                foreach (string templateName in contentTemplateCollection.Keys) {
-                                       if (!placeholders.Contains (templateName)) {
+                                       if (!placeholders.Contains (templateName.ToLowerInvariant ())) {
                                                throw new HttpException (
                                                        String.Format ("Cannot find ContentPlaceHolder '{0}' in the master page '{1}'",
                                                                       templateName, masterPageFile));
index c39d2b0edb4375290e7cfa836c28044cc44138f8..172adae4882ed30ddfcdd79254b50059ea6ebe34 100644 (file)
@@ -1,3 +1,8 @@
+2009-02-18 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * HttpApplicationFactory.cs: check of global.asax was precompiled.
+
+
 2009-01-29 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * HttpApplicationFactory.cs: fix check that avoids lock. Keep one
index 00b0d42a917262c1a93f67fa7b0c3b0ec00e3f8b..1abd3f37409fec952682e70a0985f0b9fad97cda 100644 (file)
@@ -456,7 +456,10 @@ namespace System.Web {
                                        }
 #endif
 
-                                       if (app_file != null) {
+#if NET_2_0
+                                       app_type = BuildManager.GetPrecompiledApplicationType ();
+#endif
+                                       if (app_type == null && app_file != null) {
 #if TARGET_J2EE
                                                app_file = System.Web.Util.UrlUtils.ResolveVirtualPathFromAppAbsolute("~/" + Path.GetFileName(app_file));
                                                app_type = System.Web.J2EE.PageMapper.GetObjectType(context, app_file);
@@ -471,7 +474,7 @@ namespace System.Web {
                                                        string msg = String.Format ("Error compiling application file ({0}).", app_file);
                                                        throw new ApplicationException (msg);
                                                }
-                                       } else {
+                                       } else if (app_type == null) {
                                                app_type = typeof (System.Web.HttpApplication);
                                                app_state = new HttpApplicationState ();
                                        }