Merge pull request #2227 from esdrubal/tzparse
[mono.git] / mcs / class / System.Web / System.Web / HttpApplicationFactory.cs
index 11ba8ddd4694d15a7517c68652f23d791e6ec70a..597379a9bad1bf9fd94c6a0ead55e9c87673080f 100644 (file)
@@ -38,11 +38,7 @@ using System.Threading;
 using System.Web.Util;
 
 using System.Web.Compilation;
-#if TARGET_J2EE
-using vmw.common;
-#else
 using System.CodeDom.Compiler;
-#endif
 
 namespace System.Web
 {
@@ -51,27 +47,7 @@ namespace System.Web
                object this_lock = new object ();
                
                // Initialized in InitType
-#if TARGET_J2EE
-               static HttpApplicationFactory theFactory {
-                       get
-                       {
-                               HttpApplicationFactory factory = (HttpApplicationFactory)AppDomain.CurrentDomain.GetData("HttpApplicationFactory");
-                               if (factory == null) {
-                                       lock(typeof(HttpApplicationFactory)) {
-                                               factory = (HttpApplicationFactory)AppDomain.CurrentDomain.GetData("HttpApplicationFactory");
-                                               if (factory == null) {
-                                                       factory = new HttpApplicationFactory();
-                                                       System.Threading.Thread.Sleep(1);
-                                                       AppDomain.CurrentDomain.SetData("HttpApplicationFactory", factory);
-                                               }
-                                       }
-                               }
-                               return factory;
-                       }
-               }
-#else
                static HttpApplicationFactory theFactory = new HttpApplicationFactory();
-#endif
                object session_end; // This is a MethodInfo
                bool needs_init = true;
                bool app_start_needed = true;
@@ -362,14 +338,6 @@ namespace System.Web
                }
                
                internal static HttpApplicationState ApplicationState {
-#if TARGET_J2EE
-                       get {
-                               HttpApplicationFactory factory = theFactory;
-                               if (factory.app_state == null)
-                                       factory.app_state = new HttpApplicationState (null, null);
-                               return factory.app_state;
-                       }
-#else
                        get {
                                if (theFactory.app_state == null) {
                                        HttpStaticObjectsCollection app = MakeStaticCollection (GlobalAsaxCompiler.ApplicationObjects);
@@ -379,7 +347,6 @@ namespace System.Web
                                }
                                return theFactory.app_state;
                        }
-#endif
                }
 
                internal static Type AppType {
@@ -404,8 +371,8 @@ namespace System.Web
                                                if (!File.Exists (app_file))
                                                        app_file = null;
                                        }
-                       
-#if !TARGET_J2EE
+                                       BuildManager.CallPreStartMethods ();
+                                       BuildManager.CompilingTopLevelAssemblies = true;
                                        AppResourcesCompiler ac = new AppResourcesCompiler (context);
                                        ac.Compile ();
 
@@ -413,12 +380,13 @@ namespace System.Web
                                        AppWebReferencesCompiler awrc = new AppWebReferencesCompiler ();
                                        awrc.Compile ();
 #endif
-                                       
                                        // Todo: Generate profile properties assembly from Web.config here
                                
                                        AppCodeCompiler acc = new AppCodeCompiler ();
                                        acc.Compile ();
 
+                                       BuildManager.AllowReferencedAssembliesCaching = true;
+
                                        // Get the default machine *.browser files.
                                        string default_machine_browsers_path = Path.Combine (HttpRuntime.MachineConfigurationDirectory, "Browsers");
                                        default_machine_browsers_files = new string[0];
@@ -443,16 +411,10 @@ namespace System.Web
                                        if (Directory.Exists (app_browsers_path)) {
                                                app_browsers_files = Directory.GetFiles (app_browsers_path, "*.browser");
                                        }
-#endif
-
+                                       BuildManager.CompilingTopLevelAssemblies = false;
                                        app_type = BuildManager.GetPrecompiledApplicationType ();
                                        if (app_type == null && app_file != null) {
-#if TARGET_J2EE
-                                               app_file = System.Web.Util.UrlUtils.ResolveVirtualPathFromAppAbsolute("~/" + Path.GetFileName(app_file));
-                                               app_type = System.Web.J2EE.PageMapper.GetObjectType(context, app_file);
-#else
                                                app_type = BuildManager.GetCompiledType ("~/" + Path.GetFileName (app_file));
-#endif
                                                if (app_type == null) {
                                                        string msg = String.Format ("Error compiling application file ({0}).", app_file);
                                                        throw new ApplicationException (msg);
@@ -474,7 +436,12 @@ namespace System.Web
                                        // recursively for all subdirectories and adds them to the
                                        // watch set. This can take a lot of time for deep directory
                                        // trees (see bug #490497)
-                                       ThreadPool.QueueUserWorkItem (new WaitCallback (SetUpWebConfigWatchers), null);
+                                       ThreadPool.QueueUserWorkItem (delegate {
+                                               try {
+                                                       WatchLocationForRestart (String.Empty, "?eb.?onfig", true);
+                                               } catch (Exception e) {
+                                                       Console.Error.WriteLine (e);
+                                               } }, null);
 #endif
                                        
                                        needs_init = false;
@@ -489,11 +456,6 @@ namespace System.Web
                                }
                        }
                }
-
-               static void SetUpWebConfigWatchers (object state)
-               {
-                       WatchLocationForRestart (String.Empty, "?eb.?onfig", true);
-               }
                
                //
                // Multiple-threads might hit this one on startup, and we have
@@ -501,10 +463,6 @@ namespace System.Web
                //
                internal static HttpApplication GetApplication (HttpContext context)
                {
-#if TARGET_J2EE
-                       if (context.ApplicationInstance!=null)
-                               return context.ApplicationInstance;
-#endif
                        HttpApplicationFactory factory = theFactory;
                        HttpApplication app = null;
                        if (factory.app_start_needed){
@@ -709,9 +667,11 @@ namespace System.Web
 
                static void OnFileChanged(object sender, FileSystemEventArgs args)
                {
+                       if (HttpRuntime.DomainUnloading)
+                               return;
                        string name = args.Name;
                        bool isConfig = false;
-                       
+
                        if (StrUtils.EndsWith (name, "onfig", true)) {
                                if (String.Compare (Path.GetFileName (name), "web.config", true, Helpers.InvariantCulture) != 0)
                                        return;
@@ -719,6 +679,8 @@ namespace System.Web
                        } else if (StrUtils.EndsWith (name, "lobal.asax", true) && String.Compare (name, "global.asax", true, Helpers.InvariantCulture) != 0)
                                return;
 
+                       Console.WriteLine ("Change: " + name);
+
                        // {Inotify,FAM}Watcher will notify about events for a directory regardless
                        // of the filter pattern. This might be a bug in the watchers code, but
                        // since I couldn't find any rationale for the code in there I'd opted for