Ver código fonte

Implement FileSystemWatcher stub and remove redundand TARGET_JVM ifdefs

svn path=/trunk/mcs/; revision=71414
Konstantin Triger 19 anos atrás
pai
commit
0930bf4f4f

+ 0 - 12
mcs/class/System.Web/System.Web.Caching/CacheDependency.cs

@@ -50,9 +50,7 @@ namespace System.Web.Caching
 		CacheDependency dependency;
 		DateTime start;
 		Cache cache;
-#if !TARGET_JVM
 		FileSystemWatcher[] watchers;
-#endif
 		bool hasChanged;
 #if NET_2_0
 		bool used;
@@ -96,7 +94,6 @@ namespace System.Web.Caching
 		
 		public CacheDependency (string[] filenames, string[] cachekeys, CacheDependency dependency, DateTime start)
 		{
-#if !TARGET_JVM
 			if (filenames != null) {
 				watchers = new FileSystemWatcher [filenames.Length];
 				for (int n=0; n<filenames.Length; n++) {
@@ -119,7 +116,6 @@ namespace System.Web.Caching
 					watchers [n] = watcher;
 				}
 			}
-#endif
 			this.cachekeys = cachekeys;
 			this.dependency = dependency;
 			if (dependency != null)
@@ -131,14 +127,12 @@ namespace System.Web.Caching
 		public virtual string GetUniqueID ()
 		{
 			StringBuilder sb = new StringBuilder ();
-#if !TARGET_JVM
 			lock (locker) {
 				if (watchers != null)
 					foreach (FileSystemWatcher fsw in watchers)
 						if (fsw != null && fsw.Path != null && fsw.Path.Length != 0)
 							sb.AppendFormat ("_{0}", fsw.Path);
 			}
-#endif
 
 			if (cachekeys != null)
 				foreach (string key in cachekeys)
@@ -147,7 +141,6 @@ namespace System.Web.Caching
 		}
 #endif
 		
-#if !TARGET_JVM
 		void OnChanged (object sender, FileSystemEventArgs args)
 		{
 			if (DateTime.Now < start)
@@ -170,11 +163,6 @@ namespace System.Web.Caching
 				watchers = null;
 			}
 		}
-#else
-		void DisposeWatchers ()
-		{
-		}
-#endif
 		public void Dispose ()
 		{
 			DisposeWatchers ();

+ 179 - 11
mcs/class/System.Web/System.Web.J2EE/J2EEUtils.cs

@@ -28,6 +28,8 @@ using System.Web.Util;
 using System.IO;
 using [email protected];
 using vmw.common;
+using System.ComponentModel;
+using System.Threading;
 
 namespace System.Web.J2EE
 {
@@ -87,20 +89,186 @@ namespace System.Web.J2EE
 	}
 }
 
