Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / System / System.IO / FileSystemWatcher.cs
index 2dba82cd9e6e0de027c36f8eef029c5aeb05d39b..125f07805f9403f212fe5789357ff92bd0d02f33 100644 (file)
@@ -7,7 +7,7 @@
 //
 // Copyright (C) Tim Coleman, 2002 
 // (c) 2003 Ximian, Inc. (http://www.ximian.com)
-// (c) 2004 Novell, Inc. (http://www.novell.com)
+// Copyright (C) 2004, 2006 Novell, Inc (http://www.novell.com)
 //
 
 //
@@ -32,6 +32,7 @@
 //
 
 using System.ComponentModel;
+using System.Diagnostics;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Security.Permissions;
@@ -39,6 +40,7 @@ using System.Threading;
 
 namespace System.IO {
        [DefaultEvent("Changed")]
+       [IODescription ("")]
        public class FileSystemWatcher : Component, ISupportInitialize {
 
                #region Fields
@@ -91,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;
@@ -114,7 +116,7 @@ namespace System.IO {
                                int mode = 0;
                                if (managed == null)
                                        mode = InternalSupportsFSW ();
-
+                               
                                bool ok = false;
                                switch (mode) {
                                case 1: // windows
@@ -135,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
@@ -298,7 +312,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;
@@ -317,6 +331,7 @@ namespace System.IO {
 
                [DefaultValue(null)]
                [IODescription("The object used to marshal the event handler calls resulting from a directory change")]
+               [Browsable (false)]
                public ISynchronizeInvoke SynchronizingObject {
                        get { return synchronizingObject; }
                        set { synchronizingObject = value; }
@@ -326,10 +341,9 @@ namespace System.IO {
 
                #region Methods
        
-               [MonoTODO]
                public void BeginInit ()
                {
-                       throw new NotImplementedException (); 
+                       // Not necessary in Mono
                }
 
                protected override void Dispose (bool disposing)
@@ -348,10 +362,9 @@ namespace System.IO {
                        Stop ();
                }
                
-               [MonoTODO]
                public void EndInit ()
                {
-                       throw new NotImplementedException (); 
+                       // Not necessary in Mono
                }
 
                enum EventType {
@@ -365,19 +378,16 @@ namespace System.IO {
                                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);
-                                       }
+                               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;
                                }
                                return;
                        }