private void FileChanged(object sender, FileSystemEventArgs e) { var relativePath = e.FullPath.Substring(node.Directory.FullName.Length).TrimStart(Path.DirectorySeparatorChar); if (relativePath.Length > 0) { var targetNode = node.EvaluatePath(relativePath.Split(Path.DirectorySeparatorChar), 0); targetNode?.NotifyFileSystemChanged(e); FileSystemEvents?.Invoke(sender, e); } }
private void ProcessEvents() { _threadStarted = true; while (true) { FileSystemEventBatchArgs batchEventsCopy = null; if (_onClosingEvent.WaitOne(SleepForward)) { break; } lock (_batchLock) { if (_clock.ElapsedMilliseconds <= MillisTimeout) { continue; } if (_batchEvents != null && _batchEvents.FileEvents.Count > 0) { batchEventsCopy = _batchEvents; _batchEvents = null; } else { continue; } } // TODO: squash events here (to avoid having duplicated events) // Invoke listeners try { SquashAndLogChanges(batchEventsCopy); // Squash can discard events (e.g if files excluded) if (batchEventsCopy.FileEvents.Count > 0) { FileSystemEvents?.Invoke(this, batchEventsCopy); } } catch (Exception ex) { Site.Error(ex, $"Unexpected error on SiteWatcher callback. Reason: {ex.GetReason()}"); } } _onClosingEvent.Reset(); }