Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #59 from KallDrexx/FileSystemWatcher-Abstraction

Added base and wrapper for the FileSystemWatcher class
  • Loading branch information...
commit 7aed17bb1e853e915747cd0b989194c95d628bd1 2 parents 5373737 + 0dc8f36
@tathamoddie authored
View
65 System.IO.Abstractions/FileSystemWatcherBase.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+
+namespace System.IO.Abstractions
+{
+ [Serializable]
+ public abstract class FileSystemWatcherBase : IDisposable
+ {
+ public abstract bool EnableRaisingEvents { get; set; }
+ public abstract string Filter { get; set; }
+ public abstract int InternalBufferSize { get; set; }
+ public abstract NotifyFilters NotifyFilter { get; set; }
+ public abstract string Path { get; set; }
+ public abstract ISite Site { get; set; }
+ public abstract ISynchronizeInvoke SynchronizingObject { get; set; }
+ public event FileSystemEventHandler Changed;
+ public event FileSystemEventHandler Created;
+ public event FileSystemEventHandler Deleted;
+ public event ErrorEventHandler Error;
+ public event RenamedEventHandler Renamed;
+ public abstract void BeginInit();
+ public abstract void Dispose();
+ public abstract void EndInit();
+ public abstract WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType);
+ public abstract WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout);
+
+ public static implicit operator FileSystemWatcherBase(FileSystemWatcher watcher)
+ {
+ return new FileSystemWatcherWrapper(watcher);
+ }
+
+ protected void OnCreated(object sender, FileSystemEventArgs args)
+ {
+ if (Created != null)
+ Created(sender, args);
+ }
+
+ protected void OnChanged(object sender, FileSystemEventArgs args)
+ {
+ if (Changed != null)
+ Changed(sender, args);
+ }
+
+ protected void OnDeleted(object sender, FileSystemEventArgs args)
+ {
+ if (Deleted != null)
+ Deleted(sender, args);
+ }
+
+ protected void OnRenamed(object sender, RenamedEventArgs args)
+ {
+ if (Renamed != null)
+ Renamed(sender, args);
+ }
+
+ protected void OnError(object sender, ErrorEventArgs args)
+ {
+ if (Error != null)
+ Error(sender, args);
+ }
+ }
+}
View
113 System.IO.Abstractions/FileSystemWatcherWrapper.cs
@@ -0,0 +1,113 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+
+namespace System.IO.Abstractions
+{
+ [Serializable]
+ public class FileSystemWatcherWrapper : FileSystemWatcherBase
+ {
+ private readonly FileSystemWatcher watcher;
+
+ public FileSystemWatcherWrapper()
+ {
+ watcher = new FileSystemWatcher();
+ SetupEvents();
+ }
+
+ public FileSystemWatcherWrapper(string path)
+ {
+ watcher = new FileSystemWatcher(path);
+ SetupEvents();
+ }
+
+ public FileSystemWatcherWrapper(string path, string filter)
+ {
+ watcher = new FileSystemWatcher(path, filter);
+ SetupEvents();
+ }
+
+ public FileSystemWatcherWrapper(FileSystemWatcher watcher)
+ {
+ this.watcher = watcher;
+ }
+
+ public override bool EnableRaisingEvents
+ {
+ get { return watcher.EnableRaisingEvents; }
+ set { watcher.EnableRaisingEvents = value; }
+ }
+
+ public override string Filter
+ {
+ get { return watcher.Filter; }
+ set { watcher.Filter = value; }
+ }
+
+ public override int InternalBufferSize
+ {
+ get { return watcher.InternalBufferSize; }
+ set { watcher.InternalBufferSize = value; }
+ }
+
+ public override NotifyFilters NotifyFilter
+ {
+ get { return watcher.NotifyFilter; }
+ set { watcher.NotifyFilter = value; }
+ }
+
+ public override string Path
+ {
+ get { return watcher.Path; }
+ set { watcher.Path = value; }
+ }
+
+ public override ISite Site
+ {
+ get { return watcher.Site; }
+ set { watcher.Site = value; }
+ }
+
+ public override ISynchronizeInvoke SynchronizingObject
+ {
+ get { return watcher.SynchronizingObject; }
+ set { watcher.SynchronizingObject = value; }
+ }
+
+ public override void BeginInit()
+ {
+ watcher.BeginInit();
+ }
+
+ public override void Dispose()
+ {
+ watcher.Dispose();
+ }
+
+ public override void EndInit()
+ {
+ watcher.EndInit();
+ }
+
+ public override WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType)
+ {
+ return watcher.WaitForChanged(changeType);
+ }
+
+ public override WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout)
+ {
+ return watcher.WaitForChanged(changeType, timeout);
+ }
+
+ private void SetupEvents()
+ {
+ watcher.Created += OnCreated;
+ watcher.Changed += OnChanged;
+ watcher.Deleted += OnDeleted;
+ watcher.Error += OnError;
+ watcher.Renamed += OnRenamed;
+ }
+ }
+}
View
2  System.IO.Abstractions/System.IO.Abstractions.csproj
@@ -76,6 +76,8 @@
<Compile Include="FileInfoWrapper.cs" />
<Compile Include="FileSystem.cs" />
<Compile Include="FileSystemInfoBase.cs" />
+ <Compile Include="FileSystemWatcherBase.cs" />
+ <Compile Include="FileSystemWatcherWrapper.cs" />
<Compile Include="FileWrapper.cs" />
<Compile Include="FileBase.cs" />
<Compile Include="IDirectoryInfoFactory.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.