private bool UpdateDataAndDispatch(DefaultWatcherData data, bool dispatch) { if (!data.Enabled) { return(data.DisabledTime != DateTime.MaxValue && (DateTime.Now - data.DisabledTime).TotalSeconds > 5.0); } this.DoFiles(data, data.Directory, dispatch); return(false); }
private void Monitor() { int num = 0; for (;;) { Thread.Sleep(750); Hashtable obj = DefaultWatcher.watches; Hashtable hashtable; lock (obj) { if (DefaultWatcher.watches.Count == 0) { if (++num == 20) { break; } continue; } else { hashtable = (Hashtable)DefaultWatcher.watches.Clone(); } } if (hashtable.Count != 0) { num = 0; foreach (object obj2 in hashtable.Values) { DefaultWatcherData defaultWatcherData = (DefaultWatcherData)obj2; bool flag = this.UpdateDataAndDispatch(defaultWatcherData, true); if (flag) { Hashtable obj3 = DefaultWatcher.watches; lock (obj3) { DefaultWatcher.watches.Remove(defaultWatcherData.FSW); } } } } } lock (this) { DefaultWatcher.thread = null; } }
public void StartDispatching(FileSystemWatcher fsw) { DefaultWatcherData data; lock (this) { if (watches == null) { watches = new Hashtable(); } if (thread == null) { thread = new Thread(new ThreadStart(Monitor)); thread.IsBackground = true; thread.Start(); } } lock (watches) { data = (DefaultWatcherData)watches [fsw]; if (data == null) { data = new DefaultWatcherData(); data.Files = new Hashtable(); watches [fsw] = data; } data.FSW = fsw; data.Directory = fsw.FullPath; data.NoWildcards = !fsw.Pattern.HasWildcard; if (data.NoWildcards) { data.FileMask = Path.Combine(data.Directory, fsw.MangledFilter); } else { data.FileMask = fsw.MangledFilter; } data.IncludeSubdirs = fsw.IncludeSubdirectories; data.Enabled = true; data.DisabledTime = DateTime.MaxValue; UpdateDataAndDispatch(data, false); } }
public void StopDispatching(FileSystemWatcher fsw) { lock (this) { if (watches == null) { return; } } lock (watches) { DefaultWatcherData defaultWatcherData = (DefaultWatcherData)watches[fsw]; if (defaultWatcherData != null) { defaultWatcherData.Enabled = false; defaultWatcherData.DisabledTime = DateTime.Now; } } }
void DoFiles(DefaultWatcherData data, string directory, bool dispatch) { bool direxists = Directory.Exists(directory); if (direxists && data.IncludeSubdirs) { foreach (string d in Directory.GetDirectories(directory)) { DoFiles(data, d, dispatch); } } string [] files = null; if (!direxists) { files = NoStringsArray; } else if (!data.NoWildcards) { files = Directory.GetFileSystemEntries(directory, data.FileMask); } else { // The pattern does not have wildcards if (File.Exists(data.FileMask) || Directory.Exists(data.FileMask)) { files = new string [] { data.FileMask } } ; else { files = NoStringsArray; } } lock (data.FilesLock) { if (data.Enabled) { IterateAndModifyFilesData(data, directory, dispatch, files); } } }
void IterateAndModifyFilesData(DefaultWatcherData data, string directory, bool dispatch, string[] files) { /* Set all as untested */ foreach (var entry in data.Files) { FileData fd = entry.Value; if (fd.Directory == directory) { fd.NotExists = true; } } /* New files */ foreach (string filename in files) { if (!data.Files.TryGetValue(filename, out var fd)) { try { data.Files.Add(filename, CreateFileData(directory, filename)); } catch { // The file might have been removed in the meanwhile data.Files.Remove(filename); continue; } if (dispatch) { DispatchEvents(data.FSW, FileAction.Added, filename); } } else if (fd.Directory == directory) { fd.NotExists = false; } } if (!dispatch) // We only initialize the file list { return; } /* Removed files */ List <string> removed = null; foreach (var entry in data.Files) { var filename = entry.Key; FileData fd = entry.Value; if (fd.NotExists) { if (removed == null) { removed = new List <string> (); } removed.Add(filename); DispatchEvents(data.FSW, FileAction.Removed, filename); } } if (removed != null) { foreach (string filename in removed) { data.Files.Remove(filename); } removed = null; } /* Changed files */ foreach (var entry in data.Files) { var filename = entry.Key; FileData fd = entry.Value; DateTime creation, write; try { creation = File.GetCreationTime(filename); write = File.GetLastWriteTime(filename); } catch { /* Deleted */ if (removed == null) { removed = new List <string> (); } removed.Add(filename); DispatchEvents(data.FSW, FileAction.Removed, filename); continue; } if (creation != fd.CreationTime || write != fd.LastWriteTime) { fd.CreationTime = creation; fd.LastWriteTime = write; DispatchEvents(data.FSW, FileAction.Modified, filename); } } if (removed != null) { foreach (string filename in removed) { data.Files.Remove(filename); } } }
void DoFiles(DefaultWatcherData data, string directory, bool dispatch) { bool direxists = Directory.Exists(directory); if (direxists && data.IncludeSubdirs) { foreach (string d in Directory.GetDirectories(directory)) { DoFiles(data, d, dispatch); } } string [] files = null; if (!direxists) { files = NoStringsArray; } else if (!data.NoWildcards) { files = Directory.GetFileSystemEntries(directory, data.FileMask); } else { // The pattern does not have wildcards if (File.Exists(data.FileMask) || Directory.Exists(data.FileMask)) { files = new string [] { data.FileMask } } ; else { files = NoStringsArray; } } /* Set all as untested */ foreach (string filename in data.Files.Keys) { FileData fd = (FileData)data.Files [filename]; if (fd.Directory == directory) { fd.NotExists = true; } } /* New files */ foreach (string filename in files) { FileData fd = (FileData)data.Files [filename]; if (fd == null) { try { data.Files.Add(filename, CreateFileData(directory, filename)); } catch { // The file might have been removed in the meanwhile data.Files.Remove(filename); continue; } if (dispatch) { DispatchEvents(data.FSW, FileAction.Added, filename); } } else if (fd.Directory == directory) { fd.NotExists = false; } } if (!dispatch) // We only initialize the file list { return; } /* Removed files */ ArrayList removed = null; foreach (string filename in data.Files.Keys) { FileData fd = (FileData)data.Files [filename]; if (fd.NotExists) { if (removed == null) { removed = new ArrayList(); } removed.Add(filename); DispatchEvents(data.FSW, FileAction.Removed, filename); } } if (removed != null) { foreach (string filename in removed) { data.Files.Remove(filename); } removed = null; } /* Changed files */ foreach (string filename in data.Files.Keys) { FileData fd = (FileData)data.Files [filename]; DateTime creation, write; try { creation = File.GetCreationTime(filename); write = File.GetLastWriteTime(filename); } catch { /* Deleted */ if (removed == null) { removed = new ArrayList(); } removed.Add(filename); DispatchEvents(data.FSW, FileAction.Removed, filename); continue; } if (creation != fd.CreationTime || write != fd.LastWriteTime) { fd.CreationTime = creation; fd.LastWriteTime = write; DispatchEvents(data.FSW, FileAction.Modified, filename); } } if (removed != null) { foreach (string filename in removed) { data.Files.Remove(filename); } } }
public void StartDispatching (FileSystemWatcher fsw) { DefaultWatcherData data; lock (this) { if (watches == null) watches = new Hashtable (); if (thread == null) { thread = new Thread (new ThreadStart (Monitor)); thread.IsBackground = true; thread.Start (); } } lock (watches) { data = (DefaultWatcherData) watches [fsw]; if (data == null) { data = new DefaultWatcherData (); data.Files = new Hashtable (); watches [fsw] = data; } data.FSW = fsw; data.Directory = fsw.FullPath; data.NoWildcards = !fsw.Pattern.HasWildcard; if (data.NoWildcards) data.FileMask = Path.Combine (data.Directory, fsw.MangledFilter); else data.FileMask = fsw.MangledFilter; data.IncludeSubdirs = fsw.IncludeSubdirectories; data.Enabled = true; data.DisabledTime = DateTime.MaxValue; UpdateDataAndDispatch (data, false); } }
void DoFiles (DefaultWatcherData data, string directory, bool dispatch) { bool direxists = Directory.Exists (directory); if (direxists && data.IncludeSubdirs) { foreach (string d in Directory.GetDirectories (directory)) DoFiles (data, d, dispatch); } string [] files = null; if (!direxists) { files = NoStringsArray; } else if (!data.NoWildcards) { files = Directory.GetFileSystemEntries (directory, data.FileMask); } else { // The pattern does not have wildcards if (File.Exists (data.FileMask) || Directory.Exists (data.FileMask)) files = new string [] { data.FileMask }; else files = NoStringsArray; } /* Set all as untested */ foreach (string filename in data.Files.Keys) { FileData fd = (FileData) data.Files [filename]; if (fd.Directory == directory) fd.NotExists = true; } /* New files */ foreach (string filename in files) { FileData fd = (FileData) data.Files [filename]; if (fd == null) { try { data.Files.Add (filename, CreateFileData (directory, filename)); } catch { // The file might have been removed in the meanwhile data.Files.Remove (filename); continue; } if (dispatch) DispatchEvents (data.FSW, FileAction.Added, filename); } else if (fd.Directory == directory) { fd.NotExists = false; } } if (!dispatch) // We only initialize the file list return; /* Removed files */ List<string> removed = null; foreach (string filename in data.Files.Keys) { FileData fd = (FileData) data.Files [filename]; if (fd.NotExists) { if (removed == null) removed = new List<string> (); removed.Add (filename); DispatchEvents (data.FSW, FileAction.Removed, filename); } } if (removed != null) { foreach (string filename in removed) data.Files.Remove (filename); removed = null; } /* Changed files */ foreach (string filename in data.Files.Keys) { FileData fd = (FileData) data.Files [filename]; DateTime creation, write; try { creation = File.GetCreationTime (filename); write = File.GetLastWriteTime (filename); } catch { /* Deleted */ if (removed == null) removed = new List<string> (); removed.Add (filename); DispatchEvents (data.FSW, FileAction.Removed, filename); continue; } if (creation != fd.CreationTime || write != fd.LastWriteTime) { fd.CreationTime = creation; fd.LastWriteTime = write; DispatchEvents (data.FSW, FileAction.Modified, filename); } } if (removed != null) { foreach (string filename in removed) data.Files.Remove (filename); } }
bool UpdateDataAndDispatch (DefaultWatcherData data, bool dispatch) { if (!data.Enabled) { return (data.DisabledTime != DateTime.MaxValue && (DateTime.Now - data.DisabledTime).TotalSeconds > 5); } DoFiles (data, data.Directory, dispatch); return false; }
private void DoFiles(DefaultWatcherData data, string directory, bool dispatch) { bool flag = Directory.Exists(directory); if (flag && data.IncludeSubdirs) { foreach (string directory2 in Directory.GetDirectories(directory)) { this.DoFiles(data, directory2, dispatch); } } string[] array = null; if (!flag) { array = DefaultWatcher.NoStringsArray; } else if (!data.NoWildcards) { array = Directory.GetFileSystemEntries(directory, data.FileMask); } else if (File.Exists(data.FileMask) || Directory.Exists(data.FileMask)) { array = new string[] { data.FileMask }; } else { array = DefaultWatcher.NoStringsArray; } foreach (object obj in data.Files.Keys) { string key = (string)obj; FileData fileData = (FileData)data.Files[key]; if (fileData.Directory == directory) { fileData.NotExists = true; } } foreach (string text in array) { FileData fileData2 = (FileData)data.Files[text]; if (fileData2 == null) { try { data.Files.Add(text, DefaultWatcher.CreateFileData(directory, text)); } catch { data.Files.Remove(text); goto IL_1BD; } if (dispatch) { DefaultWatcher.DispatchEvents(data.FSW, FileAction.Added, text); } } else if (fileData2.Directory == directory) { fileData2.NotExists = false; } IL_1BD :; } if (!dispatch) { return; } ArrayList arrayList = null; foreach (object obj2 in data.Files.Keys) { string text2 = (string)obj2; FileData fileData3 = (FileData)data.Files[text2]; if (fileData3.NotExists) { if (arrayList == null) { arrayList = new ArrayList(); } arrayList.Add(text2); DefaultWatcher.DispatchEvents(data.FSW, FileAction.Removed, text2); } } if (arrayList != null) { foreach (object obj3 in arrayList) { string key2 = (string)obj3; data.Files.Remove(key2); } arrayList = null; } foreach (object obj4 in data.Files.Keys) { string text3 = (string)obj4; FileData fileData4 = (FileData)data.Files[text3]; DateTime creationTime; DateTime lastWriteTime; try { creationTime = File.GetCreationTime(text3); lastWriteTime = File.GetLastWriteTime(text3); } catch { if (arrayList == null) { arrayList = new ArrayList(); } arrayList.Add(text3); DefaultWatcher.DispatchEvents(data.FSW, FileAction.Removed, text3); continue; } if (creationTime != fileData4.CreationTime || lastWriteTime != fileData4.LastWriteTime) { fileData4.CreationTime = creationTime; fileData4.LastWriteTime = lastWriteTime; DefaultWatcher.DispatchEvents(data.FSW, FileAction.Modified, text3); } } if (arrayList != null) { foreach (object obj5 in arrayList) { string key3 = (string)obj5; data.Files.Remove(key3); } } }
void IterateAndModifyFilesData (DefaultWatcherData data, string directory, bool dispatch, string[] files) { /* Set all as untested */ foreach (string filename in data.Files.Keys) { FileData fd = (FileData) data.Files [filename]; if (fd.Directory == directory) fd.NotExists = true; } /* New files */ foreach (string filename in files) { FileData fd = (FileData) data.Files [filename]; if (fd == null) { try { data.Files.Add (filename, CreateFileData (directory, filename)); } catch { // The file might have been removed in the meanwhile data.Files.Remove (filename); continue; } if (dispatch) DispatchEvents (data.FSW, FileAction.Added, filename); } else if (fd.Directory == directory) { fd.NotExists = false; } } if (!dispatch) // We only initialize the file list return; /* Removed files */ List<string> removed = null; foreach (string filename in data.Files.Keys) { FileData fd = (FileData) data.Files [filename]; if (fd.NotExists) { if (removed == null) removed = new List<string> (); removed.Add (filename); DispatchEvents (data.FSW, FileAction.Removed, filename); } } if (removed != null) { foreach (string filename in removed) data.Files.Remove (filename); removed = null; } /* Changed files */ foreach (string filename in data.Files.Keys) { FileData fd = (FileData) data.Files [filename]; DateTime creation, write; try { creation = File.GetCreationTime (filename); write = File.GetLastWriteTime (filename); } catch { /* Deleted */ if (removed == null) removed = new List<string> (); removed.Add (filename); DispatchEvents (data.FSW, FileAction.Removed, filename); continue; } if (creation != fd.CreationTime || write != fd.LastWriteTime) { fd.CreationTime = creation; fd.LastWriteTime = write; DispatchEvents (data.FSW, FileAction.Modified, filename); } } if (removed != null) { foreach (string filename in removed) data.Files.Remove (filename); } }
void DoFiles (DefaultWatcherData data, string directory, bool dispatch) { bool direxists = Directory.Exists (directory); if (direxists && data.IncludeSubdirs) { foreach (string d in Directory.GetDirectories (directory)) DoFiles (data, d, dispatch); } string [] files = null; if (!direxists) { files = NoStringsArray; } else if (!data.NoWildcards) { files = Directory.GetFileSystemEntries (directory, data.FileMask); } else { // The pattern does not have wildcards if (File.Exists (data.FileMask) || Directory.Exists (data.FileMask)) files = new string [] { data.FileMask }; else files = NoStringsArray; } lock (data.FilesLock) { IterateAndModifyFilesData (data, directory, dispatch, files); } }
private void DoFiles(DefaultWatcherData data, string directory, bool dispatch) { bool flag = Directory.Exists(directory); if (flag && data.IncludeSubdirs) { string[] directories = Directory.GetDirectories(directory); foreach (string directory2 in directories) { DoFiles(data, directory2, dispatch); } } string[] array = null; array = ((!flag) ? NoStringsArray : ((!data.NoWildcards) ? Directory.GetFileSystemEntries(directory, data.FileMask) : ((!File.Exists(data.FileMask) && !Directory.Exists(data.FileMask)) ? NoStringsArray : new string[1] { data.FileMask }))); foreach (string key4 in data.Files.Keys) { FileData fileData = (FileData)data.Files[key4]; if (fileData.Directory == directory) { fileData.NotExists = true; } } string[] array2 = array; foreach (string text in array2) { FileData fileData2 = (FileData)data.Files[text]; if (fileData2 == null) { try { data.Files.Add(text, CreateFileData(directory, text)); } catch { data.Files.Remove(text); continue; IL_0185 :; } if (dispatch) { DispatchEvents(data.FSW, FileAction.Added, text); } } else if (fileData2.Directory == directory) { fileData2.NotExists = false; } } if (dispatch) { ArrayList arrayList = null; foreach (string key5 in data.Files.Keys) { FileData fileData3 = (FileData)data.Files[key5]; if (fileData3.NotExists) { if (arrayList == null) { arrayList = new ArrayList(); } arrayList.Add(key5); DispatchEvents(data.FSW, FileAction.Removed, key5); } } if (arrayList != null) { foreach (string item in arrayList) { data.Files.Remove(item); } arrayList = null; } foreach (string key6 in data.Files.Keys) { FileData fileData4 = (FileData)data.Files[key6]; DateTime creationTime; DateTime lastWriteTime; try { creationTime = File.GetCreationTime(key6); lastWriteTime = File.GetLastWriteTime(key6); } catch { if (arrayList == null) { arrayList = new ArrayList(); } arrayList.Add(key6); DispatchEvents(data.FSW, FileAction.Removed, key6); continue; IL_0340 :; } if (creationTime != fileData4.CreationTime || lastWriteTime != fileData4.LastWriteTime) { fileData4.CreationTime = creationTime; fileData4.LastWriteTime = lastWriteTime; DispatchEvents(data.FSW, FileAction.Modified, key6); } } if (arrayList != null) { foreach (string item2 in arrayList) { data.Files.Remove(item2); } } } }