public virtual Type GetCompiledType ()
{
- Type type = CachingCompiler.GetTypeFromCache (parser.InputFile, parser.ClassName);
+ Type type = CachingCompiler.GetTypeFromCache (parser.InputFile);
if (type != null)
return type;
{
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;
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;
+ }
}
}
+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
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;
"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)
+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.
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;
ParseDirective (trimmed);
directiveFound = true;
if (gotDefault) {
- cachedType = CachingCompiler.GetTypeFromCache (physPath,
- className);
+ cachedType = CachingCompiler.GetTypeFromCache (physPath);
if (cachedType != null)
break;
}