-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathFileSystemWatcherWrapper.cs
More file actions
214 lines (182 loc) · 6.39 KB
/
FileSystemWatcherWrapper.cs
File metadata and controls
214 lines (182 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System.ComponentModel;
namespace System.IO.Abstractions
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class FileSystemWatcherWrapper : FileSystemWatcherBase
{
#if FEATURE_SERIALIZABLE
[NonSerialized]
#endif
private readonly FileSystemWatcher watcher;
/// <inheritdoc />
public FileSystemWatcherWrapper(IFileSystem fileSystem)
: this(fileSystem, new FileSystemWatcher())
{
// do nothing
}
/// <inheritdoc />
public FileSystemWatcherWrapper(IFileSystem fileSystem, string path)
: this(fileSystem, new FileSystemWatcher(path))
{
// do nothing
}
/// <inheritdoc />
public FileSystemWatcherWrapper(IFileSystem fileSystem, string path, string filter)
: this(fileSystem, new FileSystemWatcher(path, filter))
{
// do nothing
}
/// <inheritdoc />
public FileSystemWatcherWrapper(IFileSystem fileSystem, FileSystemWatcher watcher)
{
FileSystem = fileSystem;
this.watcher = watcher ?? throw new ArgumentNullException(nameof(watcher));
this.watcher.Created += OnCreated;
this.watcher.Changed += OnChanged;
this.watcher.Deleted += OnDeleted;
this.watcher.Error += OnError;
this.watcher.Renamed += OnRenamed;
}
/// <inheritdoc />
public override IFileSystem FileSystem { get; }
/// <inheritdoc />
public override bool IncludeSubdirectories
{
get { return watcher.IncludeSubdirectories; }
set { watcher.IncludeSubdirectories = value; }
}
/// <inheritdoc />
public override IContainer Container
=> watcher.Container;
/// <inheritdoc />
public override bool EnableRaisingEvents
{
get { return watcher.EnableRaisingEvents; }
set { watcher.EnableRaisingEvents = value; }
}
/// <inheritdoc />
public override string Filter
{
get { return watcher.Filter; }
set { watcher.Filter = value; }
}
#if FEATURE_FILE_SYSTEM_WATCHER_FILTERS
/// <inheritdoc />
public override Collections.ObjectModel.Collection<string> Filters
{
get { return watcher.Filters; }
}
#endif
/// <inheritdoc />
public override int InternalBufferSize
{
get { return watcher.InternalBufferSize; }
set { watcher.InternalBufferSize = value; }
}
/// <inheritdoc />
public override NotifyFilters NotifyFilter
{
get { return watcher.NotifyFilter; }
set { watcher.NotifyFilter = value; }
}
/// <inheritdoc />
public override string Path
{
get { return watcher.Path; }
set { watcher.Path = value; }
}
/// <inheritdoc />
public override ISite Site
{
get { return watcher.Site; }
set { watcher.Site = value; }
}
/// <inheritdoc />
public override ISynchronizeInvoke SynchronizingObject
{
get { return watcher.SynchronizingObject; }
set { watcher.SynchronizingObject = value; }
}
/// <inheritdoc />
public override void BeginInit()
{
watcher.BeginInit();
}
/// <inheritdoc />
public override void Dispose(bool disposing)
{
if (disposing)
{
watcher.Created -= OnCreated;
watcher.Changed -= OnChanged;
watcher.Deleted -= OnDeleted;
watcher.Error -= OnError;
watcher.Renamed -= OnRenamed;
watcher.Dispose();
}
base.Dispose(disposing);
}
/// <inheritdoc />
public override void EndInit()
{
watcher.EndInit();
}
/// <inheritdoc />
public override IWaitForChangedResult WaitForChanged(WatcherChangeTypes changeType)
{
return new WaitForChangedResultWrapper(watcher.WaitForChanged(changeType));
}
/// <inheritdoc />
public override IWaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout)
{
return new WaitForChangedResultWrapper(watcher.WaitForChanged(changeType, timeout));
}
#if FEATURE_FILE_SYSTEM_WATCHER_WAIT_WITH_TIMESPAN
/// <inheritdoc />
public override IWaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, TimeSpan timeout)
{
return new WaitForChangedResultWrapper(watcher.WaitForChanged(changeType, timeout));
}
#endif
private readonly struct WaitForChangedResultWrapper
: IWaitForChangedResult, IEquatable<WaitForChangedResultWrapper>
{
private readonly WaitForChangedResult instance;
public WaitForChangedResultWrapper(WaitForChangedResult instance)
{
this.instance = instance;
}
/// <inheritdoc cref="IWaitForChangedResult.ChangeType" />
public WatcherChangeTypes ChangeType
=> instance.ChangeType;
/// <inheritdoc cref="IWaitForChangedResult.Name" />
public string Name
=> instance.Name;
/// <inheritdoc cref="IWaitForChangedResult.OldName" />
public string OldName
=> instance.OldName;
/// <inheritdoc cref="IWaitForChangedResult.TimedOut" />
public bool TimedOut
=> instance.TimedOut;
/// <inheritdoc cref="IEquatable{WaitForChangedResultWrapper}.Equals(WaitForChangedResultWrapper)" />
public bool Equals(WaitForChangedResultWrapper other)
{
return instance.Equals(other.instance);
}
/// <inheritdoc cref="object.Equals(object)" />
public override bool Equals(object obj)
{
return obj is WaitForChangedResultWrapper other
&& Equals(other);
}
/// <inheritdoc cref="object.GetHashCode()" />
public override int GetHashCode()
{
return instance.GetHashCode();
}
}
}
}