Author: mhabersack
Date: 2007-08-31 18:23:30 -0400 (Fri, 31 Aug 2007)
New Revision: 85155
Modified:
trunk/mcs/class/System.Web/System.Web/ChangeLog
trunk/mcs/class/System.Web/System.Web/HttpApplicationFactory.cs
trunk/mcs/class/System.Web/System.Web/HttpRuntime.cs
Log:
2007-09-01 Marek Habersack <[EMAIL PROTECTED]>
* HttpRuntime.cs: rewrote the app_offline.htm support. It now uses
filesystem watchers instead of checking for existence of the
file(s) at the beginning of every request. No performance penalty
that way.
Modified: trunk/mcs/class/System.Web/System.Web/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web/ChangeLog 2007-08-31 21:11:54 UTC
(rev 85154)
+++ trunk/mcs/class/System.Web/System.Web/ChangeLog 2007-08-31 22:23:30 UTC
(rev 85155)
@@ -1,3 +1,10 @@
+2007-09-01 Marek Habersack <[EMAIL PROTECTED]>
+
+ * HttpRuntime.cs: rewrote the app_offline.htm support. It now uses
+ filesystem watchers instead of checking for existence of the
+ file(s) at the beginning of every request. No performance penalty
+ that way.
+
2007-08-31 Marek Habersack <[EMAIL PROTECTED]>
* HttpApplicationFactory.cs: added methods to enable/disable
Modified: trunk/mcs/class/System.Web/System.Web/HttpApplicationFactory.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpApplicationFactory.cs
2007-08-31 21:11:54 UTC (rev 85154)
+++ trunk/mcs/class/System.Web/System.Web/HttpApplicationFactory.cs
2007-08-31 22:23:30 UTC (rev 85155)
@@ -69,8 +69,6 @@
#else
static HttpApplicationFactory theFactory = new
HttpApplicationFactory();
#endif
-
-
MethodInfo session_end;
bool needs_init = true;
bool app_start_needed = true;
Modified: trunk/mcs/class/System.Web/System.Web/HttpRuntime.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpRuntime.cs 2007-08-31
21:11:54 UTC (rev 85154)
+++ trunk/mcs/class/System.Web/System.Web/HttpRuntime.cs 2007-08-31
22:23:30 UTC (rev 85155)
@@ -287,75 +287,109 @@
#if NET_2_0
static readonly string[] app_offline_files =
{"app_offline.htm", "App_Offline.htm", "APP_OFFLINE.HTM"};
- static FileSystemWatcher app_offline_watcher;
+ static FileSystemWatcher[] app_offline_watchers;
+ static string app_offline_file;
+
+ static bool AppIsOffline (HttpContext context)
+ {
+ if (!HttpApplicationFactory.ApplicationDisabled ||
app_offline_file == null)
+ return false;
+ HttpResponse response = context.Response;
+ response.Clear ();
+ response.ContentType = "text/html";
+ response.ExpiresAbsolute = DateTime.UtcNow;
+ response.TransmitFile (app_offline_file, true);
+
+ context.Request.ReleaseResources ();
+ context.Response.ReleaseResources ();
+ HttpContext.Current = null;
+
+ return true;
+ }
+
static void AppOfflineFileRenamed (object sender,
RenamedEventArgs args)
{
AppOfflineFileChanged (sender, args);
}
-
+
static void AppOfflineFileChanged (object sender,
FileSystemEventArgs args)
{
lock (appOfflineLock) {
- HttpApplicationFactory.DisableWatchers ();
- app_offline_watcher.EnableRaisingEvents = false;
+ bool offline;
- // Restart application
- HttpRuntime.UnloadAppDomain();
+ switch (args.ChangeType) {
+ case WatcherChangeTypes.Created:
+ case WatcherChangeTypes.Changed:
+ offline = true;
+ break;
+
+ case WatcherChangeTypes.Deleted:
+ offline = false;
+ break;
+
+ case WatcherChangeTypes.Renamed:
+ RenamedEventArgs rargs = args
as RenamedEventArgs;
+
+ if (rargs != null &&
+ String.Compare (rargs.Name,
"app_offline.htm", StringComparison.OrdinalIgnoreCase) == 0)
+ offline = true;
+ else
+ offline = false;
+ break;
+
+ default:
+ offline = false;
+ break;
+ }
+ SetOfflineMode (offline, args.FullPath);
}
}
+
+ static void SetOfflineMode (bool offline, string filePath)
+ {
+ if (!offline) {
+ app_offline_file = null;
+ if (HttpApplicationFactory.ApplicationDisabled)
+ HttpRuntime.UnloadAppDomain ();
+ } else {
+ app_offline_file = filePath;
+ HttpApplicationFactory.DisableWatchers ();
+ HttpApplicationFactory.ApplicationDisabled =
true;
+ }
+ }
- static bool AppIsOffline (HttpContext context)
+ static void SetupOfflineWatch ()
{
- string app_path =
context.Request.PhysicalApplicationPath;
- string aof_path = null;
- bool haveOfflineFile = false;
+ lock (appOfflineLock) {
+ FileSystemEventHandler seh = new
FileSystemEventHandler (AppOfflineFileChanged);
+ RenamedEventHandler reh = new
RenamedEventHandler (AppOfflineFileRenamed);
- foreach (string aof in app_offline_files) {
- aof_path = Path.Combine (app_path, aof);
- if (File.Exists (aof_path)) {
- haveOfflineFile = true;
- break;
- }
- }
+ string app_dir = AppDomainAppPath;
+ ArrayList watchers = new ArrayList ();
+ FileSystemWatcher watcher;
+ string offlineFile = null, tmp;
+
+ foreach (string f in app_offline_files) {
+ watcher = new FileSystemWatcher ();
+ watcher.Path = Path.GetDirectoryName
(app_dir);
+ watcher.Filter = Path.GetFileName (f);
+ watcher.NotifyFilter |=
NotifyFilters.Size;
+ watcher.Deleted += seh;
+ watcher.Changed += seh;
+ watcher.Renamed += reh;
+ watcher.EnableRaisingEvents = true;
+
+ watchers.Add (watcher);
- lock (appOfflineLock) {
- if (!haveOfflineFile) {
- if
(HttpApplicationFactory.ApplicationDisabled) {
-
HttpApplicationFactory.ApplicationDisabled = false;
-
HttpApplicationFactory.EnableWatchers ();
- }
-
- return false;
+ tmp = Path.Combine (app_dir, f);
+ if (File.Exists (tmp))
+ offlineFile = tmp;
}
- HttpApplicationFactory.ApplicationDisabled =
true;
- HttpApplicationFactory.DisableWatchers ();
-
- FileSystemEventHandler seh = new
FileSystemEventHandler (AppOfflineFileChanged);
- RenamedEventHandler reh = new
RenamedEventHandler (AppOfflineFileRenamed);
-
- app_offline_watcher = new FileSystemWatcher ();
- app_offline_watcher.Path =
Path.GetDirectoryName (aof_path);
- app_offline_watcher.Filter = Path.GetFileName
(aof_path);
- app_offline_watcher.NotifyFilter |=
NotifyFilters.Size;
- app_offline_watcher.Deleted += seh;
- app_offline_watcher.Changed += seh;
- app_offline_watcher.Renamed += reh;
- app_offline_watcher.EnableRaisingEvents = true;
+ if (offlineFile != null)
+ SetOfflineMode (true, offlineFile);
}
-
- HttpResponse response = context.Response;
- response.Clear ();
- response.ContentType = "text/html";
- response.ExpiresAbsolute = DateTime.UtcNow;
- response.TransmitFile (aof_path, true);
-
- context.Request.ReleaseResources ();
- context.Response.ReleaseResources ();
- HttpContext.Current = null;
-
- return true;
}
#endif
@@ -363,10 +397,12 @@
{
HttpContext context = new HttpContext
((HttpWorkerRequest) o);
HttpContext.Current = context;
-
bool error = false;
#if !TARGET_J2EE
if (firstRun) {
+#if NET_2_0
+ SetupOfflineWatch ();
+#endif
firstRun = false;
if (initialException != null) {
FinishWithException
((HttpWorkerRequest) o, new HttpException ("Initial exception",
initialException));
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches