Mark tests as not working under TARGET_JVM
[mono.git] / mcs / class / System.Web / System.Web / HttpRuntime.cs
index 202df0f68e5ef86db653f712523c16f3abefdf01..34a8d98282536eda0cffcc54fe612213c8a19f19 100644 (file)
@@ -34,6 +34,7 @@ using System.IO;
 using System.Text;
 using System.Globalization;
 using System.Collections;
+using System.Reflection;
 using System.Security;
 using System.Security.Permissions;
 using System.Web.Caching;
@@ -41,6 +42,11 @@ using System.Web.Configuration;
 using System.Web.UI;
 using System.Threading;
 
+#if NET_2_0 && !TARGET_JVM
+using System.CodeDom.Compiler;
+using System.Web.Compilation;
+#endif
+
 namespace System.Web {
        
        // CAS - no InheritanceDemand here as the class is sealed
@@ -51,7 +57,7 @@ namespace System.Web {
                static TraceManager trace_manager { get { return _runtime._trace_manager; } }
                static Cache cache { get { return _runtime._cache; } }
                static WaitCallback do_RealProcessRequest;
-
+               
                QueueManager _queue_manager;
                TraceManager _trace_manager;
                Cache _cache;
@@ -63,6 +69,7 @@ namespace System.Web {
 
                public HttpRuntime ()
                {
+                       WebConfigurationManager.Init ();
                        _queue_manager = new QueueManager ();
                        _trace_manager = new TraceManager ();
                        _cache = new Cache ();
@@ -89,8 +96,16 @@ namespace System.Web {
                static Cache cache;
                static WaitCallback do_RealProcessRequest;
 
+#if NET_2_0
+               static bool assemblyMappingEnabled;
+               static object assemblyMappingLock = new object ();
+#endif
+               
                static HttpRuntime ()
                {
+#if NET_2_0
+                       WebConfigurationManager.Init ();
+#endif
                        queue_manager = new QueueManager ();
                        trace_manager = new TraceManager ();
                        timeout_manager = new TimeoutManager ();
@@ -161,7 +176,7 @@ namespace System.Web {
                
                public static string BinDirectory {
                        get {
-                               string dirname = Path.Combine (AppDomainAppPath, "bin");
+                               string dirname = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
                                if (SecurityManager.SecurityEnabled) {
                                        new FileIOPermission (FileIOPermissionAccess.PathDiscovery, dirname).Demand ();
                                }
@@ -254,7 +269,7 @@ namespace System.Web {
                                HttpContext.Current = null;
                        } else {
                                context.ApplicationInstance = app;
-                       
+                               
                                //
                                // Ask application to service the request
                                //
@@ -379,6 +394,73 @@ namespace System.Web {
                        wr.CloseConnection ();
                }
 
+#if NET_2_0 && !TARGET_J2EE
+               static internal void WritePreservationFile (Assembly asm, string genericNameBase)
+               {
+                       if (asm == null)
+                               throw new ArgumentNullException ("asm");
+                       if (String.IsNullOrEmpty (genericNameBase))
+                               throw new ArgumentNullException ("genericNameBase");
+
+                       string compiled = Path.Combine (AppDomain.CurrentDomain.SetupInformation.DynamicBase,
+                                                       genericNameBase + ".compiled");
+                       PreservationFile pf = new PreservationFile ();
+                       try {
+                               pf.VirtualPath = String.Format ("/{0}/", genericNameBase);
+
+                               AssemblyName an = asm.GetName ();
+                               pf.Assembly = an.Name;
+                               pf.ResultType = BuildResultTypeCode.TopLevelAssembly;
+                               pf.Save (compiled);
+                       } catch (Exception ex) {
+                               throw new HttpException (
+                                       String.Format ("Failed to write preservation file {0}", genericNameBase + ".compiled"),
+                                       ex);
+                       }
+               }
+               
+               static Assembly ResolveAssemblyHandler(object sender, ResolveEventArgs e)
+               {
+                       AssemblyName an = new AssemblyName (e.Name);
+                       string dynamic_base = AppDomain.CurrentDomain.SetupInformation.DynamicBase;
+                       string compiled = Path.Combine (dynamic_base, an.Name + ".compiled");
+
+                       if (!File.Exists (compiled))
+                               return null;
+
+                       PreservationFile pf;
+                       try {
+                               pf = new PreservationFile (compiled);
+                       } catch (Exception ex) {
+                               throw new HttpException (
+                                       String.Format ("Failed to read preservation file {0}", an.Name + ".compiled"),
+                                       ex);
+                       }
+                       
+                       Assembly ret = null;
+                       try {
+                               string asmPath = Path.Combine (dynamic_base, pf.Assembly + ".dll");
+                               ret = Assembly.LoadFrom (asmPath);
+                       } catch (Exception) {
+                               // ignore
+                       }
+                       
+                       return ret;
+               }
+               
+               internal static void EnableAssemblyMapping (bool enable)
+               {
+                       lock (assemblyMappingLock) {
+                               if (assemblyMappingEnabled == enable)
+                                       return;
+                               if (enable)
+                                       AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler (ResolveAssemblyHandler);
+                               else
+                                       AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler (ResolveAssemblyHandler);
+                       }
+               }
+#endif
+               
                internal static TraceManager TraceManager {
                        get {
                                return trace_manager;