internal FileAttributesData(ref UnsafeNativeMethods.WIN32_FIND_DATA wfd) { FileAttributes = (FileAttributes)wfd.dwFileAttributes; UtcCreationTime = DateTimeUtil.FromFileTimeToUtc(((long)wfd.ftCreationTime_dwHighDateTime) << 32 | (long)wfd.ftCreationTime_dwLowDateTime); UtcLastAccessTime = DateTimeUtil.FromFileTimeToUtc(((long)wfd.ftLastAccessTime_dwHighDateTime) << 32 | (long)wfd.ftLastAccessTime_dwLowDateTime); UtcLastWriteTime = DateTimeUtil.FromFileTimeToUtc(((long)wfd.ftLastWriteTime_dwHighDateTime) << 32 | (long)wfd.ftLastWriteTime_dwLowDateTime); FileSize = (long)wfd.nFileSizeHigh << 32 | (long)wfd.nFileSizeLow; }
internal FileAttributesData(ref UnsafeNativeMethods.WIN32_FIND_DATA wfd) { this.FileAttributes = (System.IO.FileAttributes)wfd.dwFileAttributes; this.UtcCreationTime = DateTimeUtil.FromFileTimeToUtc((long)((wfd.ftCreationTime_dwHighDateTime << 0x20) | wfd.ftCreationTime_dwLowDateTime)); this.UtcLastAccessTime = DateTimeUtil.FromFileTimeToUtc((long)((wfd.ftLastAccessTime_dwHighDateTime << 0x20) | wfd.ftLastAccessTime_dwLowDateTime)); this.UtcLastWriteTime = DateTimeUtil.FromFileTimeToUtc((long)((wfd.ftLastWriteTime_dwHighDateTime << 0x20) | wfd.ftLastWriteTime_dwLowDateTime)); this.FileSize = (wfd.nFileSizeHigh << 0x20) | wfd.nFileSizeLow; }
public FileSystemMonitor(Dictionary <string, string> paths, Profile profile) { if (paths == null) { throw new ArgumentNullException(nameof(paths)); } else if (paths.Count == 0) { throw new ArgumentException("No paths specified.", nameof(paths)); } Paths = new Dictionary <DirectoryInfo, string>(paths.Keys.Count); Profile = profile; foreach (KeyValuePair <string, string> kv in paths) { try { if (Directory.Exists(kv.Key)) { DirectoryInfo dir = new DirectoryInfo(kv.Key); string searchPattern = Path.Combine(dir.FullName, kv.Value); var findFileData = new UnsafeNativeMethods.WIN32_FIND_DATA(); IntPtr hFindFile = UnsafeNativeMethods.FindFirstFile(searchPattern, ref findFileData); if (hFindFile != UnsafeNativeMethods.INVALID_HANDLE_VALUE) { Debug("Adding {0} {1} to monitored paths.", dir.FullName, kv.Value); Paths.Add(dir, kv.Value); } else { Warn("Path {0} currently has no files matching pattern {1}.", dir.FullName, kv.Value); Debug("Adding {0} {1} to monitored paths.", dir.FullName, kv.Value); Paths.Add(dir, kv.Value); } } else { Warn("The directory {0} does not exist.", kv.Key); continue; } } catch (Exception e) { Error(e, "Error occurred enumerating files in directory {0} using search pattern {1}.", kv.Key, kv.Value); Debug("Not adding {0} to monitored paths.", kv.Key); continue; } } if (Paths.Count > 0) { Status = ApiStatus.Initializing; } else { Status = ApiStatus.FileNotFound; } }
internal FindFileData(ref UnsafeNativeMethods.WIN32_FIND_DATA wfd) { this._fileAttributesData = new System.Web.Util.FileAttributesData(ref wfd); this._fileNameLong = wfd.cFileName; if (((wfd.cAlternateFileName != null) && (wfd.cAlternateFileName.Length > 0)) && !StringUtil.EqualsIgnoreCase(wfd.cFileName, wfd.cAlternateFileName)) { this._fileNameShort = wfd.cAlternateFileName; } }
internal FindFileData(ref UnsafeNativeMethods.WIN32_FIND_DATA wfd) { _fileAttributesData = new FileAttributesData(ref wfd); _fileNameLong = wfd.cFileName; if (wfd.cAlternateFileName != null && wfd.cAlternateFileName.Length > 0 && !StringUtil.EqualsIgnoreCase(wfd.cFileName, wfd.cAlternateFileName)) { _fileNameShort = wfd.cAlternateFileName; } }
public FileSystemMonitor(string[] directories, string[] extensions, Profile profile) { if (directories == null) { throw new ArgumentNullException(nameof(directories)); } else if (directories.Length == 0) { throw new ArgumentException("No paths specified.", nameof(directories)); } if (extensions == null) { throw new ArgumentNullException(nameof(extensions)); } else if (extensions.Length == 0) { throw new ArgumentException("No paths specified.", nameof(extensions)); } Paths = new Dictionary <DirectoryInfo, string>(directories.Length * extensions.Length); foreach (string d in directories) { try { if (Directory.Exists(d)) { foreach (string ext in extensions) { DirectoryInfo dir = new DirectoryInfo(d); try { string searchPattern = Path.Combine(dir.FullName, ext); var findFileData = new UnsafeNativeMethods.WIN32_FIND_DATA(); IntPtr hFindFile = UnsafeNativeMethods.FindFirstFile(searchPattern, ref findFileData); if (hFindFile != UnsafeNativeMethods.INVALID_HANDLE_VALUE) { Verbose("Adding {0} {1} to monitored paths.", dir.FullName, ext); Paths.Add(dir, ext); } else { Verbose("Path {0} currently has no files matching pattern {1}.", dir.FullName, ext); Verbose("Adding {0} {1} to monitored paths.", dir.FullName, ext); Paths.Add(dir, ext); } } catch (Exception e) { Error(e, "Error occurred enumerating files in directory {0} using search pattern {1}.", d, ext); Debug("Not adding {0} to monitored paths.", Path.Combine(dir.FullName, ext)); continue; } } } else { Warn("The directory {0} does not exist.", d); continue; } } catch (Exception e) { Error(e, "Error occurred enumerating files in directory {0}.", d); Debug("Not adding {0} to monitored paths.", d); continue; } } Profile = profile; if (Paths.Count > 0) { Status = ApiStatus.Initializing; } else { Status = ApiStatus.FileNotFound; } }