Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/System/System.IO/FileSystemWatcher.cs')
-rw-r--r--mcs/class/System/System.IO/FileSystemWatcher.cs100
1 files changed, 24 insertions, 76 deletions
diff --git a/mcs/class/System/System.IO/FileSystemWatcher.cs b/mcs/class/System/System.IO/FileSystemWatcher.cs
index c27900524d3..53e31d61f7e 100644
--- a/mcs/class/System/System.IO/FileSystemWatcher.cs
+++ b/mcs/class/System/System.IO/FileSystemWatcher.cs
@@ -45,8 +45,6 @@ namespace System.IO {
#region Fields
- bool inited;
- bool start_requested;
bool enableRaisingEvents;
string filter;
bool includeSubdirectories;
@@ -61,7 +59,6 @@ namespace System.IO {
bool disposed;
string mangledFilter;
static IFileWatcher watcher;
- object watcher_handle;
static object lockobj = new object ();
#endregion // Fields
@@ -98,8 +95,6 @@ namespace System.IO {
if (!Directory.Exists (path))
throw new ArgumentException ("Directory does not exist", "path");
- this.inited = false;
- this.start_requested = false;
this.enableRaisingEvents = false;
this.filter = filter;
this.includeSubdirectories = false;
@@ -126,39 +121,28 @@ namespace System.IO {
switch (mode) {
case 1: // windows
ok = DefaultWatcher.GetInstance (out watcher);
- watcher_handle = this;
+ //ok = WindowsWatcher.GetInstance (out watcher);
break;
case 2: // libfam
ok = FAMWatcher.GetInstance (out watcher, false);
- watcher_handle = this;
break;
case 3: // kevent
ok = KeventWatcher.GetInstance (out watcher);
- watcher_handle = this;
break;
case 4: // libgamin
ok = FAMWatcher.GetInstance (out watcher, true);
- watcher_handle = this;
break;
case 5: // inotify
ok = InotifyWatcher.GetInstance (out watcher, true);
- watcher_handle = this;
- break;
- case 6: // CoreFX
- ok = CoreFXFileSystemWatcherProxy.GetInstance (out watcher);
- watcher_handle = (watcher as CoreFXFileSystemWatcherProxy).NewWatcher (this);
break;
}
if (mode == 0 || !ok) {
if (String.Compare (managed, "disabled", true) == 0)
NullFileWatcher.GetInstance (out watcher);
- else {
+ else
DefaultWatcher.GetInstance (out watcher);
- watcher_handle = this;
- }
}
- this.inited = true;
ShowWatcherInfo ();
}
@@ -189,6 +173,9 @@ namespace System.IO {
return mangledFilter;
string filterLocal = "*.*";
+ if (!(watcher.GetType () == typeof (WindowsWatcher)))
+ filterLocal = "*";
+
return filterLocal;
}
}
@@ -223,12 +210,6 @@ namespace System.IO {
public bool EnableRaisingEvents {
get { return enableRaisingEvents; }
set {
- if (disposed)
- throw new ObjectDisposedException (GetType().Name);
-
- start_requested = true;
- if (!inited)
- return;
if (value == enableRaisingEvents)
return; // Do nothing
@@ -237,7 +218,6 @@ namespace System.IO {
Start ();
} else {
Stop ();
- start_requested = false;
}
}
}
@@ -252,7 +232,7 @@ namespace System.IO {
if (value == null || value == "")
value = "*.*";
- if (!string.Equals(filter, value, PathInternal.StringComparison)) {
+ if (filter != value) {
filter = value;
pattern = null;
mangledFilter = null;
@@ -284,8 +264,8 @@ namespace System.IO {
if (internalBufferSize == value)
return;
- if (value < 4096)
- value = 4096;
+ if (value < 4196)
+ value = 4196;
internalBufferSize = value;
if (enableRaisingEvents) {
@@ -319,11 +299,7 @@ namespace System.IO {
public string Path {
get { return path; }
set {
- if (disposed)
- throw new ObjectDisposedException (GetType().Name);
-
- value = (value == null) ? string.Empty : value;
- if (string.Equals(path, value, PathInternal.StringComparison))
+ if (path == value)
return;
bool exists = false;
@@ -336,10 +312,10 @@ namespace System.IO {
}
if (exc != null)
- throw new ArgumentException(SR.Format(SR.InvalidDirName, value), nameof(Path));
+ throw new ArgumentException ("Invalid directory name", "value", exc);
if (!exists)
- throw new ArgumentException(SR.Format(SR.InvalidDirName_NotExists, value), nameof(Path));
+ throw new ArgumentException ("Directory does not exist", "value");
path = value;
fullpath = null;
@@ -353,12 +329,7 @@ namespace System.IO {
[Browsable(false)]
public override ISite Site {
get { return base.Site; }
- set
- {
- base.Site = value;
- if (Site != null && Site.DesignMode)
- this.EnableRaisingEvents = true;
- }
+ set { base.Site = value; }
}
[DefaultValue(null)]
@@ -376,41 +347,27 @@ namespace System.IO {
public void BeginInit ()
{
// Not necessary in Mono
- // but if called, EndInit() must be called
- inited = false;
}
protected override void Dispose (bool disposing)
{
- if (disposed)
- return;
-
- try {
- watcher.StopDispatching (watcher_handle);
- watcher.Dispose (watcher_handle);
- } catch (Exception) { }
-
- watcher_handle = null;
- watcher = null;
+ if (!disposed) {
+ disposed = true;
+ Stop ();
+ }
- disposed = true;
base.Dispose (disposing);
- GC.SuppressFinalize (this);
}
~FileSystemWatcher ()
{
- if (disposed)
- return;
-
- Dispose (false);
+ disposed = true;
+ Stop ();
}
public void EndInit ()
{
- inited = true;
- if (start_requested)
- this.EnableRaisingEvents = true;
+ // Not necessary in Mono
}
enum EventType {
@@ -427,13 +384,13 @@ namespace System.IO {
foreach (var target in ev.GetInvocationList()) {
switch (evtype) {
case EventType.RenameEvent:
- ((RenamedEventHandler)target).Invoke (this, (RenamedEventArgs)arg);
+ ((RenamedEventHandler)target).BeginInvoke (this, (RenamedEventArgs)arg, null, null);
break;
case EventType.ErrorEvent:
- ((ErrorEventHandler)target).Invoke (this, (ErrorEventArgs)arg);
+ ((ErrorEventHandler)target).BeginInvoke (this, (ErrorEventArgs)arg, null, null);
break;
case EventType.FileSystemEvent:
- ((FileSystemEventHandler)target).Invoke (this, (FileSystemEventArgs)arg);
+ ((FileSystemEventHandler)target).BeginInvoke (this, (FileSystemEventArgs)arg, null, null);
break;
}
}
@@ -546,20 +503,12 @@ namespace System.IO {
void Start ()
{
- if (disposed)
- return;
- if (watcher_handle == null)
- return;
- watcher.StartDispatching (watcher_handle);
+ watcher.StartDispatching (this);
}
void Stop ()
{
- if (disposed)
- return;
- if (watcher_handle == null)
- return;
- watcher.StopDispatching (watcher_handle);
+ watcher.StopDispatching (this);
}
#endregion // Methods
@@ -588,7 +537,6 @@ namespace System.IO {
/* 3 -> Kevent */
/* 4 -> gamin */
/* 5 -> inotify */
- /* 6 -> CoreFX */
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern int InternalSupportsFSW ();
}