From 24ff4f1c36dcca4f35675579443fe2bf60ba4d88 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Sun, 31 Aug 2008 23:31:09 +0000 Subject: [PATCH] Backport of r111998 svn path=/branches/mono-2-0/mcs/; revision=111999 --- .../System.Web.Compilation/AspGenerator.cs | 24 ++++++++++++------- .../System.Web.Compilation/BaseCompiler.cs | 4 +++- .../System.Web.Compilation/CachingCompiler.cs | 21 +++++++++------- .../System.Web.UI/TemplateControl.cs | 23 +++++++++++++++++- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs b/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs index 2fc7f234ba307..62299d1e332b2 100644 --- a/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs +++ b/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs @@ -349,17 +349,23 @@ public void Parse () internal static void AddTypeToCache (ArrayList dependencies, string inputFile, Type type) { - string [] deps = (string []) dependencies.ToArray (typeof (string)); - HttpContext ctx = HttpContext.Current; - HttpRequest req = ctx != null ? ctx.Request : null; + if (type == null || inputFile == null || inputFile.Length == 0) + return; - if (req == null) - throw new HttpException ("No current context, cannot compile."); + if (dependencies != null && dependencies.Count > 0) { + string [] deps = (string []) dependencies.ToArray (typeof (string)); + HttpContext ctx = HttpContext.Current; + HttpRequest req = ctx != null ? ctx.Request : null; + + if (req == null) + throw new HttpException ("No current context, cannot compile."); - for (int i = 0; i < deps.Length; i++) - deps [i] = req.MapPath (deps [i]); + for (int i = 0; i < deps.Length; i++) + deps [i] = req.MapPath (deps [i]); - HttpRuntime.InternalCache.Insert ("@@Type" + inputFile, type, new CacheDependency (deps)); + HttpRuntime.InternalCache.Insert ("@@Type" + inputFile, type, new CacheDependency (deps)); + } else + HttpRuntime.InternalCache.Insert ("@@Type" + inputFile, type); } public Type GetCompiledType () @@ -372,7 +378,7 @@ public Type GetCompiledType () Parse (); BaseCompiler compiler = GetCompilerFromType (); - + type = compiler.GetCompiledType (); AddTypeToCache (tparser.Dependencies, tparser.InputFile, type); return type; diff --git a/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs b/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs index 99df494b215ca..feed871ce7d07 100644 --- a/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs +++ b/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs @@ -303,8 +303,10 @@ protected virtual void CreateStaticFields () #if NET_2_0 void AssignAppRelativeVirtualPath (CodeConstructor ctor) { + if (String.IsNullOrEmpty (parser.InputFile)) + return; + Type baseType = parser.CodeFileBaseClassType; - if (baseType == null) baseType = parser.BaseType; if (baseType == null) diff --git a/mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs b/mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs index bb51e5c5c5e28..b77c20df935f7 100644 --- a/mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs +++ b/mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs @@ -99,17 +99,20 @@ public static CompilerResults Compile (BaseCompiler compiler) CompilerParameters options = compiler.CompilerParameters; GetExtraAssemblies (options); results = comp.CompileAssemblyFromDom (options, compiler.CompileUnit); - string [] deps = (string []) compiler.Parser.Dependencies.ToArray (typeof (string)); - HttpContext ctx = HttpContext.Current; - HttpRequest req = ctx != null ? ctx.Request : null; - - if (req == null) - throw new HttpException ("No current context, cannot compile."); + ArrayList dependencies = compiler.Parser.Dependencies; + if (dependencies != null && dependencies.Count > 0) { + string [] deps = (string []) dependencies.ToArray (typeof (string)); + HttpContext ctx = HttpContext.Current; + HttpRequest req = ctx != null ? ctx.Request : null; + + if (req == null) + throw new HttpException ("No current context, cannot compile."); - for (int i = 0; i < deps.Length; i++) - deps [i] = req.MapPath (deps [i]); + for (int i = 0; i < deps.Length; i++) + deps [i] = req.MapPath (deps [i]); - cache.Insert (key, results, new CacheDependency (deps)); + cache.Insert (key, results, new CacheDependency (deps)); + } } finally { Monitor.Exit (ticket); if (acquired) diff --git a/mcs/class/System.Web/System.Web.UI/TemplateControl.cs b/mcs/class/System.Web/System.Web.UI/TemplateControl.cs index 7d3be81ac684c..aded9a6a207de 100644 --- a/mcs/class/System.Web/System.Web.UI/TemplateControl.cs +++ b/mcs/class/System.Web/System.Web.UI/TemplateControl.cs @@ -320,12 +320,33 @@ public Control ParseControl (string content) throw new ArgumentNullException ("content"); #if NET_2_0 + // FIXME: This method needs to be rewritten in some sane way - the way it is now, + // is a kludge. New version should not use + // UserControlParser.GetCompiledType, but instead resort to some other way + // of creating the content (template instantiation? BuildManager? TBD) TextReader reader = new StringReader (content); Type control = UserControlParser.GetCompiledType (reader, HttpContext.Current); if (control == null) return null; + + TemplateControl parsedControl = Activator.CreateInstance (control, null) as TemplateControl; + if (parsedControl == null) + return null; + + if (this is System.Web.UI.Page) + parsedControl.Page = (System.Web.UI.Page) this; + parsedControl.FrameworkInitialize (); - return Activator.CreateInstance (control, null) as Control; + Control ret = new Control (); + int count = parsedControl.Controls.Count; + Control[] parsedControlControls = new Control [count]; + parsedControl.Controls.CopyTo (parsedControlControls, 0); + + for (int i = 0; i < count; i++) + ret.Controls.Add (parsedControlControls [i]); + + parsedControl = null; + return ret; #else return null; #endif