-#if !CODEDOM_SUPPORT
-//stubs for CodeDom symbols
-namespace System.CodeDom
+#region FileSystemWatcher Stub
+
+namespace System.IO
 {
-	public class CodeObject
+	[DefaultEvent ("Changed")]
+#if NET_2_0
+	[IODescription ("")]
+#endif
+	public class FileSystemWatcher : Component, ISupportInitialize
 	{
-		protected CodeObject () { }
+		public FileSystemWatcher ()
+			: this (String.Empty) {
+		}
 
-		public System.Collections.IDictionary UserData { get { throw new NotSupportedException (); } }
-	}
+		public FileSystemWatcher (string path)
+			: this (path, "*.*") {
+		}
 
-	public class CodeExpression : CodeObject
-	{
-		protected CodeExpression () { }
+		public FileSystemWatcher (string path, string filter) {
+		}
+
+		#region Properties
+
+		[DefaultValue (false)]
+		[IODescription ("Flag to indicate if this instance is active")]
+		public bool EnableRaisingEvents {
+			get { return false; }
+			set { }
+		}
+
+		[DefaultValue ("*.*")]
+		[IODescription ("File name filter pattern")]
+		[RecommendedAsConfigurable (true)]
+		[TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
+		public string Filter {
+			get { return "*.*"; }
+			set { }
+		}
+
+		[DefaultValue (false)]
+		[IODescription ("Flag to indicate we want to watch subdirectories")]
+		public bool IncludeSubdirectories {
+			get { return false; }
+			set { }
+		}
+
+		[Browsable (false)]
+		[DefaultValue (8192)]
+		public int InternalBufferSize {
+			get { return 8192; }
+			set { }
+		}
+
+		[DefaultValue (NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite)]
+		[IODescription ("Flag to indicate which change event we want to monitor")]
+		public NotifyFilters NotifyFilter {
+			get { return NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite; }
+			set { }
+		}
+
+		[DefaultValue ("")]
+		[IODescription ("The directory to monitor")]
+		[RecommendedAsConfigurable (true)]
+		[TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
+		[Editor ("System.Diagnostics.Design.FSWPathEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
+		public string Path {
+			get { return String.Empty; }
+			set { }
+		}
+
+		[DefaultValue (null)]
+		[IODescription ("The object used to marshal the event handler calls resulting from a directory change")]
+#if NET_2_0
+		[Browsable (false)]
+#endif
+		public ISynchronizeInvoke SynchronizingObject {
+			get { return null; }
+			set { }
+		}
+
+		#endregion // Properties
+
+		#region Methods
+
+		protected override void Dispose (bool disposing) {
+			base.Dispose (disposing);
+		}
+
+		enum EventType
+		{
+			FileSystemEvent,
+			ErrorEvent,
+			RenameEvent
+		}
+
+		private void RaiseEvent (Delegate ev, EventArgs arg, EventType evtype) {
+			if (ev == null)
+				return;
+
+			if (SynchronizingObject == null) {
+				Delegate [] delegates = ev.GetInvocationList ();
+				if (evtype == EventType.RenameEvent) {
+					foreach (RenamedEventHandler d in delegates) {
+						d.BeginInvoke (this, (RenamedEventArgs) arg, null, null);
+					}
+				}
+				else if (evtype == EventType.ErrorEvent) {
+					foreach (ErrorEventHandler d in delegates) {
+						d.BeginInvoke (this, (ErrorEventArgs) arg, null, null);
+					}
+				}
+				else {
+					foreach (FileSystemEventHandler d in delegates) {
+						d.BeginInvoke (this, (FileSystemEventArgs) arg, null, null);
+					}
+				}
+				return;
+			}
+
+			SynchronizingObject.BeginInvoke (ev, new object [] { this, arg });
+		}
+
+		protected void OnChanged (FileSystemEventArgs e) {
+			RaiseEvent (Changed, e, EventType.FileSystemEvent);
+		}
+
+		protected void OnCreated (FileSystemEventArgs e) {
+			RaiseEvent (Created, e, EventType.FileSystemEvent);
+		}
+
+		protected void OnDeleted (FileSystemEventArgs e) {
+			RaiseEvent (Deleted, e, EventType.FileSystemEvent);
+		}
+
+		protected void OnError (ErrorEventArgs e) {
+			RaiseEvent (Error, e, EventType.ErrorEvent);
+		}
+
+		protected void OnRenamed (RenamedEventArgs e) {
+			RaiseEvent (Renamed, e, EventType.RenameEvent);
+		}
+
+		public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType) {
+			return WaitForChanged (changeType, Timeout.Infinite);
+		}
+
+		public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType, int timeout) {
+			return new WaitForChangedResult ();
+		}
+
+		#endregion
+
+		#region Events and Delegates
+
+		[IODescription ("Occurs when a file/directory change matches the filter")]
+		public event FileSystemEventHandler Changed;
+
+		[IODescription ("Occurs when a file/directory creation matches the filter")]
+		public event FileSystemEventHandler Created;
+
+		[IODescription ("Occurs when a file/directory deletion matches the filter")]
+		public event FileSystemEventHandler Deleted;
+
+		[Browsable (false)]
+		public event ErrorEventHandler Error;
+
+		[IODescription ("Occurs when a file/directory rename matches the filter")]
+		public event RenamedEventHandler Renamed;
+
+		#endregion // Events and Delegates
+
+		#region ISupportInitialize Members
+
+		public void BeginInit () {
+		}
+
+		public void EndInit () {
+		}
+
+		#endregion
 	}
 }
-#endif
+#endregion

+ 3 - 9
mcs/class/System.Web/System.Web/HttpApplicationFactory.cs

@@ -76,10 +76,8 @@ namespace System.Web {
 		Type app_type;
 		HttpApplicationState app_state;
 		Hashtable app_event_handlers;
-#if !TARGET_JVM
 		static ArrayList watchers = new ArrayList();
 		static object watchers_lock = new object();
-#endif
 		Stack available = new Stack ();
 		Stack available_for_end = new Stack ();
 		
@@ -201,7 +199,6 @@ namespace System.Web {
 			theFactory.FireOnAppEnd ();
 		}
 
-#if !TARGET_JVM
 		static FileSystemWatcher CreateWatcher (string file, FileSystemEventHandler hnd, RenamedEventHandler reh)
 		{
 			FileSystemWatcher watcher = new FileSystemWatcher ();
@@ -218,7 +215,6 @@ namespace System.Web {
 
 			return watcher;
 		}
-#endif
 
 		internal static void AttachEvents (HttpApplication app)
 		{
@@ -394,7 +390,6 @@ namespace System.Web {
 						app_state = new HttpApplicationState ();
 					}
 
-#if !TARGET_JVM
 					app_file = "Global.asax";
 					if (!File.Exists(Path.Combine(physical_app_path, app_file)))
 						app_file =  "global.asax";
@@ -407,14 +402,15 @@ namespace System.Web {
 						WatchLocationForRestart("web.config");
 					else if (File.Exists(Path.Combine(physical_app_path, "Web.Config")))
 						WatchLocationForRestart("Web.Config");
-#endif
 					needs_init = false;
 #if NET_2_0
 				} catch (Exception) {
+#if !TARGET_J2EE
 					if (BuildManager.CodeAssemblies != null)
 						BuildManager.CodeAssemblies.Clear ();
 					if (BuildManager.TopLevelAssemblies != null)
 						BuildManager.TopLevelAssemblies.Clear ();
+#endif
 					if (WebConfigurationManager.ExtraAssemblies != null)
 						WebConfigurationManager.ExtraAssemblies.Clear ();
 					throw;
@@ -443,13 +439,11 @@ namespace System.Web {
 				factory.InitType (context);
 				lock (factory) {
 					if (factory.app_start_needed) {
-#if !TARGET_JVM
 						WatchLocationForRestart("bin", "*.dll");
-#if NET_2_0 && !TARGET_J2EE
+#if NET_2_0
 			                        WatchLocationForRestart("App_Code", "");
 			                        WatchLocationForRestart("App_Browsers", "");
 			                        WatchLocationForRestart("App_GlobalResources", "");
-#endif
 #endif
 			                        app = factory.FireOnAppStart (context);
 						factory.app_start_needed = false;

+ 0 - 8
mcs/class/System.Web/System.Web/XmlSiteMapProvider.cs

@@ -47,9 +47,7 @@ namespace System.Web
 		bool building;
 		string file;
 		SiteMapNode root = null;
-#if !TARGET_JVM // Java platform does not support file notifications
 		FileSystemWatcher watcher;
-#endif
 
 		protected internal override void AddNode (SiteMapNode node, SiteMapNode parentNode)
 		{
@@ -168,10 +166,8 @@ namespace System.Web
 
 		protected virtual void Dispose (bool disposing)
 		{
-#if !TARGET_JVM // Java platform does not support file notifications
 			if (disposing)
 				watcher.Dispose ();
-#endif
 		}
 
 		public void Dispose ()
@@ -203,7 +199,6 @@ namespace System.Web
 			else
 				file = UrlUtils.ResolvePhysicalPathFromAppAbsolute (file);
 
-#if !TARGET_JVM // Java platform does not support file notifications
 			if (File.Exists (file)) {
 				watcher = new FileSystemWatcher ();
 				watcher.Path = Path.GetFullPath (Path.GetDirectoryName (file));
@@ -211,7 +206,6 @@ namespace System.Web
 				watcher.Changed += new FileSystemEventHandler (OnFileChanged);
 				watcher.EnableRaisingEvents = true;
 			}
-#endif
 		}
 
 		protected override void RemoveNode (SiteMapNode node)
@@ -224,12 +218,10 @@ namespace System.Web
 		{
 			throw new NotImplementedException ();
 		}
-#if !TARGET_JVM
 		void OnFileChanged (object sender, FileSystemEventArgs args)
 		{
 			Clear ();
 		}
-#endif
 		public override SiteMapNode RootNode {
 			get {
 				BuildSiteMap ();