private void Run() { this.isRunning = true; var logFilePath = this.logFilePathDiscoveryStrategy.DiscoverLogFile(); this.AutoResetEvent = this.fileReaderAutoResetEventFactory.CreateFileReaderAutoResetEvent(false); var fileSystemWatcher = this.fileReaderFileSystemWatcherFactory.CreateFileReaderFileSystemWatcher(logFilePath, true, this.AutoResetEvent); using (var inputProvider = this.fileReaderInputProviderFactory.CreateFileReaderInputProvider(logFilePath)) { var nextInputLine = string.Empty; while (this.isRunning) { nextInputLine = inputProvider.ReadLine(); if (nextInputLine != null) { var nextParsedCommand = this.commandParsingStrategy.ParseCommand(nextInputLine); if (nextParsedCommand != null) { this.commandUtilizationStrategy.UtilizeCommand(nextParsedCommand); } } else { this.AwaitLogFileChanges(); } } } }
public FileReaderFileSystemWatcher(string filter, bool enableRaisingEvents, IFileReaderAutoResetEvent autoResetEvent) { Guard.WhenArgument(filter, nameof(filter)).IsNullOrEmpty().Throw(); Guard.WhenArgument(autoResetEvent, nameof(IFileReaderAutoResetEvent)).IsNull().Throw(); this.fileSystemWatcher = new FileSystemWatcher("."); this.fileSystemWatcher.Filter = filter; this.fileSystemWatcher.EnableRaisingEvents = enableRaisingEvents; this.fileSystemWatcher.Changed += this.CreateOnChangedEventHandler(autoResetEvent); }
private FileSystemEventHandler CreateOnChangedEventHandler(IFileReaderAutoResetEvent autoResetEvent) { return((sender, args) => autoResetEvent.Set()); }