private static FileExistsAssertionResult AssertFileExists(TailOptions options) { if (!options.Filename.Any()) return new FileExistsAssertionResult {AssertionFailedReason = "You must specify a file to tail"}; var fileName = options.Filename.First(); if (!File.Exists(fileName)) return new FileExistsAssertionResult { AssertionFailedReason = $"{fileName} does not exist" }; return new FileExistsAssertionResult { FileExists = true }; }
private static void StartFileWatch(TailOptions options) { if (options.Version) SpitVersionInfoAndExit(); var conf = TailOptionsToFileWatchConfiguration(options); ISleeper sleeper = new ThreadSleeper(); IStreamReader streamReader = new TailStreamReader(conf.FileName); TailWatcherProxy.StartWatcher(TailWatcherProxy.WatcherType.File, conf, streamReader, sleeper); }
private static FileWatchConfiguration TailOptionsToFileWatchConfiguration(TailOptions options) { var assertionResult = AssertFileExists(options); if (!assertionResult.FileExists) { System.Console.WriteLine(assertionResult.AssertionFailedReason); Environment.Exit(0); } var conf = new FileWatchConfiguration { PollIntervalInMs = (int) options.SleepIntervalInSeconds*1000, Observer = new ConsoleObserver(), FileName = options.Filename.First(), NumberOfLinesToOutputWhenWatchingStarts = options.Lines }; if (!string.IsNullOrWhiteSpace(options.InclusionFilter)) { conf.WatchFilter = new WatchFilter { InclusionFilter = new Filter { SimpleFilter = options.InclusionFilter } }; } if (!string.IsNullOrWhiteSpace(options.ExclusionFilter)) { conf.WatchFilter = new WatchFilter { ExclusionFilter = new Filter { SimpleFilter = options.ExclusionFilter } }; } return conf; }