private void ProcessEvent(kevent ev) { lock (this) { KeventData keventData = (KeventData)requests[ev.ident]; if (keventData.Enabled) { string empty = string.Empty; FileSystemWatcher fSW = keventData.FSW; FileAction fileAction = (FileAction)0; DirectoryInfo directoryInfo = new DirectoryInfo(keventData.Directory); FileSystemInfo changedFsi = null; try { FileSystemInfo[] fileSystemInfos = directoryInfo.GetFileSystemInfos(); foreach (FileSystemInfo fileSystemInfo in fileSystemInfos) { if (keventData.DirEntries.ContainsKey(fileSystemInfo.FullName) && fileSystemInfo is FileInfo) { KeventFileData keventFileData = (KeventFileData)keventData.DirEntries[fileSystemInfo.FullName]; if (keventFileData.LastWriteTime != fileSystemInfo.LastWriteTime) { empty = fileSystemInfo.Name; fileAction = FileAction.Modified; keventData.DirEntries[fileSystemInfo.FullName] = new KeventFileData(fileSystemInfo, fileSystemInfo.LastAccessTime, fileSystemInfo.LastWriteTime); if (fSW.IncludeSubdirectories && fileSystemInfo is DirectoryInfo) { keventData.Directory = empty; requests[ev.ident] = keventData; ProcessEvent(ev); } PostEvent(empty, fSW, fileAction, changedFsi); } } } } catch (Exception) { } try { bool flag = true; while (flag) { foreach (KeventFileData value in keventData.DirEntries.Values) { if (!File.Exists(value.fsi.FullName) && !Directory.Exists(value.fsi.FullName)) { empty = value.fsi.Name; fileAction = FileAction.Removed; keventData.DirEntries.Remove(value.fsi.FullName); PostEvent(empty, fSW, fileAction, changedFsi); break; } } flag = false; } } catch (Exception) { } try { FileSystemInfo[] fileSystemInfos2 = directoryInfo.GetFileSystemInfos(); foreach (FileSystemInfo fileSystemInfo2 in fileSystemInfos2) { if (!keventData.DirEntries.ContainsKey(fileSystemInfo2.FullName)) { changedFsi = fileSystemInfo2; empty = fileSystemInfo2.Name; fileAction = FileAction.Added; keventData.DirEntries[fileSystemInfo2.FullName] = new KeventFileData(fileSystemInfo2, fileSystemInfo2.LastAccessTime, fileSystemInfo2.LastWriteTime); PostEvent(empty, fSW, fileAction, changedFsi); } } } catch (Exception) { } } } }
void ProcessEvent(kevent ev) { lock (this) { KeventData data = (KeventData)requests [ev.ident]; if (!data.Enabled) { return; } FileSystemWatcher fsw; string filename = ""; fsw = data.FSW; FileAction fa = 0; DirectoryInfo dir = new DirectoryInfo(data.Directory); FileSystemInfo changedFsi = null; try { foreach (FileSystemInfo fsi in dir.GetFileSystemInfos()) { if (data.DirEntries.ContainsKey(fsi.FullName) && (fsi is FileInfo)) { KeventFileData entry = (KeventFileData)data.DirEntries [fsi.FullName]; if (entry.LastWriteTime != fsi.LastWriteTime) { filename = fsi.Name; fa = FileAction.Modified; data.DirEntries [fsi.FullName] = new KeventFileData(fsi, fsi.LastAccessTime, fsi.LastWriteTime); if (fsw.IncludeSubdirectories && fsi is DirectoryInfo) { data.Directory = filename; requests [ev.ident] = data; ProcessEvent(ev); } PostEvent(filename, fsw, fa, changedFsi); } } } } catch (Exception) { // The file system infos were changed while we processed them } // Deleted try { bool deleteMatched = true; while (deleteMatched) { foreach (KeventFileData entry in data.DirEntries.Values) { if (!File.Exists(entry.fsi.FullName) && !Directory.Exists(entry.fsi.FullName)) { filename = entry.fsi.Name; fa = FileAction.Removed; data.DirEntries.Remove(entry.fsi.FullName); PostEvent(filename, fsw, fa, changedFsi); break; } } deleteMatched = false; } } catch (Exception) { // The file system infos were changed while we processed them } // Added try { foreach (FileSystemInfo fsi in dir.GetFileSystemInfos()) { if (!data.DirEntries.ContainsKey(fsi.FullName)) { changedFsi = fsi; filename = fsi.Name; fa = FileAction.Added; data.DirEntries [fsi.FullName] = new KeventFileData(fsi, fsi.LastAccessTime, fsi.LastWriteTime); PostEvent(filename, fsw, fa, changedFsi); } } } catch (Exception) { // The file system infos were changed while we processed them } } }
private void ProcessEvent(kevent ev) { lock (this) { KeventData keventData = (KeventData)KeventWatcher.requests[ev.ident]; if (keventData.Enabled) { string text = string.Empty; FileSystemWatcher fsw = keventData.FSW; DirectoryInfo directoryInfo = new DirectoryInfo(keventData.Directory); FileSystemInfo changedFsi = null; try { foreach (FileSystemInfo fileSystemInfo in directoryInfo.GetFileSystemInfos()) { if (keventData.DirEntries.ContainsKey(fileSystemInfo.FullName) && fileSystemInfo is FileInfo) { KeventFileData keventFileData = (KeventFileData)keventData.DirEntries[fileSystemInfo.FullName]; if (keventFileData.LastWriteTime != fileSystemInfo.LastWriteTime) { text = fileSystemInfo.Name; FileAction fa = FileAction.Modified; keventData.DirEntries[fileSystemInfo.FullName] = new KeventFileData(fileSystemInfo, fileSystemInfo.LastAccessTime, fileSystemInfo.LastWriteTime); if (fsw.IncludeSubdirectories && fileSystemInfo is DirectoryInfo) { keventData.Directory = text; KeventWatcher.requests[ev.ident] = keventData; this.ProcessEvent(ev); } this.PostEvent(text, fsw, fa, changedFsi); } } } } catch (Exception) { } try { bool flag = true; while (flag) { foreach (object obj in keventData.DirEntries.Values) { KeventFileData keventFileData2 = (KeventFileData)obj; if (!File.Exists(keventFileData2.fsi.FullName) && !Directory.Exists(keventFileData2.fsi.FullName)) { text = keventFileData2.fsi.Name; FileAction fa = FileAction.Removed; keventData.DirEntries.Remove(keventFileData2.fsi.FullName); this.PostEvent(text, fsw, fa, changedFsi); break; } } flag = false; } } catch (Exception) { } try { foreach (FileSystemInfo fileSystemInfo2 in directoryInfo.GetFileSystemInfos()) { if (!keventData.DirEntries.ContainsKey(fileSystemInfo2.FullName)) { changedFsi = fileSystemInfo2; text = fileSystemInfo2.Name; FileAction fa = FileAction.Added; keventData.DirEntries[fileSystemInfo2.FullName] = new KeventFileData(fileSystemInfo2, fileSystemInfo2.LastAccessTime, fileSystemInfo2.LastWriteTime); this.PostEvent(text, fsw, fa, changedFsi); } } } catch (Exception) { } } } }