2004-09-05 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sun, 5 Sep 2004 19:42:12 +0000 (19:42 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sun, 5 Sep 2004 19:42:12 +0000 (19:42 -0000)
* System.Web.Compilation/BaseCompiler.cs:
* System.Web.Compilation/CachingCompiler.cs:
* System.Web.Compilation/WebServiceCompiler.cs:
* System.Web.UI/SimpleWebHandlerParser.cs: correctly cache Type instead
of the assembly for ashx/asmx. Otherwise we need to open the file and
check for the class name in there. Thanks to Ben for pointing this out.

svn path=/branches/mono-1-0/mcs/; revision=33383

mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs
mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs
mcs/class/System.Web/System.Web.Compilation/ChangeLog
mcs/class/System.Web/System.Web.Compilation/WebServiceCompiler.cs
mcs/class/System.Web/System.Web.UI/ChangeLog
mcs/class/System.Web/System.Web.UI/SimpleWebHandlerParser.cs

index c5f1c41092399a342959ffa342c4b0de46bd4bef..07578009be5dbc3829800d8ffd90ac36d89a79d7 100644 (file)
@@ -284,7 +284,7 @@ namespace System.Web.Compilation
 
                public virtual Type GetCompiledType () 
                {
-                       Type type = CachingCompiler.GetTypeFromCache (parser.InputFile, parser.ClassName);
+                       Type type = CachingCompiler.GetTypeFromCache (parser.InputFile);
                        if (type != null)
                                return type;
 
index 0c14da135a5891112bd7bfccbd41ba695afb281e..0e6f7d12bbf0fc6ed9d3ca10ae45925d3609c7a2 100644 (file)
@@ -44,21 +44,20 @@ namespace System.Web.Compilation
        {
                static object compilationLock = new object ();
                const string cachePrefix = "@@Assembly";
+               const string cacheTypePrefix = "@@@Type";
 
-               public static Type GetTypeFromCache (string filename, string typename)
+               public static void InsertType (Type type, string filename)
                {
-                       string key = CachingCompiler.cachePrefix + filename;
-                       CompilerResults results = (CompilerResults) HttpRuntime.Cache [key];
-                       if (results == null)
-                               return null;
-
-                       Assembly a = results.CompiledAssembly;
-                       if (a == null)
-                               return null;
+                       string [] cacheKeys = new string [] { cachePrefix + filename };
+                       CacheDependency dep = new CacheDependency (null, cacheKeys);
+                       HttpRuntime.Cache.Insert (cacheTypePrefix + filename, type, dep);
+               }
 
-                       return a.GetType (typename, false);
+               public static Type GetTypeFromCache (string filename)
+               {
+                       return (Type) HttpRuntime.Cache [cacheTypePrefix + filename];
                }
-               
+
                public static CompilerResults Compile (BaseCompiler compiler)
                {
                        Cache cache = HttpRuntime.Cache;
@@ -153,6 +152,26 @@ namespace System.Web.Compilation
 
                        return results;
                }
+
+               public static Type CompileAndGetType (string typename, string language, string key,
+                                               string file, ArrayList assemblies)
+               {
+                       CompilerResults result = CachingCompiler.Compile (language, key, file, assemblies);
+                       if (result.NativeCompilerReturnValue != 0) {
+                               StreamReader reader = new StreamReader (file);
+                               throw new CompilationException (file, result.Errors, reader.ReadToEnd ());
+                       }
+
+                       Assembly assembly = result.CompiledAssembly;
+                       if (assembly == null) {
+                               StreamReader reader = new StreamReader (file);
+                               throw new CompilationException (file, result.Errors, reader.ReadToEnd ());
+                       }
+               
+                       Type type = assembly.GetType (typename, true);
+                       InsertType (type, file);
+                       return type;
+               }
        }
 }
 
index 8e4e6ea40291065b6c0c886320b53b6ea01638ba..5d1e428381bdd6919cf3066d80e2efaa46ccb4be 100644 (file)
@@ -1,3 +1,11 @@
+2004-09-05 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * BaseCompiler.cs:
+       * CachingCompiler.cs:
+       * WebServiceCompiler.cs: correctly cache Type instead of the assembly
+       for ashx/asmx. Otherwise we need to open the file and check for the
+       class name in there. Thanks to Ben for pointing this out.
+
 2004-09-01 Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * CachingCompiler.cs: don't try to watch for changes in system
index f6884bf428bceba17d13ec967ee966c41b996afb..469bb0aba7230badf1510fe92d8ae8ae913e164d 100644 (file)
@@ -59,12 +59,15 @@ namespace System.Web.Compilation
 
                public override Type GetCompiledType ()
                {
-                       Type type = CachingCompiler.GetTypeFromCache (parser.PhysicalPath, parser.ClassName);
+                       Type type = CachingCompiler.GetTypeFromCache (parser.PhysicalPath);
                        if (type != null)
                                return type;
 
-                       if (parser.Program.Trim () == "")
-                               return parser.GetTypeFromBin (parser.ClassName);
+                       if (parser.Program.Trim () == "") {
+                               type = parser.GetTypeFromBin (parser.PhysicalPath);
+                               CachingCompiler.InsertType (type, parser.PhysicalPath);
+                               return type;
+                       }
 
                        string lang = parser.Language;
                        CompilationConfiguration config;
@@ -106,7 +109,9 @@ namespace System.Web.Compilation
                                        "No assembly returned after compilation!?");
 
                        results.TempFiles.Delete ();
-                       return results.CompiledAssembly.GetType (parser.ClassName, true);
+                       type = results.CompiledAssembly.GetType (parser.ClassName, true);
+                       CachingCompiler.InsertType (type, parser.PhysicalPath);
+                       return type;
                }
 
                void CheckCompilerErrors (CompilerResults results)
index 0ffb5a9a4fb93af367adaaa1e69c341e053d3057..6337d82a2c20abb22ce2b23cc2a89269ad7e6c1e 100644 (file)
@@ -1,3 +1,9 @@
+2004-09-05 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * SimpleWebHandlerParser.cs: correctly cache Type instead of the
+       assembly for ashx/asmx. Otherwise we need to open the file and check
+       for the class name in there. Thanks to Ben for pointing this out.
+
 2004-09-05 Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * TemplateParser.cs: removed creation of StringWriter.  It's not used.
index 4c200a9356883da4695835574d84105c13f12b43..d075d404a5cc89064fb60ccde2e54a397c427dca 100644 (file)
@@ -64,6 +64,10 @@ namespace System.Web.UI
 
                protected SimpleWebHandlerParser (HttpContext context, string virtualPath, string physicalPath)
                {
+                       cachedType = CachingCompiler.GetTypeFromCache (physicalPath);
+                       if (cachedType != null)
+                               return; // We don't need anything else.
+
                        this.context = context;
                        this.vPath = virtualPath;
                        this.physPath = physicalPath;
@@ -104,8 +108,7 @@ namespace System.Web.UI
                                        ParseDirective (trimmed);
                                        directiveFound = true;
                                        if (gotDefault) {
-                                               cachedType = CachingCompiler.GetTypeFromCache (physPath,
-                                                                                               className);
+                                               cachedType = CachingCompiler.GetTypeFromCache (physPath);
                                                if (cachedType != null)
                                                        break;
                                        }