public int CheckAndProcessEvents() { if (processingEvents) { signalProcessingEventsDone.Wait(cancellationToken); return(lastCountOfProcessedEvents); } signalProcessingEventsDone.Reset(); processingEvents = true; var processedEventCount = 0; var fileEvents = nativeInterface.GetEvents(); if (fileEvents.Length > 0) { processedEventCount = ProcessEvents(fileEvents); } if (worktreeNativeInterface != null) { fileEvents = worktreeNativeInterface.GetEvents(); if (fileEvents.Length > 0) { processedEventCount = processedEventCount + ProcessEvents(fileEvents); } } lastCountOfProcessedEvents = processedEventCount; processingEvents = false; signalProcessingEventsDone.Set(); return(processedEventCount); }
public int CheckAndProcessEvents() { if (processingEvents) { signalProcessingEventsDone.Wait(cancellationToken); return(lastCountOfProcessedEvents); } signalProcessingEventsDone.Reset(); processingEvents = true; var processedEventCount = 0; var fileEvents = nativeInterface.GetEvents(); if (fileEvents.Length > 0) { Logger.Trace("Handling {0} Events", fileEvents.Length); processedEventCount = ProcessEvents(fileEvents); Logger.Trace("Processed {0} Events", processedEventCount); } lastCountOfProcessedEvents = processedEventCount; processingEvents = false; signalProcessingEventsDone.Set(); return(processedEventCount); }
static int Main(string[] args) { string path = null; if (args.Any()) { path = args[0]; } if (string.IsNullOrEmpty(path)) { Console.WriteLine("Missing Path"); return(1); } Console.WriteLine("Monitoring Path: " + path); using (var nativeInterface = new NativeInterface(path)) { var continueFlag = true; while (continueFlag) { var events = nativeInterface.GetEvents(); if (events.Any()) { foreach (Event @event in events) { Console.WriteLine("{0}: {1}", @event.Type, @event.FileA); } } Console.Write("Press any key to continue or 'q' to quit: "); var read = Console.ReadKey(); Console.WriteLine(string.Empty); if (read.KeyChar == 'q' || read.KeyChar == 'Q') { continueFlag = false; } } } return(0); }
public int CheckAndProcessEvents() { if (processingEvents) { signalProcessingEventsDone.Wait(cancellationToken); return(lastCountOfProcessedEvents); } signalProcessingEventsDone.Reset(); processingEvents = true; lastCountOfProcessedEvents = 0; var fileEvents = nativeInterface.GetEvents(); if (fileEvents.Length > 0) { Logger.Trace("Processing {0} Events", fileEvents.Length); } var repositoryChanged = false; foreach (var fileEvent in fileEvents) { if (!running) { break; } if (cancellationToken.IsCancellationRequested) { Stop(); break; } //Logger.Trace(fileEvent.Describe()); var eventDirectory = new NPath(fileEvent.Directory); var fileA = eventDirectory.Combine(fileEvent.FileA); NPath fileB = null; if (fileEvent.FileB != null) { fileB = eventDirectory.Combine(fileEvent.FileB); } // handling events in .git/* if (fileA.IsChildOf(paths.DotGitPath)) { HandleEventInDotGit(fileEvent, fileA, fileB); } else { if (repositoryChanged || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath))) { continue; } repositoryChanged = true; } lastCountOfProcessedEvents++; } if (repositoryChanged) { Logger.Trace("RepositoryChanged"); RepositoryChanged?.Invoke(); } processingEvents = false; signalProcessingEventsDone.Set(); return(lastCountOfProcessedEvents); }
private void WatcherLoop() { Logger.Trace("Starting watcher"); while (running) { if (cancellationToken.IsCancellationRequested) { Stop(); break; } var fileEvents = nativeInterface.GetEvents(); if (fileEvents.Any()) { Logger.Trace("Processing {0} Events", fileEvents.Length); } var repositoryChanged = false; foreach (var fileEvent in fileEvents) { if (!running) { break; } if (cancellationToken.IsCancellationRequested) { Stop(); break; } //Logger.Trace(fileEvent.Describe()); var eventDirectory = new NPath(fileEvent.Directory); var fileA = eventDirectory.Combine(fileEvent.FileA); NPath fileB = null; if (fileEvent.FileB != null) { fileB = eventDirectory.Combine(fileEvent.FileB); } // handling events in .git/* if (fileA.IsChildOf(paths.DotGitPath)) { HandleEventInDotGit(fileEvent, fileA, fileB); } else { if (repositoryChanged || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath))) { continue; } repositoryChanged = true; } } if (repositoryChanged) { Logger.Trace("RepositoryChanged"); RepositoryChanged?.Invoke(); } if (pauseEvent.Wait(200)) { break; } } }