public FileEvent(Int64 num, WatcherChangeTypes type, string path, string oldpath) { eventnum = num; eventtype = type; eventpath = path; oldevpath = oldpath; }
private void OnFileChanged(string path, WatcherChangeTypes changeType) { if (!_enableEvents) return; _actions.Enqueue(new TreeChange { Path = path, Type = SimplifyType(changeType) }); _eventFlusher.Change(DebounceInMs, Timeout.Infinite); }
protected static FileBehavior FilterIgnored(string path, WatcherChangeTypes type) { if(Regex.IsMatch(path, Init.Singleton.JsonData.regexIgnoreFiles, RegexOptions.IgnoreCase) || new FileInfo(path).Length <= 0) return new FileIgnored(path, type); else return new FileOK(path, type); }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="path">The root path that this trigger is configured to watch for files on.</param> /// <param name="filter">The optional file filter that will be used.</param> /// <param name="changeTypes">The <see cref="WatcherChangeTypes"/> that will be used by the file watcher. The Default is Created.</param> /// <param name="autoDelete">True if processed files should be deleted automatically, false otherwise. The default is False.</param> public FileTriggerAttribute(string path, string filter, WatcherChangeTypes changeTypes = WatcherChangeTypes.Created, bool autoDelete = false) { this.Path = path; this.Filter = filter; this.ChangeTypes = changeTypes; this.AutoDelete = autoDelete; }
protected void Changed(WatcherChangeTypes changeType, IVirtualItem item) { if (this.OnChanged != null) { this.OnChanged(this, new VirtualItemChangedEventArgs(changeType, item)); } }
protected FileBehavior(string fp, WatcherChangeTypes ct) { fullPath = fp; changeType = ct; fileDT = new FileInfo(fp).LastWriteTime; sysTime = DateTime.Now; }
internal WaitForChangedResult(WatcherChangeTypes changeType, string name, string oldName, bool timedOut) { ChangeType = changeType; Name = name; OldName = oldName; TimedOut = timedOut; }
protected static FileBehavior FilterFileSize(string path, WatcherChangeTypes type) { if(new FileInfo(path).Length <= Init.Singleton.JsonData.maxSize) return new FileOK(path, type); else return new FileTooLarge(path, type); }
public static void TestNestedDirectoriesHelper( string testDirectory, WatcherChangeTypes change, Action<AutoResetEvent, TempDirectory> action, NotifyFilters changeFilers = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName) { using (var dir = new TempDirectory(testDirectory)) using (var watcher = new FileSystemWatcher()) { AutoResetEvent createdOccurred = WatchForEvents(watcher, WatcherChangeTypes.Created); // not "using" to avoid race conditions with FSW callbacks AutoResetEvent eventOccurred = WatchForEvents(watcher, change); watcher.Path = Path.GetFullPath(dir.Path); watcher.Filter = "*"; watcher.NotifyFilter = changeFilers; watcher.IncludeSubdirectories = true; watcher.EnableRaisingEvents = true; using (var firstDir = new TempDirectory(Path.Combine(dir.Path, "dir1"))) { ExpectEvent(createdOccurred, "dir1 created"); using (var nestedDir = new TempDirectory(Path.Combine(firstDir.Path, "nested"))) { ExpectEvent(createdOccurred, "nested created"); action(eventOccurred, nestedDir); } } } }
internal WaitForChangedResult(WatcherChangeTypes changeType, string name, string oldName, bool timedOut) { this.changeType = changeType; this.name = name; this.oldName = oldName; this.timedOut = timedOut; }
// Constructor. public FileSystemEventArgs(WatcherChangeTypes changeType, String directory, String name) { this.changeType = changeType; this.directory = directory; this.name = name; }
/// <summary> /// A file system event. /// For instance, a file was renamed. /// </summary> public FSEvent(WatcherChangeTypes type, string path) { if(path == null) { throw new ArgumentNullException("Argument null in FSEvent Constructor","path"); } Type = type; Path = path; }
// Constructor. public RenamedEventArgs(WatcherChangeTypes changeType, String directory, String name, String oldName) : base(changeType, directory, name) { this.oldName = oldName; }
protected override bool HandleChangeInternal(string objectName, WatcherChangeTypes changeType) { Trace.TraceInformation("Running MSBuild to compile type script files"); ProcessStartInfo startInfo = new ProcessStartInfo("msbuild.exe"); startInfo.Arguments = string.Format("\"{0}\" /p:Configuration=Debug,BuildingProject=true /t:CompileTypeScript", _projectFilePath); startInfo.CreateNoWindow = true; startInfo.WindowStyle = ProcessWindowStyle.Hidden; Process proc = Process.Start(startInfo); if (null != proc) { proc.WaitForExit(); Trace.TraceInformation("MSBuild exited with code {0}", proc.ExitCode); if (proc.ExitCode != 0) Console.Beep(); } else Trace.TraceWarning("MSBuild executable not found"); RefreshBrowser(); return true; }
public FileEventArgs(WatcherChangeTypes changeType, string fullname, string name, RenamedEventArgs renameArgs) { this.ChangeType = changeType; this.FullPath = fullname; this.Name = name; RenameName = renameArgs; }
protected override bool HandleChangeInternal(string objectName, WatcherChangeTypes changeType) { Trace.TraceInformation("Refreshing browser due to the change notification."); RefreshBrowser(); return true; }
public RxFileSystemEventArgs (WatcherChangeTypes changeType, string fullPath, string oldFullPath, string directory) { this.ChangeType = changeType; this.FullPath = fullPath; this.OldFullPath = oldFullPath; this.Directory = directory; }
protected static FileBehavior FilterAllowedExt(string path, WatcherChangeTypes type) { string coreRegex = String.Join("|", Init.Singleton.JsonData.allowedExt); if(Regex.IsMatch(path, @".*\.(" + coreRegex + ")$", RegexOptions.IgnoreCase)) return new FileOK(path, type); else return new FileExtensionNotAllowed(path, type); }
//TODO: Controllare validità? forse si fa più danno a controllarne subito la validità, occorre esserne sicuri al momento // della gestione da parte del demone che si preoccupa di pushare i cambiamenti sul server. Forse sarebbe opportuno controllare la validità dei nomi dei file // eliminando i caratteri non validi in termini di OS, ovvero i caratteri riservati in name. public PendingChange(WatcherChangeTypes type, string fullPath, string name, string oldPath = null) { Type = type; FullPath = fullPath; Name = name; if (type == WatcherChangeTypes.Renamed) OldPath = oldPath; }
public RenamedEventArgs(WatcherChangeTypes changeType, string directory, string name, string oldName) : base(changeType, directory, name) { if (!directory.EndsWith(@"\", StringComparison.Ordinal)) { directory = directory + @"\"; } this.oldName = oldName; this.oldFullPath = directory + oldName; }
public void Add(string guid, int version, string fileName, string oldName, int date, WatcherChangeTypes changeType) { string sqlInsert = $"INSERT INTO {Event.TableName} " + $"({Event.FGuid},{Event.FVersion},{Event.FName},{Event.FOldName},{Event.FDate},{Event.FChange})" + $"VALUES('{guid}', {version}, '{fileName.ToLower()}', '{oldName}', '{date}', '{(int)changeType}');"; IDbCommand command = new SQLiteCommand(sqlInsert, (SQLiteConnection)this.sqlConnection); command.ExecuteNonQuery(); }
public FileSystemEventArgs(WatcherChangeTypes changeType, string directory, string name) { this.changeType = changeType; this.name = name; if (!directory.EndsWith(@"\", StringComparison.Ordinal)) { directory = directory + @"\"; } this.fullPath = directory + name; }
// Browse the filters located in filtersOrder and return the correct FileBehavior or null in case of an Exception public static FileBehavior Filter(string fullpath, WatcherChangeTypes type) { FileBehavior file; foreach(FilterOperationDelegate d in filtersOrder) { file = filter(fullpath, type, d); if(!(file is FileOK)) return file; } return new FileOK(fullpath, type); }
/// <summary> /// /// </summary> /// <param name="fileChangeCallback">文件发生变化后回调的方法</param> /// <param name="directoryPath">监控目录物理路径</param> /// <param name="filter">监控文件筛选</param> /// <param name="isContinued">是否持续监控,True持续监控,False则文件发生变生触发事件后监控失效。</param> internal FileMonitor(string directoryPath, string filter, bool isContinued, Action<IFileMonitor> fileChangedCallback, WatcherChangeTypes actionTypes) { this.IsContinued = isContinued; this.Filter = string.IsNullOrEmpty(filter) ? "*.*" : filter; this.ActionTypes = actionTypes; this.DirectoryPath = directoryPath; this.fileChangedCallBack = fileChangedCallback; this.fileSystemWatcher = this.BuildFileWatcher(); }
public FtpChangedEventArg(WatcherChangeTypes changeType, Uri absoluteUri, Uri baseUri) { if (changeType == WatcherChangeTypes.Renamed) { throw new ArgumentException("Rename change type was incompatible with this constructor"); } this.ChangeType = changeType; this.AbsoluteUri = absoluteUri; this.BaseUri = baseUri; }
public ChangeInfo(string fullPath, string basePath, WatcherChangeTypes changeType) { RelativePath = fullPath.Replace(basePath, string.Empty); Condition.Requires(RelativePath).IsNotEqualTo(fullPath, $"relative path '{RelativePath}' of file change should differ from fullpath '{FullPath}'"); if (RelativePath.StartsWith(@"\")) RelativePath = RelativePath.Substring(1); FullPath = fullPath; ChangeTypes.Add(changeType); }
public FtpChangedEventArg(Uri absoluteUri, Uri baseUri, string newName) { if (newName == null) { throw new ArgumentNullException("newName"); } this.ChangeType = WatcherChangeTypes.Renamed; this.AbsoluteUri = absoluteUri; this.BaseUri = baseUri; this.NewName = newName; }
/// <devdoc> /// <para> /// Initializes a new instance of the <see cref='System.IO.RenamedEventArgs'/> /// class. /// </para> /// </devdoc> public RenamedEventArgs(WatcherChangeTypes changeType, string directory, string name, string oldName) : base(changeType, directory, name) { // Ensure that the directory name ends with a "\" if (!directory.EndsWith("\\", StringComparison.Ordinal)) { directory = directory + "\\"; } this.oldName = oldName; this.oldFullPath = directory + oldName; }
/// <summary> /// Initializes a new instance of the <see cref="CmisSync.Lib.Events.FSEvent"/> class. /// </summary> /// <param name='type'> /// The Type. /// </param> /// <param name='path'> /// The Path. /// </param> /// <param name="isDirectory"> /// Signalizes if the target of the path is a directory or file. /// </param> /// <exception cref='ArgumentNullException'> /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> . /// </exception> public FSEvent(WatcherChangeTypes type, string path, bool isDirectory) { if (path == null) { throw new ArgumentNullException("path"); } this.Type = type; FileSystemInfo fileSystemInfo = isDirectory ? (FileSystemInfo)new DirectoryInfo(path) : (FileSystemInfo)new FileInfo(path); this.LocalPath = fileSystemInfo.FullName; this.IsDirectory = isDirectory; this.Name = fileSystemInfo.Name; }
private void HandleChange(string name, WatcherChangeTypes changeType) { WatchedFile file; if (_watchedFiles.TryGetValue(name.ToLower(), out file)) { if (changeType == WatcherChangeTypes.Changed || changeType == WatcherChangeTypes.Created) file.FileChanged(); if (changeType == WatcherChangeTypes.Deleted) file.Reset(); } }
public TestFileSystemWatcher(string path, string filter = "*.*", bool includeSubdirectories = true, WatcherChangeTypes changeTypes = WatcherChangeTypes.All, ILoggerFactory loggerFactory = null) : base(path, filter, includeSubdirectories, changeTypes, loggerFactory) { }
/// <devdoc> /// Initializes a new instance of the <see cref='System.IO.FileSystemEventArgs'/> class. /// </devdoc> public FileSystemEventArgs(WatcherChangeTypes changeType, string directory, string?name) { _changeType = changeType; _name = name; _fullPath = Combine(directory, name); }
public WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout) { return(new WaitForChangedResult()); }
public bool ReportChange(string newPath, WatcherChangeTypes changeType) { return(ReportChange(oldPath: null, newPath: newPath, changeType: changeType)); }
/// <summary> /// A synchronous method that returns a structure that contains specific information on the change that occurred, given the type of change you want to monitor /// and the time (in milliseconds) to wait before timing out. /// </summary> /// <param name="changeType">The System.IO.WatcherChangeTypes to watch for.</param> /// <param name="timeout">The time (in milliseconds) to wait before timing out.</param> /// <returns>A System.IO.WaitForChangedResult that contains specific information on the change that occurred.</returns> public WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout) { //TODO throw new NotImplementedException(); }
private void OnExcelPathChange(WatcherChangeTypes type, FileSystemEventArgs args) { ReloadExcelPath(); }
public abstract WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout);
public void NotifyChange(WatcherChangeTypes changeType, string directory, string name) => OnFileSystemChange(new FileSystemEventArgs(changeType, directory, name));
/// <summary> /// Does verification that the given watcher will throw exactly/only the events in "expectedEvents" when /// "action" is executed. /// </summary> /// <param name="watcher">The FileSystemWatcher to test</param> /// <param name="expectedEvents">All of the events that are expected to be raised by this action</param> /// <param name="action">The Action that will trigger events.</param> /// <param name="cleanup">Optional. Undoes the action and cleans up the watcher so the test may be run again if necessary.</param> public static void ExpectEvent(FileSystemWatcher watcher, WatcherChangeTypes expectedEvents, Action action, Action cleanup = null) { ExpectEvent(watcher, expectedEvents, action, cleanup, (string[])null); }
/// <summary> /// 对一个备份文件名称进行分解,分别获得该备份文件的源文件名称,动作时间和备份动作 /// </summary> /// <param name="backupFileName">备份文件名称</param> /// <param name="fileName">源文件的名称</param> /// <param name="datetime">备份时间</param> /// <param name="action">动作名称</param> /// <returns></returns> public bool SplitFileName(string backupFullFileName, ref string displayedName, ref string fileName, ref DateTime datetime, ref WatcherChangeTypes changeType) { //eg:abc.txt@2013_03_01_11_20_49.Created int minLen = 25;//min len of a backupName,len of @2013_03_01_11_20_49.Created/Changed if (backupFullFileName.Length < minLen) { return(false); } int pos = backupFullFileName.LastIndexOf("@"); if (pos <= 0) { return(false); } try { int lenOfDate = 19;//length of "yyyy_MM_dd_HH_mm_ss" displayedName = backupFullFileName.Substring(0, pos); fileName = displayedName.Substring(displayedName.LastIndexOf("\\") + 1); string datetimeStr = backupFullFileName.Substring(pos + 1, lenOfDate); string[] dateArr = datetimeStr.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries); datetime = new DateTime(Convert.ToInt32(dateArr[0]), Convert.ToInt32(dateArr[1]), Convert.ToInt32(dateArr[2]), Convert.ToInt32(dateArr[3]), Convert.ToInt32(dateArr[4]), Convert.ToInt32(dateArr[5])); changeType = (WatcherChangeTypes)Enum.Parse(typeof(WatcherChangeTypes), backupFullFileName.Substring(pos + 1 + lenOfDate + 1)); return(true); } catch { return(false); } }
public static void Windows_File_Move_To_Same_Directory_Triggers_Event(WatcherChangeTypes eventType, bool moveRaisesEvent) { MoveAndCheck_SameDirectory(eventType, moveRaisesEvent); }
public List <BackupInfo> SearchBackupFiles(string path, DateTime startingDate, DateTime endingDate, string fileNameKeyword, WatcherChangeTypes changeType, bool includeSubdir) { List <string> searchFileResults = new List <string>();//定义一个集合来存储所有搜索到的文件的名称 SearchFiles(path, changeType, includeSubdir, ref searchFileResults); List <BackupInfo> searchResults = new List <BackupInfo>(); foreach (string backupFullFileName in searchFileResults) { DateTime date = DateTime.MinValue; string displayedName = null; string fileName = null; WatcherChangeTypes _changeType = WatcherChangeTypes.Created; if (SplitFileName(backupFullFileName, ref displayedName, ref fileName, ref date, ref _changeType)) { if (date >= startingDate && date <= endingDate)//如果该文件时间是在开始时间和结束时间内的,则显示在列表中 { if (string.IsNullOrEmpty(fileNameKeyword) || displayedName.Contains(fileNameKeyword)) { BackupInfo bak = new BackupInfo(backupFullFileName, date, _changeType); searchResults.Add(bak); } } } } return(searchResults); }
/// <summary> /// A synchronous method that returns a structure that contains specific information on the change that occurred, given the type of change you want to monitor and the time (in milliseconds) to wait before timing out. /// </summary> /// <returns>A <see cref="WaitForChangedResult"/> that contains specific information on the change that occurred.</returns> /// <param name="changeType">The <see cref="WatcherChangeTypes"/> to watch for.</param> /// <param name="timeout">The time (in milliseconds) to wait before timing out.</param> public WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType, int timeout) { return(m_fileSystemWatcher.WaitForChanged(changeType, timeout)); }
/// <summary> /// A synchronous method that returns a structure that contains specific information on the change that occurred, given the type of change you want to monitor. /// </summary> /// <returns>A <see cref="WaitForChangedResult"/> that contains specific information on the change that occurred.</returns> /// <param name="changeType">The <see cref="WatcherChangeTypes"/> to watch for.</param> public WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType) { return(m_fileSystemWatcher.WaitForChanged(changeType)); }
private unsafe void ProcessEvents(int numEvents, byte **eventPaths, Interop.EventStream.FSEventStreamEventFlags[] eventFlags, FSEventStreamEventId[] eventIds, FileSystemWatcher watcher) { // Since renames come in pairs, when we find the first we need to search for the next one. Once we find it, we'll add it to this // list so when the for-loop comes across it, we'll skip it since it's already been processed as part of the original of the pair. List <FSEventStreamEventId> handledRenameEvents = null; Memory <char>[] events = new Memory <char> [numEvents]; ParseEvents(); for (long i = 0; i < numEvents; i++) { ReadOnlySpan <char> path = events[i].Span; Debug.Assert(path[path.Length - 1] != '/', "Trailing slashes on events is not supported"); // Match Windows and don't notify us about changes to the Root folder if (_fullDirectory.Length >= path.Length && path.Equals(_fullDirectory.AsSpan(0, path.Length), StringComparison.OrdinalIgnoreCase)) { continue; } WatcherChangeTypes eventType = 0; // First, we should check if this event should kick off a re-scan since we can't really rely on anything after this point if that is true if (ShouldRescanOccur(eventFlags[i])) { watcher.OnError(new ErrorEventArgs(new IOException(SR.FSW_BufferOverflow, (int)eventFlags[i]))); break; } else if ((handledRenameEvents != null) && (handledRenameEvents.Contains(eventIds[i]))) { // If this event is the second in a rename pair then skip it continue; } else if (CheckIfPathIsNested(path) && ((eventType = FilterEvents(eventFlags[i])) != 0)) { // The base FileSystemWatcher does a match check against the relative path before combining with // the root dir; however, null is special cased to signify the root dir, so check if we should use that. ReadOnlySpan <char> relativePath = ReadOnlySpan <char> .Empty; if (!path.Equals(_fullDirectory, StringComparison.OrdinalIgnoreCase) && path.Length >= _fullDirectory.Length && _fullDirectory.AsSpan().Equals(path.Slice(0, _fullDirectory.Length), StringComparison.OrdinalIgnoreCase)) { // Remove the root directory to get the relative path relativePath = path.Slice(_fullDirectory.Length); } // Raise a notification for the event if (((eventType & WatcherChangeTypes.Changed) > 0)) { watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Changed, relativePath); } if (((eventType & WatcherChangeTypes.Created) > 0)) { watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Created, relativePath); } if (((eventType & WatcherChangeTypes.Deleted) > 0)) { watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Deleted, relativePath); } if (((eventType & WatcherChangeTypes.Renamed) > 0)) { // Find the rename that is paired to this rename, which should be the next rename in the list long pairedId = FindRenameChangePairedChange(i, eventFlags); if (pairedId == long.MinValue) { // Getting here means we have a rename without a pair, meaning it should be a create for the // move from unwatched folder to watcher folder scenario or a move from the watcher folder out. // Check if the item exists on disk to check which it is // Don't send a new notification if we already sent one for this event. if (DoesItemExist(path, IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemIsFile))) { if ((eventType & WatcherChangeTypes.Created) == 0) { watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Created, relativePath); } } else if ((eventType & WatcherChangeTypes.Deleted) == 0) { watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Deleted, relativePath); } } else { // Remove the base directory prefix and add the paired event to the list of // events to skip and notify the user of the rename if (events[pairedId].Span.Length >= _fullDirectory.Length && _fullDirectory.AsSpan().Equals(events[pairedId].Span.Slice(0, _fullDirectory.Length), StringComparison.OrdinalIgnoreCase)) { ReadOnlySpan <char> newPathRelativeName = events[pairedId].Span.Slice(_fullDirectory.Length); watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, newPathRelativeName, relativePath); } else { //if the base directory prefix isn't there, just use the full absolute path watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, events[pairedId].Span, relativePath); } // Create a new list, if necessary, and add the event if (handledRenameEvents == null) { handledRenameEvents = new List <FSEventStreamEventId>(); } handledRenameEvents.Add(eventIds[pairedId]); } } } ArraySegment <char> underlyingArray; if (MemoryMarshal.TryGetArray(events[i], out underlyingArray)) { ArrayPool <char> .Shared.Return(underlyingArray.Array); } } this._context = ExecutionContext.Capture(); void ParseEvents() { for (int i = 0; i < events.Length; i++) { int byteCount = 0; Debug.Assert(eventPaths[i] != null); byte *temp = eventPaths[i]; // Finds the position of null character. while (*temp != 0) { temp++; byteCount++; } Debug.Assert(byteCount > 0, "Empty events are not supported"); events[i] = new Memory <char>(ArrayPool <char> .Shared.Rent(Encoding.UTF8.GetMaxCharCount(byteCount))); int charCount; // Converting an array of bytes to UTF-8 char array charCount = Encoding.UTF8.GetChars(new ReadOnlySpan <byte>(eventPaths[i], byteCount), events[i].Span); events[i] = events[i].Slice(0, charCount); } } }
/// <summary> /// Helper for the ExpectEvent function. /// </summary> /// <param name="watcher">The FileSystemWatcher to test</param> /// <param name="expectedEvents">All of the events that are expected to be raised by this action</param> /// <param name="action">The Action that will trigger events.</param> /// <param name="assertExpected">True if results should be asserted. Used if there is no retry.</param> /// <param name="expectedPath"> Adds path verification to all expected events.</param> /// <returns>True if the events raised correctly; else, false.</returns> public static bool ExecuteAndVerifyEvents(FileSystemWatcher watcher, WatcherChangeTypes expectedEvents, Action action, bool assertExpected, string[] expectedPaths, int timeout) { bool result = true, verifyChanged = true, verifyCreated = true, verifyDeleted = true, verifyRenamed = true; (AutoResetEvent EventOccured, FileSystemEventHandler Handler)changed = default, created = default, deleted = default;
private bool IsWatching(WatcherChangeTypes changeType) { return((_identity.ChangeTypes | changeType) == changeType); }
public WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType) { return(WaitForChanged(changeType, Timeout.Infinite)); }
public static void Windows_File_Move_With_Set_NotifyFilter_Triggers_Event(WatcherChangeTypes eventType, bool moveRaisesEvent) { MoveAndCheck_WithNotifyFilter(eventType, moveRaisesEvent); }
private FileSystemEventArgs GetEventArgs(WatcherChangeTypes changeType, string path) { return(new FileSystemEventArgs(changeType, PathUtils.GetFolderPath(path), PathUtils.GetName(path))); }
public DeletedEventArgsExt(WatcherChangeTypes changeTypes, string directory, string name, bool isDir) : base(changeTypes, directory, name) { this.isDirectory = isDir; }
public static void Unix_File_Move_To_Different_Directory_Triggers_Event(WatcherChangeTypes eventType, bool moveRaisesEvent) { MoveAndCheck_DifferentDirectory(eventType, moveRaisesEvent); }
/// <summary> /// Does verification that the given watcher will throw exactly/only the events in "expectedEvents" when /// "action" is executed. /// </summary> /// <param name="watcher">The FileSystemWatcher to test</param> /// <param name="expectedEvents">All of the events that are expected to be raised by this action</param> /// <param name="action">The Action that will trigger events.</param> /// <param name="cleanup">Optional. Undoes the action and cleans up the watcher so the test may be run again if necessary.</param> /// <param name="expectedPath">Optional. Adds path verification to all expected events.</param> /// <param name="attempts">Optional. Number of times the test should be executed if it's failing.</param> public static void ExpectEvent(FileSystemWatcher watcher, WatcherChangeTypes expectedEvents, Action action, Action cleanup = null, string expectedPath = null, int attempts = DefaultAttemptsForExpectedEvent, int timeout = WaitForExpectedEventTimeout) { ExpectEvent(watcher, expectedEvents, action, cleanup, expectedPath == null ? null : new string[] { expectedPath }, attempts, timeout); }
public static void Unix_File_Move_In_Nested_Directory_Triggers_Event(WatcherChangeTypes eventType, bool moveRaisesEvent) { MoveAndCheck_NestedDirectory(eventType, moveRaisesEvent); }
private void Reader_StreamChanged(object sender, WatcherChangeTypes changeType) { CheckRange(changeType != WatcherChangeTypes.Changed); }
private bool FolderTheSame() { int fileCounter = 0; string[] arrFilesSource = Directory.GetFiles(strSourcePath); string[] arrFilesDest = Directory.GetFiles(strDesPath); for (int i = 0; i < arrFilesDest.Length; i++) { for (int j = 0; j < arrFilesSource.Length; j++) { string[] getsrcFilename = arrFilesSource[j].Split('\\'); string[] getdestFilename = arrFilesDest[i].Split('\\'); if (getsrcFilename[getsrcFilename.Length - 1] == getdestFilename[getdestFilename.Length - 1]) { byte[] bd, bs; FileStream fd = new FileStream(arrFilesDest[i], FileMode.Open); FileStream fs = new FileStream(arrFilesSource[j], FileMode.Open); bs = new byte[fs.Length]; bd = new byte[fd.Length]; fs.Read(bs, 0, bs.Length); fd.Read(bd, 0, bd.Length); if (FilesTheSame(bd, bs)) { fileCounter++; } if (!FilesTheSame(bd, bs)) { tempFileDest = getdestFilename[getdestFilename.Length - 1]; tempFileSource = getsrcFilename[getsrcFilename.Length - 1]; tempFilePathS = arrFilesSource[j]; tempFilePathD = arrFilesDest[i]; TYPES = WatcherChangeTypes.Changed; fs.Close(); fd.Close(); return(false); } //else //{ // return false; //} fs.Close(); fd.Close(); } string strFileName = Path.GetFileName(arrFilesSource[j]); string strDesFilePath = string.Format(@"{0}\{1}", strDesPath, strFileName); if (!File.Exists(strDesFilePath)) { if (IsFileLocked(arrFilesSource[j])) { File.Copy(arrFilesSource[j], strDesFilePath, true); return(false); } } } } if (arrFilesSource.Length == fileCounter) { return(true); } return(false); }
internal FileChange(string directory, string path, WatcherChangeTypes type) { Directory = directory; Name = path; ChangeType = type; }
public FileSystemEventArgs(WatcherChangeTypes changeType, string directory, string name) { throw new NotImplementedException(); }
public abstract WaitForChangedResult WaitForChanged(WatcherChangeTypes changeType);
private static void WriteNlog(string log, WatcherChangeTypes e) { var logger = new Logging(e.ToString()); logger.Info(log); }