private void ReScan(object sender, FileChangedEvent changedEvent) { if (changedEvent.BeforeTime < changedEvent.UpdateTime) { AutoScan(); } }
private void OnChanged(object sender, FileSystemEventArgs e) { if (e.FullPath.IndexOf(System.IO.Path.GetFileName(_FileToWatch), StringComparison.OrdinalIgnoreCase) >= 0) { FileChangedEvent.Set(); } }
public void FileWasCreated() { var file = Path.Combine(watcherTempDirectory, $"{Guid.NewGuid():N}.txt"); var events = CollectEvents(() => File.WriteAllText(file, "Hello"), 1); events.Should().BeEquivalentTo(FileChangedEvent.CreatedOrUpdated(file)); }
public void FileWasUpdatedAndDeleted() { var events = CollectEvents(() => { File.WriteAllText(filePath, "Hello"); Thread.Sleep(QuietTimeMs * 2); File.Delete(filePath); }, 2); events.Should().BeEquivalentTo(FileChangedEvent.CreatedOrUpdated(filePath), FileChangedEvent.Deleted(filePath)); }
public void FileWasCreatedAndDeleted() { var file = Path.Combine(watcherTempDirectory, $"{Guid.NewGuid():N}.txt"); var events = CollectEvents(() => { File.WriteAllText(file, "Hello"); Thread.Sleep(QuietTimeMs * 2); File.Delete(file); }, 2); events.Should().BeEquivalentTo(FileChangedEvent.CreatedOrUpdated(file), FileChangedEvent.Deleted(file)); }
private void _fw_OnCreated(Object sender, FileChangedEvent e) { //if (txtConsole.InvokeRequired) //{ // txtConsole.Invoke(new Action<Object, FileChangedEvent>(_fw_OnCreated), sender, e); //} //else //{ txtConsole.Text += string.Format("[cre] {0} | {1}", Enum.GetName(typeof(ChangeType), e.ChangeType), e.FullPath) + "\r\n"; //} }
public void FileWasCreatedAndMoved() { var events = CollectEvents(() => { var anotherFilePath = Path.Combine(watcherTempDirectory, $"{Guid.NewGuid():N}"); File.Move(filePath, anotherFilePath); Thread.Sleep(QuietTimeMs * 2); File.WriteAllText(anotherFilePath, "Hello"); Thread.Sleep(QuietTimeMs * 2); }, 2); events.Should().BeEquivalentTo(FileChangedEvent.CreatedOrUpdated(filePath), FileChangedEvent.Deleted(filePath)); }
private void IndexChanges(FileChangedEvent changeEvent) { switch (changeEvent.Type) { case FileChangeType.Deleted: IndexDeletedFile(changeEvent.Path); break; case FileChangeType.CreatedOrUpdated: IndexNewFile(changeEvent.Path); break; } }
public void FileWasCreatedAndRenamed_EscapeFromWatchDirectory() { var sourceFileName = Path.Combine(watcherTempDirectory, $"{Guid.NewGuid():N}.txt"); var destinationFileName = Path.Combine(tempDirectory, $"{Guid.NewGuid():N}.txt"); var events = CollectEvents(() => { File.WriteAllText(sourceFileName, "Hello"); Thread.Sleep(QuietTimeMs * 2); File.Move(sourceFileName, destinationFileName); }, 2); events.Should().BeEquivalentTo(FileChangedEvent.CreatedOrUpdated(sourceFileName), FileChangedEvent.Deleted(sourceFileName)); }
public void HandleChange(FileSystemEventArgs args) { try { switch (args.ChangeType) { case WatcherChangeTypes.Created: { if (File.Exists(args.FullPath)) { this.Files.Add(new LocalFile(args.FullPath, this.FolderPath)); var @event = new FileCreatedEvent(args.FullPath, this.FolderName); this.eventListener.On(@event); Console.WriteLine($"Created: {args.FullPath}"); } break; } case WatcherChangeTypes.Deleted: { var toDelete = this.Files.FirstOrDefault(it => string.Equals(it.AbsolutePath, args.FullPath, StringComparison.InvariantCultureIgnoreCase)); this.Files.Remove(toDelete); var @event = new FileDeletedEvent(args.FullPath, this.FolderName); this.eventListener.On(@event); Console.WriteLine($"Deleted: {args.FullPath}"); break; } case WatcherChangeTypes.Changed: { if (File.Exists(args.FullPath)) { var @event = new FileChangedEvent(args.FullPath, this.FolderName); this.eventListener.On(@event); Console.WriteLine($"Changed: {args.FullPath}"); } break; } } } catch (Exception exception) { Console.WriteLine(exception.ToString()); } }
public void On(FileChangedEvent @event) { string source = @event.Path; string target; Operation operation; if (@event.Sender == this.encryptedFolder.FolderName) { target = this.decryptedFolder.GetAbsolutePath(this.encryptedFolder.GetRelativePath(source)); operation = new DecryptFileOperation(source, target, this.credentials); } else { target = this.encryptedFolder.GetAbsolutePath(this.decryptedFolder.GetRelativePath(source)); operation = new EncryptFileOperation(source, target, this.credentials); } this.operations.Enqueue(operation); }
public void FileWasCreatedAndDirectoryWasRenamed_EntryToWatchDirectory() { var fileName = $"{Guid.NewGuid():N}.txt"; var sourceDirectory = Path.Combine(tempDirectory, $"{Guid.NewGuid():N}"); var sourceFile = Path.Combine(sourceDirectory, fileName); Directory.CreateDirectory(sourceDirectory); var destinationDirectory = Path.Combine(watcherTempDirectory, $"{Guid.NewGuid():N}"); var destinationFile = Path.Combine(destinationDirectory, fileName); var events = CollectEvents(() => { File.WriteAllText(sourceFile, "Hello"); Thread.Sleep(QuietTimeMs * 2); Directory.Move(sourceDirectory, destinationDirectory); }, 1); events.Should().BeEquivalentTo(FileChangedEvent.CreatedOrUpdated(destinationFile)); }
private async Task CompilePile(string pile, bool setupWatchers) { // Here we are combining all files // If one file in a pile changes... all the rest have to too var filePath = Path.Combine(_compilationDirectory.FullName, pile + _compileExtension); var tasks = _pile.FindFiles(pile) .Select(async file => Tuple.Create(await _compiler.CompileFile(file, _compilerManager).ConfigureAwait(false), file)) .ToList(); if (tasks.Any()) { var compiledFiles = await Task.WhenAll(tasks).ConfigureAwait(false); var builder = new StringBuilder(); foreach (var compiledFile in compiledFiles) { // Combine all the outputs builder.Append(compiledFile.Item1.Output); // If we are watching, make sure to watch and compile the original file if (setupWatchers && _pile.IsWatchingFiles && compiledFile.Item1.AdditionalDependencies.Any()) { var changedEvent = new FileChangedEvent(pile, compiledFile.Item2); foreach (var dep in compiledFile.Item1.AdditionalDependencies) { var info = new FileInfo(dep); if (info.Exists) { var watcher = new FileSystemWatcher { Path = info.DirectoryName, Filter = info.Name, NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime }; watcher.Created += (sender, args) => PileOnFileUpdated(pile, changedEvent); watcher.Changed += (sender, args) => PileOnFileUpdated(pile, changedEvent); watcher.Renamed += (sender, args) => PileOnFileUpdated(pile, changedEvent); watcher.Deleted += (sender, args) => PileOnFileUpdated(pile, changedEvent); watcher.EnableRaisingEvents = true; } } } } AttemptWrite(filePath, builder.ToString()); } }
private async Task CompileFile(string pile, FileInfo file, int count, bool setupWatchers) { // Here we are keeping the files seperate... so just compile the single file // However the file will live in a subDirectory var dirPath = Path.Combine(_compilationDirectory.FullName, pile); var filePath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(file.Name) + count + _compileExtension); // Compile/minimise and write to file var fileData = await _compiler.CompileFile(file, _compilerManager).ConfigureAwait(false); // If we are watching, watch the additional deps, but fire the event on the original file if (setupWatchers && _pile.IsWatchingFiles && fileData.AdditionalDependencies.Any()) { var changedEvent = new FileChangedEvent(pile, file); foreach (var dep in fileData.AdditionalDependencies) { var info = new FileInfo(dep); if (info.Exists) { var watcher = new FileSystemWatcher { Path = info.DirectoryName, Filter = info.Name, NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime }; watcher.Created += (sender, args) => PileOnFileUpdated(pile, changedEvent); watcher.Changed += (sender, args) => PileOnFileUpdated(pile, changedEvent); watcher.Renamed += (sender, args) => PileOnFileUpdated(pile, changedEvent); watcher.Deleted += (sender, args) => PileOnFileUpdated(pile, changedEvent); watcher.EnableRaisingEvents = true; } } } AttemptWrite(filePath, fileData.Output); }
private async void PileOnFileUpdated(object sender, FileChangedEvent fileChangedEvent) { if (_combine) { await CompilePile(fileChangedEvent.Pile, false).ConfigureAwait(false); } else { int count = _pile.FindFiles(fileChangedEvent.Pile).TakeWhile(file => file.FullName != fileChangedEvent.File.FullName).Count(); await CompileFile(fileChangedEvent.Pile, fileChangedEvent.File, count, false).ConfigureAwait(false); } }
public bool Equals(FileChangedEvent other) { return(string.Equals(Path, other.Path) && Type == other.Type); }
int IVsFileChangeEvents.DirectoryChanged(string pszDirectory) { FileChangedEvent?.Invoke(this, new TestFileChangedEventArgs(null, pszDirectory, TestFileChangedReason.Changed)); return(VSConstants.S_OK); }
public ChangesScanner(string root, SyncStack syncStack, FileChangedEvent callback) { this.syncStack = syncStack; this.callback = callback; this.root = root; }
private void PileOnFileUpdated(object sender, FileChangedEvent fileChangedEvent) { if (_combine) { CompilePile(fileChangedEvent.Pile); } else { CompileFile(fileChangedEvent.Pile, fileChangedEvent.File); } }
static void OnFileChangedEvent(object sender, EventArgs e) { FileChangedEvent?.Invoke(sender, e); }