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:
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2003-03-17 20:36:06 +0300
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2003-03-17 20:36:06 +0300
commit29a0b2e8d7d090f2688e4c49adffca43a86fddc8 (patch)
treeb2447f4b4056953de3e24bbed5f4105aafee6b59 /mcs/class/System/System.IO/FileSystemWatcher.cs
parent468d31eee076f73731066e5210424b7d89cfdcf4 (diff)
2003-03-17 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* FileSystemWatcher.cs: added attributes and some more implementation. Now only the guts left to do. * FileSystemEventArgs.cs: * RenamedEventArgs.cs: implemented a couple of properties. svn path=/trunk/mcs/; revision=12627
Diffstat (limited to 'mcs/class/System/System.IO/FileSystemWatcher.cs')
-rw-r--r--mcs/class/System/System.IO/FileSystemWatcher.cs110
1 files changed, 86 insertions, 24 deletions
diff --git a/mcs/class/System/System.IO/FileSystemWatcher.cs b/mcs/class/System/System.IO/FileSystemWatcher.cs
index 3b93891619d..285ba501f15 100644
--- a/mcs/class/System/System.IO/FileSystemWatcher.cs
+++ b/mcs/class/System/System.IO/FileSystemWatcher.cs
@@ -1,16 +1,20 @@
//
// System.IO.FileSystemWatcher.cs
//
-// Author:
-// Tim Coleman (tim@timcoleman.com)
+// Authors:
+// Tim Coleman (tim@timcoleman.com)
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
-// Copyright (C) Tim Coleman, 2002
+// Copyright (C) Tim Coleman, 2002
+// (c) 2003 Ximian, Inc. (http://www.ximian.com)
//
using System;
using System.ComponentModel;
+using System.Threading;
namespace System.IO {
+ [DefaultEvent("Changed")]
public class FileSystemWatcher : Component, ISupportInitialize {
#region Fields
@@ -43,17 +47,19 @@ namespace System.IO {
{
}
- [MonoTODO]
public FileSystemWatcher (string path, string filter)
{
if (path == null)
- throw new ArgumentNullException ();
+ throw new ArgumentNullException ("path");
+
if (filter == null)
- throw new ArgumentNullException ();
+ throw new ArgumentNullException ("filter");
+
if (path == String.Empty)
- throw new ArgumentException ();
+ throw new ArgumentException ("Empty path", "path");
- // if the path does not exist throw an ArgumentException
+ if (!Directory.Exists (path))
+ throw new ArgumentException ("Directory does not exists", "path");
this.enableRaisingEvents = false;
this.filter = filter;
@@ -68,43 +74,81 @@ namespace System.IO {
#region Properties
+ [DefaultValue(false)]
+ [IODescription("Flag to indicate if this instance is active")]
public bool EnableRaisingEvents {
get { return enableRaisingEvents; }
set { enableRaisingEvents = value; }
}
+ [DefaultValue("*.*")]
+ [IODescription("File name filter pattern")]
+ [RecommendedAsConfigurable(true)]
public string Filter {
get { return filter; }
- set { filter = value; }
+ set {
+ filter = value;
+ if (filter == null || filter == "")
+ filter = "*.*";
+ }
}
+ [DefaultValue(false)]
+ [IODescription("Flag to indicate we want to watch subdirectories")]
public bool IncludeSubdirectories {
get { return includeSubdirectories; }
set { includeSubdirectories = value; }
}
+ [Browsable(false)]
+ [DefaultValue(8192)]
public int InternalBufferSize {
get { return internalBufferSize; }
set { internalBufferSize = value; }
}
+ [DefaultValue(NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite)]
+ [IODescription("Flag to indicate which change event we want to monitor")]
public NotifyFilters NotifyFilter {
get { return notifyFilter; }
[MonoTODO ("Perform validation.")]
set { notifyFilter = value; }
}
+ [DefaultValue("")]
+ [IODescription("The directory to monitor")]
+ [RecommendedAsConfigurable(true)]
public string Path {
get { return path; }
- [MonoTODO ("Perform validation.")]
- set { path = value; }
+ set {
+ bool exists = false;
+ Exception exc = null;
+
+ try {
+ exists = Directory.Exists (value);
+ } catch (Exception e) {
+ exists = false;
+ exc = e;
+ }
+
+ if (exc != null)
+ throw new ArgumentException ("Invalid directory name", "value", exc);
+
+ if (!exists)
+ throw new ArgumentException ("Directory does not exists", "value");
+
+ path = value;
+ }
}
+ [Browsable(false)]
public override ISite Site {
get { return site; }
set { site = value; }
}
+ [DefaultValue(null)]
+ [IODescription("The object used to marshal the event handler calls resulting from a directory change")]
public ISynchronizeInvoke SynchronizingObject {
get { return synchronizingObject; }
set { synchronizingObject = value; }
@@ -135,40 +179,49 @@ namespace System.IO {
throw new NotImplementedException ();
}
- [MonoTODO]
+ private void RaiseEvent (Delegate ev, EventArgs arg)
+ {
+ if (ev == null)
+ return;
+
+ object [] args = new object [] {this, arg};
+
+ if (synchronizingObject == null) {
+ ev.DynamicInvoke (args);
+ return;
+ }
+
+ synchronizingObject.BeginInvoke (ev, args);
+ }
+
protected void OnChanged (FileSystemEventArgs e)
{
- throw new NotImplementedException ();
+ RaiseEvent (Changed, e);
}
- [MonoTODO]
protected void OnCreated (FileSystemEventArgs e)
{
- throw new NotImplementedException ();
+ RaiseEvent (Created, e);
}
- [MonoTODO]
protected void OnDeleted (FileSystemEventArgs e)
{
- throw new NotImplementedException ();
+ RaiseEvent (Deleted, e);
}
- [MonoTODO]
protected void OnError (ErrorEventArgs e)
{
- throw new NotImplementedException ();
+ RaiseEvent (Error, e);
}
- [MonoTODO]
protected void OnRenamed (RenamedEventArgs e)
{
- throw new NotImplementedException ();
+ RaiseEvent (Renamed, e);
}
- [MonoTODO]
public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType)
{
- throw new NotImplementedException ();
+ return WaitForChanged (changeType, Timeout.Infinite);
}
[MonoTODO]
@@ -177,15 +230,24 @@ namespace System.IO {
throw new NotImplementedException ();
}
-
#endregion // Methods
#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