Author: andrews
Date: 2006-11-29 07:26:00 -0500 (Wed, 29 Nov 2006)
New Revision: 68660
Modified:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/WebTest.cs
Log:
don't create AppDomain while copying resources; don't allow to copy a resource
after AppDomain is created.
Modified: trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/WebTest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/WebTest.cs
2006-11-29 12:15:58 UTC (rev 68659)
+++ trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/WebTest.cs
2006-11-29 12:26:00 UTC (rev 68660)
@@ -20,7 +20,15 @@
/// <seealso cref="Run"/>
[Serializable]
public class WebTest
- {
+ {
+ /// <summary>
+ /// Thrown when trying to copy a resource after appdomain was
created. Please call
+ /// WebTest.Unload before copying resource.
+ /// </summary>
+ public class DomainUpException : Exception
+ {
+ }
+
object _userData;
/// <summary>
/// Any user-defined data. Must be serializable to pass between
appdomains.
@@ -96,24 +104,7 @@
private static MyHost Host
{
get {
- if (host != null)
- return host;
-#if !TARGET_JVM
- host = AppDomain.CurrentDomain.GetData
(HOST_INSTANCE_NAME) as MyHost;
- if (host != null)
- return host;
- try {
- host = new MyHost (); //Fake instance
to make EnsureHosting happy
- host = InitHosting ();
-
- }
- catch {
- host = null; //Remove the fake instance
if CreateHosting failed
- throw;
- }
-#else
- host = new MyHost ();
-#endif
+ EnsureHosting ();
return host;
}
}
@@ -205,6 +196,11 @@
return;
AppDomain oldDomain = host.AppDomain;
+ if (oldDomain == AppDomain.CurrentDomain)
+ {
+ Console.Error.WriteLine ("Some nasty runtime
bug happened");
+ throw new Exception ("Some nasty runtime bug
happened");
+ }
host = null;
AppDomain.CurrentDomain.SetData (HOST_INSTANCE_NAME,
null);
AppDomain.Unload (oldDomain);
@@ -269,50 +265,6 @@
}
-#if !TARGET_JVM
- static void LoadAssemblyRecursive (Assembly ass)
- {
- if (ass.GlobalAssemblyCache)
- return;
- foreach (AssemblyName ran in
ass.GetReferencedAssemblies ()) {
- bool found = false;
- foreach (Assembly domain_ass in
AppDomain.CurrentDomain.GetAssemblies ()) {
- if (domain_ass.FullName ==
ran.FullName) {
- found = true;
- break;
- }
- }
- if (found)
- continue;
- Assembly ra = Assembly.Load (ran, null);
- LoadAssemblyRecursive (ra);
- }
- }
-
- private static void CopyAssembly (Assembly ass, string dir)
- {
- if (ass.GlobalAssemblyCache)
- return;
- string oldfn = ass.Location;
- if (oldfn.EndsWith (".exe"))
- return;
- string newfn = Path.Combine (dir, Path.GetFileName
(oldfn));
- if (File.Exists (newfn))
- return;
- File.Copy (oldfn, newfn);
- }
-#endif
-
- private static void EnsureDirectoryExists (string directory)
- {
- if (directory == string.Empty)
- return;
- if (Directory.Exists (directory))
- return;
- EnsureDirectoryExists (Path.GetDirectoryName
(directory));
- Directory.CreateDirectory (directory);
- }
-
/// <summary>
/// Copy a resource embedded in the assembly into the web
application
/// </summary>
@@ -324,10 +276,8 @@
public static void CopyResource (Type type, string
resourceName, string targetUrl)
{
#if !TARGET_JVM
- if (targetUrl.IndexOf ("web.config") != -1 ||
- targetUrl.IndexOf ("Web.config") != -1)
- Console.WriteLine ("URL: {0} at {1}",
targetUrl, Environment.StackTrace);
- EnsureHosting ();
+ EnsureWorkingDirectories ();
+ CheckDomainIsDown ();
EnsureDirectoryExists (Path.Combine (baseDir,
Path.GetDirectoryName (targetUrl)));
using (Stream source =
type.Assembly.GetManifestResourceStream (resourceName)) {
@@ -340,43 +290,106 @@
}
}
#endif
- }
+ }
+
+ private static void EnsureHosting ()
+ {
+ if (host != null)
+ return;
+#if TARGET_JVM
+ host = new MyHost ();
+ return;
+#else
+ host = AppDomain.CurrentDomain.GetData
(HOST_INSTANCE_NAME) as MyHost;
+ if (host != null)
+ return;
+ CopyResources ();
+ foreach (Assembly ass in
AppDomain.CurrentDomain.GetAssemblies ())
+ LoadAssemblyRecursive (ass);
+
+ foreach (Assembly ass in
AppDomain.CurrentDomain.GetAssemblies ())
+ CopyAssembly (ass, binDir);
+
+ host = (MyHost) ApplicationHost.CreateApplicationHost
(typeof (MyHost), VIRTUAL_BASE_DIR, baseDir);
+ AppDomain.CurrentDomain.SetData (HOST_INSTANCE_NAME,
host);
+ host.AppDomain.SetData (HOST_INSTANCE_NAME, host);
+#endif
+ }
- private static void EnsureHosting ()
- {
- MyHost h = Host;
+#if !TARGET_JVM
+ const string VIRTUAL_BASE_DIR = "/NunitWeb";
+ private static string baseDir;
+ private static string binDir;
+ const string HOST_INSTANCE_NAME =
"MonoTests/SysWeb/Framework/Host";
+
+ static void LoadAssemblyRecursive (Assembly ass)
+ {
+ if (ass.GlobalAssemblyCache)
+ return;
+ foreach (AssemblyName ran in
ass.GetReferencedAssemblies ()) {
+ bool found = false;
+ foreach (Assembly domain_ass in
AppDomain.CurrentDomain.GetAssemblies ()) {
+ if (domain_ass.FullName ==
ran.FullName) {
+ found = true;
+ break;
+ }
+ }
+ if (found)
+ continue;
+ Assembly ra = Assembly.Load (ran, null);
+ LoadAssemblyRecursive (ra);
+ }
+ }
+
+ private static void CopyAssembly (Assembly ass, string dir)
+ {
+ if (ass.GlobalAssemblyCache)
+ return;
+ string oldfn = ass.Location;
+ if (oldfn.EndsWith (".exe"))
+ return;
+ string newfn = Path.Combine (dir, Path.GetFileName
(oldfn));
+ if (File.Exists (newfn))
+ return;
+ EnsureDirectoryExists (dir);
+ File.Copy (oldfn, newfn);
+ }
+
+ private static void EnsureDirectoryExists (string directory)
+ {
+ if (directory == string.Empty)
+ return;
+ if (Directory.Exists (directory))
+ return;
+ EnsureDirectoryExists (Path.GetDirectoryName
(directory));
+ Directory.CreateDirectory (directory);
+ }
+
+ private static void CheckDomainIsDown ()
+ {
+ if (host != null)
+ throw new DomainUpException ();
+ }
+
+ private static void EnsureWorkingDirectories ()
+ {
+ if (baseDir != null)
+ return;
+ CreateWorkingDirectories ();
+ }
+
+ private static void CreateWorkingDirectories ()
+ {
+ string tmpFile = Path.GetTempFileName ();
+ File.Delete (tmpFile);
+ baseDir = tmpFile;
+ Directory.CreateDirectory (tmpFile);
+ binDir = Path.Combine (baseDir, "bin");
+ Directory.CreateDirectory (binDir);
}
-#if !TARGET_JVM
- const string VIRTUAL_BASE_DIR = "/NunitWeb";
- private static string baseDir;
- private static string binDir;
- const string HOST_INSTANCE_NAME =
"MonoTests/SysWeb/Framework/Host";
-
- private static MyHost InitHosting ()
- {
- string tmpFile = Path.GetTempFileName ();
- File.Delete (tmpFile);
- Directory.CreateDirectory (tmpFile);
- baseDir = tmpFile;
- binDir = Directory.CreateDirectory (Path.Combine
(baseDir, "bin")).FullName;
-
- CopyResources ();
- File.Create (Path.Combine (baseDir, "page.fake"));
- foreach (Assembly ass in
AppDomain.CurrentDomain.GetAssemblies ())
- LoadAssemblyRecursive (ass);
-
- foreach (Assembly ass in
AppDomain.CurrentDomain.GetAssemblies ())
- CopyAssembly (ass, binDir);
-
- MyHost host = (MyHost)
ApplicationHost.CreateApplicationHost (typeof (MyHost), VIRTUAL_BASE_DIR,
baseDir);
- AppDomain.CurrentDomain.SetData (HOST_INSTANCE_NAME,
host);
- host.AppDomain.SetData (HOST_INSTANCE_NAME, host);
- return host;
- }
-
private static void CopyResources ()
- {
+ {
#if VISUAL_STUDIO
CopyResource (typeof (WebTest),
"MonoTests.SystemWeb.Framework.Resources.Web.config",
@@ -393,26 +406,6 @@
CopyResource (typeof (WebTest),
"MonoTests.SystemWeb.Framework.Resources.My.master",
"My.master");
-//#if TARGET_JVM
-// CopyResource (typeof (WebTest),
-//
"MonoTests.SystemWeb.Framework.Resources.assemblies.global.asax.xml",
-// "assemblies/global.asax.xml");
-// CopyResource (typeof (WebTest),
-//
"MonoTests.SystemWeb.Framework.Resources.assemblies.mypage.aspx.xml",
-// "assemblies/mypage.aspx.xml");
-// CopyResource (typeof (WebTest),
-//
"MonoTests.SystemWeb.Framework.Resources.assemblies.hnnefdht.dll.ghres",
-// "assemblies/hnnefdht/dll.ghres");
-// CopyResource (typeof (WebTest),
-//
"MonoTests.SystemWeb.Framework.Resources.assemblies.hnnefdht.hnnefdhtAttrib.class",
-// "assemblies/hnnefdht/hnnefdhtAttrib.class");
-//// CopyResource (typeof (WebTest),
-////
"MonoTests.SystemWeb.Framework.Resources.assemblies.hnnefdht.ASP.MyPage_aspx_MyPage_aspxAttrib.class",
-////
"assemblies/hnnefdht/ASP/MyPage_aspx$MyPage_aspxAttrib.class");
-//// CopyResource (typeof (WebTest),
-////
"MonoTests.SystemWeb.Framework.Resources.assemblies.hnnefdht.ASP.MyPage_aspx.class",
-//// "assemblies/hnnefdht/ASP/MyPage_aspx.class");
-//#endif
#else
CopyResource (typeof (WebTest), "Web.mono.config",
"Web.config");
CopyResource (typeof (WebTest), "MyPage.aspx",
"MyPage.aspx");
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches