Merge pull request #463 from strawd/concurrent-requests
[mono.git] / mcs / class / System / System.IO / FileSystemWatcher.cs
index 6226aa012e6f6342356130a9975558969f0b9ec2..43d3c2f362e1f681a13c46a53265585006de6e6a 100644 (file)
@@ -32,6 +32,7 @@
 //
 
 using System.ComponentModel;
+using System.Diagnostics;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Security.Permissions;
@@ -39,9 +40,7 @@ using System.Threading;
 
 namespace System.IO {
        [DefaultEvent("Changed")]
-#if NET_2_0
        [IODescription ("")]
-#endif
        public class FileSystemWatcher : Component, ISupportInitialize {
 
                #region Fields
@@ -94,7 +93,7 @@ namespace System.IO {
                                throw new ArgumentException ("Empty path", "path");
 
                        if (!Directory.Exists (path))
-                               throw new ArgumentException ("Directory does not exists", "path");
+                               throw new ArgumentException ("Directory does not exist", "path");
 
                        this.enableRaisingEvents = false;
                        this.filter = filter;
@@ -117,7 +116,7 @@ namespace System.IO {
                                int mode = 0;
                                if (managed == null)
                                        mode = InternalSupportsFSW ();
-
+                               
                                bool ok = false;
                                switch (mode) {
                                case 1: // windows
@@ -138,11 +137,23 @@ namespace System.IO {
                                        break;
                                }
 
-                               if (mode == 0 || !ok)
-                                       DefaultWatcher.GetInstance (out watcher);
+                               if (mode == 0 || !ok) {
+                                       if (String.Compare (managed, "disabled", true) == 0)
+                                               NullFileWatcher.GetInstance (out watcher);
+                                       else
+                                               DefaultWatcher.GetInstance (out watcher);
+                               }
+
+                               ShowWatcherInfo ();
                        }
                }
 
+               [Conditional ("DEBUG"), Conditional ("TRACE")]
+               void ShowWatcherInfo ()
+               {
+                       Console.WriteLine ("Watcher implementation: {0}", watcher != null ? watcher.GetType ().ToString () : "<none>");
+               }
+               
                #endregion // Constructors
 
                #region Properties
@@ -172,7 +183,10 @@ namespace System.IO {
                internal SearchPattern2 Pattern {
                        get {
                                if (pattern == null) {
-                                       pattern = new SearchPattern2 (MangledFilter);
+                                       if (watcher.GetType () == typeof (KeventWatcher))
+                                               pattern = new SearchPattern2 (MangledFilter, true); //assume we want to ignore case (OS X)
+                                       else
+                                               pattern = new SearchPattern2 (MangledFilter);
                                }
                                return pattern;
                        }
@@ -301,7 +315,7 @@ namespace System.IO {
                                        throw new ArgumentException ("Invalid directory name", "value", exc);
 
                                if (!exists)
-                                       throw new ArgumentException ("Directory does not exists", "value");
+                                       throw new ArgumentException ("Directory does not exist", "value");
 
                                path = value;
                                fullpath = null;
@@ -320,9 +334,7 @@ namespace System.IO {
 
                [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 synchronizingObject; }
                        set { synchronizingObject = value; }
@@ -332,10 +344,9 @@ namespace System.IO {
 
                #region Methods
        
-               [MonoTODO]
                public void BeginInit ()
                {
-                       throw new NotImplementedException (); 
+                       // Not necessary in Mono
                }
 
                protected override void Dispose (bool disposing)
@@ -354,10 +365,9 @@ namespace System.IO {
                        Stop ();
                }
                
-               [MonoTODO]
                public void EndInit ()
                {
-                       throw new NotImplementedException (); 
+                       // Not necessary in Mono
                }
 
                enum EventType {
@@ -371,16 +381,18 @@ namespace System.IO {
                                return;
 
                        if (synchronizingObject == null) {
-                               switch (evtype) {
-                               case EventType.RenameEvent:
-                                       ((RenamedEventHandler)ev).BeginInvoke (this, (RenamedEventArgs) arg, null, null);
-                                       break;
-                               case EventType.ErrorEvent:
-                                       ((ErrorEventHandler)ev).BeginInvoke (this, (ErrorEventArgs) arg, null, null);
-                                       break;
-                               case EventType.FileSystemEvent:
-                                       ((FileSystemEventHandler)ev).BeginInvoke (this, (FileSystemEventArgs) arg, null, null);
-                                       break;
+                               foreach (var target in ev.GetInvocationList()) {
+                                       switch (evtype) {
+                                       case EventType.RenameEvent:
+                                               ((RenamedEventHandler)target).BeginInvoke (this, (RenamedEventArgs)arg, null, null);
+                                               break;
+                                       case EventType.ErrorEvent:
+                                               ((ErrorEventHandler)target).BeginInvoke (this, (ErrorEventArgs)arg, null, null);
+                                               break;
+                                       case EventType.FileSystemEvent:
+                                               ((FileSystemEventHandler)target).BeginInvoke (this, (FileSystemEventArgs)arg, null, null);
+                                               break;
+                                       }
                                }
                                return;
                        }
@@ -440,6 +452,11 @@ namespace System.IO {
                        return result;
                }
 
+               internal void DispatchErrorEvents (ErrorEventArgs args)
+               {
+                       OnError (args);
+               }
+
                internal void DispatchEvents (FileAction act, string filename, ref RenamedEventArgs renamed)
                {
                        if (waiting) {