Files
mono/mcs/class/System.Web/System.Web.Compilation/UserControlCompiler.cs
T
Gonzalo Paniagua Javier 31c202887f 2002-12-13 Gonzalo Paniagua Javier <[email protected]>
* System.Web.Compilation/AspGenerator.cs: added support for
	AutoEventWireup attribute in @Page and @Control.

	* System.Web.Compilation/CompilationResult.cs:
	* System.Web.Compilation/GlobalAsaxCompiler.cs:
	* System.Web.Compilation/PageCompiler.cs:
	* System.Web.Compilation/UserControlCompiler.cs: store the options.

	* System.Web.UI/Control.cs: added AutoEventWireup internal property.

	* System.Web.UI/Page.cs: removed page events wire up from here.

	* System.Web.UI/TemplateControl.cs: new method WireupAutomaticEvents to
	hook up page and user controls events.

	* System.Web.UI/TemplateControlParser.cs: process the options that are
	applicable once we have the instance of the control.

	* System.Web.UI/TemplateParser.cs: also stores the options.

	* System.Web.UI/UserControl.cs: hook up events before initializing the
	control.

svn path=/trunk/mcs/; revision=9623
2002-12-13 15:57:07 +00:00

118 lines
3.0 KiB
C#

//
// System.Web.Compilation.UserControlCompiler
//
// Authors:
// Gonzalo Paniagua Javier ([email protected])
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
//
using System;
using System.IO;
using System.Reflection;
using System.Web.UI;
using System.Web.Util;
namespace System.Web.Compilation
{
class UserControlCompiler : BaseCompiler
{
UserControlParser userControlParser;
string sourceFile;
string targetFile;
internal UserControlCompiler (UserControlParser userControlParser)
{
this.userControlParser = userControlParser;
}
public override Type GetCompiledType ()
{
string inputFile = userControlParser.InputFile;
sourceFile = GenerateSourceFile (userControlParser);
CachingCompiler compiler = new CachingCompiler (this);
CompilationResult result = new CompilationResult ();
result.Options = options;
if (compiler.Compile (result) == false)
throw new CompilationException (result);
if (result.Data is Type) {
targetFile = result.OutputFile;
return (Type) result.Data;
}
Assembly assembly = Assembly.LoadFrom (result.OutputFile);
Type [] types = assembly.GetTypes ();
foreach (Type t in types) {
if (t.IsSubclassOf (typeof (UserControl))) {
if (result.Data != null)
throw new CompilationException ("More that 1 user control!!!", result);
result.Data = t;
}
}
return result.Data as Type;
}
public override string Key {
get {
return userControlParser.InputFile;
}
}
public override string SourceFile {
get {
return sourceFile;
}
}
public override string TargetFile {
get {
if (targetFile == null)
targetFile = Path.ChangeExtension (sourceFile, ".dll");
return targetFile;
}
}
public static Type CompileUserControlType (UserControlParser userControlParser)
{
CompilationCacheItem item = CachingCompiler.GetCached (userControlParser.InputFile);
if (item != null && item.Result != null) {
if (item.Result != null) {
userControlParser.Options = item.Result.Options;
return item.Result.Data as Type;
}
throw new CompilationException (item.Result);
}
UserControlCompiler pc = new UserControlCompiler (userControlParser);
return pc.GetCompiledType ();
}
string GenerateSourceFile (UserControlParser userControlParser)
{
string inputFile = userControlParser.InputFile;
Stream input = File.OpenRead (inputFile);
AspParser parser = new AspParser (inputFile, input);
parser.Parse ();
AspGenerator generator = new AspGenerator (inputFile, parser.Elements);
generator.BaseType = userControlParser.BaseType.ToString ();
generator.ProcessElements ();
userControlParser.Text = 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 (userControlParser.Text);
output.Close ();
return csName;
}
}
}