Browse Source

2004-09-05 Gonzalo Paniagua Javier <[email protected]>

	* 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=/trunk/mcs/; revision=33382
Gonzalo Paniagua Javier 21 năm trước cách đây
mục cha
commit
628467bbfc

+ 1 - 1
mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs

@@ -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;
 

+ 30 - 11
mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs

@@ -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;
+		}
 	}
 }
 

+ 8 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,11 @@
+2004-09-05 Gonzalo Paniagua Javier <[email protected]>
+
+	* 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-05 Gonzalo Paniagua Javier <[email protected]>
 
 	* AspParser.cs:

+ 9 - 4
mcs/class/System.Web/System.Web.Compilation/WebServiceCompiler.cs

@@ -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)

+ 6 - 0
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,3 +1,9 @@
+2004-09-05 Gonzalo Paniagua Javier <[email protected]>
+
+	* 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 <[email protected]>
 
 	* TemplateParser.cs: removed creation of StringWriter.  It's not used.

+ 5 - 2
mcs/class/System.Web/System.Web.UI/SimpleWebHandlerParser.cs

@@ -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;
 					}