2002-11-29 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 29 Nov 2002 03:07:50 +0000 (03:07 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 29 Nov 2002 03:07:50 +0000 (03:07 -0000)
* list: added new file.
* System.Web.Compilation/GlobalAsaxCompiler.cs: compiler for global.asax
file. If the file exists, it will be compiled into an HttpApplication
derived class (directly or through a user-provided class).

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

mcs/class/System.Web/ChangeLog
mcs/class/System.Web/System.Web.Compilation/ChangeLog
mcs/class/System.Web/System.Web.Compilation/GlobalAsaxCompiler.cs [new file with mode: 0644]
mcs/class/System.Web/list

index 015e43ba022911ef725dac8e112c6e6bb66e781c..e36cf5f324453fd7c011a5cf55e96fc5eac5a3b8 100644 (file)
@@ -1,3 +1,7 @@
+2002-11-29  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * list: added new file.
+
 2002-11-26  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * list: added/removed files.
index 108bb61610875e7b24549409ba6ec0ba130eda7e..5cc759eba35f9aff5f31f264ac35b59c2b1ad046 100644 (file)
@@ -1,3 +1,9 @@
+2002-11-29  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * GlobalAsaxCompiler.cs: compiler for global.asax file. If the file
+       exists, it will be compiled into an HttpApplication derived class
+       (directly or through a user-provided class).
+
 2002-11-27  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * AspGenerator.cs: fixed target file name and generated class name.
diff --git a/mcs/class/System.Web/System.Web.Compilation/GlobalAsaxCompiler.cs b/mcs/class/System.Web/System.Web.Compilation/GlobalAsaxCompiler.cs
new file mode 100644 (file)
index 0000000..caddc05
--- /dev/null
@@ -0,0 +1,119 @@
+//
+// System.Web.Compilation.GlobalAsaxCompiler
+//
+// Authors:
+//     Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (C) 2002 Ximian, Inc (http://www.ximian.com)
+//
+using System;
+using System.Collections;
+using System.IO;
+using System.Reflection;
+using System.Text;
+using System.Web;
+using System.Web.Util;
+
+namespace System.Web.Compilation
+{
+       class GlobalAsaxCompiler : BaseCompiler
+       {
+               Hashtable options;
+               string filename;
+               string sourceFile;
+
+               private GlobalAsaxCompiler (string filename)
+               {
+                       this.filename = filename;
+               }
+
+               public override Type GetCompiledType ()
+               {
+                       sourceFile = GenerateSourceFile ();
+
+                       CachingCompiler compiler = new CachingCompiler (this);
+                       CompilationResult result = new CompilationResult ();
+                       if (compiler.Compile (result) == false)
+                               throw new CompilationException (result);
+                               
+                       Assembly assembly = Assembly.LoadFrom (result.OutputFile);
+                       Type [] types = assembly.GetTypes ();
+                       if (types.Length != 1)
+                               throw new CompilationException ("More than 1 Type in an application?", result);
+
+                       result.Data = types [0];
+                       return types [0];
+               }
+
+               public override string Key {
+                       get {
+                               return filename;
+                       }
+               }
+
+               public override string SourceFile {
+                       get {
+                               return sourceFile;
+                       }
+               }
+
+               public override string CompilerOptions {
+                       get {
+                               if (options == null)
+                                       return base.CompilerOptions;
+
+                               StringBuilder sb = new StringBuilder (base.CompilerOptions);
+                               string compilerOptions = options ["CompilerOptions"] as string;
+                               if (compilerOptions != null) {
+                                       sb.Append (' ');
+                                       sb.Append (compilerOptions);
+                               }
+
+                               string references = options ["References"] as string;
+                               if (references == null)
+                                       return sb.ToString ();
+
+                               string [] split = references.Split (' ');
+                               foreach (string s in split)
+                                       sb.AppendFormat (" /r:{0}", s);
+
+                               return sb.ToString ();
+                       }
+               }
+
+               public static Type CompileApplicationType (string filename)
+               {
+                       CompilationCacheItem item = CachingCompiler.GetCached (filename);
+                       if (item != null && item.Result != null) {
+                               if (item.Result != null)
+                                       return item.Result.Data as Type;
+
+                               throw new CompilationException (item.Result);
+                       }
+
+                       GlobalAsaxCompiler gac = new GlobalAsaxCompiler (filename);
+                       return gac.GetCompiledType ();
+               }
+
+               string GenerateSourceFile ()
+               {
+                       Stream input = File.OpenRead (filename);
+                       AspParser parser = new AspParser (filename, input);
+                       parser.Parse ();
+                       AspGenerator generator = new AspGenerator (filename, parser.Elements);
+                       generator.BaseType = typeof (HttpApplication).ToString ();
+                       generator.ProcessElements ();
+                       string generated = generator.GetCode ().ReadToEnd ();
+                       options = generator.Options;
+
+                       //FIXME: should get Tmp dir for this application
+                       string csName = Path.GetTempFileName () + ".cs";
+                       WebTrace.WriteLine ("Writing {0}", csName);
+                       StreamWriter output = new StreamWriter (File.OpenWrite (csName));
+                       output.Write (generated);
+                       output.Close ();
+                       return csName;
+               }
+       }
+}
+
index b79df061abe606c18a2646944374362581aca255..97bcf5f9c09eb8a23270787d40d683f8893d5bc6 100755 (executable)
@@ -358,6 +358,7 @@ System.Web.Compilation/BaseCompiler.cs
 System.Web.Compilation/CachingCompiler.cs
 System.Web.Compilation/CompilationResult.cs
 System.Web.Compilation/CompilationException.cs
+System.Web.Compilation/GlobalAsaxCompiler.cs
 System.Web.Compilation/PageCompiler.cs
 System.Web.Compilation/UserControlCompiler.cs
 System.Web.Compilation/WebServiceCompiler.cs