Revision 48686774 trunk/Pithos.Core/Agents/FileSystemWatcherAdapter.cs
b/trunk/Pithos.Core/Agents/FileSystemWatcherAdapter.cs | ||
---|---|---|
47 | 47 |
namespace Pithos.Core.Agents |
48 | 48 |
{ |
49 | 49 |
using System; |
50 |
using System.Collections.Generic; |
|
51 |
using System.Linq; |
|
52 |
using System.Text; |
|
53 | 50 |
|
54 | 51 |
/// <summary> |
55 |
/// TODO: Update summary.
|
|
52 |
/// Wraps a FileSystemWatcher and raises Move and child object events
|
|
56 | 53 |
/// </summary> |
57 | 54 |
public class FileSystemWatcherAdapter |
58 | 55 |
{ |
... | ... | |
76 | 73 |
} |
77 | 74 |
|
78 | 75 |
private string _cachedDeletedFullPath; |
79 |
private const int PropagateDelay = 10; |
|
80 |
|
|
81 |
private static void OnTimeout(object state) |
|
82 |
{ |
|
83 |
throw new NotImplementedException(); |
|
84 |
} |
|
76 |
private const int PropagateDelay = 10; |
|
85 | 77 |
|
86 | 78 |
private void OnDeleted(object sender, FileSystemEventArgs e) |
87 | 79 |
{ |
... | ... | |
115 | 107 |
TaskEx.Delay(PropagateDelay).ContinueWith(t => |
116 | 108 |
{ |
117 | 109 |
var myPath = e.FullPath; |
118 |
if (this._cachedDeletedFullPath==myPath)
|
|
110 |
if (_cachedDeletedFullPath==myPath) |
|
119 | 111 |
PropagateCachedDeleted(sender); |
120 | 112 |
}); |
121 | 113 |
} |
... | ... | |
162 | 154 |
PropagateCachedDeleted(sender); |
163 | 155 |
//and propagate the actual event |
164 | 156 |
var actualEvent = e.ChangeType == WatcherChangeTypes.Created ? Created : Changed; |
157 |
|
|
165 | 158 |
if (actualEvent != null) |
159 |
{ |
|
166 | 160 |
actualEvent(sender, e); |
161 |
//For Folders, raise Created events for all children |
|
162 |
RaiseCreatedForChildren(sender,e); |
|
163 |
} |
|
167 | 164 |
} |
168 | 165 |
finally |
169 | 166 |
{ |
... | ... | |
173 | 170 |
|
174 | 171 |
} |
175 | 172 |
|
173 |
private void RaiseCreatedForChildren(object sender, FileSystemEventArgs e) |
|
174 |
{ |
|
175 |
Contract.Requires(sender!=null); |
|
176 |
Contract.Requires(e!=null); |
|
177 |
|
|
178 |
if (e.ChangeType != WatcherChangeTypes.Created) |
|
179 |
return; |
|
180 |
var dir= new DirectoryInfo(e.FullPath); |
|
181 |
//Skip if this is not a folder |
|
182 |
if (!dir.Exists) |
|
183 |
return; |
|
184 |
foreach (var info in dir.EnumerateFileSystemInfos("*",SearchOption.AllDirectories)) |
|
185 |
{ |
|
186 |
var path = Path.GetDirectoryName(info.FullName); |
|
187 |
Created(sender,new FileSystemEventArgs(WatcherChangeTypes.Created,path,info.Name)); |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
176 | 191 |
private bool HandleMoved(object sender, FileSystemEventArgs e) |
177 | 192 |
{ |
178 | 193 |
if (sender == null) |
Also available in: Unified diff