Skip to content

Commit

Permalink
Backport of r111998
Browse files Browse the repository at this point in the history
svn path=/branches/mono-2-0/mcs/; revision=111999
  • Loading branch information
grendello committed Aug 31, 2008
1 parent 8ecd99c commit 24ff4f1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
24 changes: 15 additions & 9 deletions mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs
Expand Up @@ -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 ()
Expand All @@ -372,7 +378,7 @@ public Type GetCompiledType ()
Parse ();

BaseCompiler compiler = GetCompilerFromType ();

type = compiler.GetCompiledType ();
AddTypeToCache (tparser.Dependencies, tparser.InputFile, type);
return type;
Expand Down
4 changes: 3 additions & 1 deletion mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs
Expand Up @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs
Expand Up @@ -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)
Expand Down
23 changes: 22 additions & 1 deletion mcs/class/System.Web/System.Web.UI/TemplateControl.cs
Expand Up @@ -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
Expand Down

0 comments on commit 24ff4f1

Please sign in to comment.