public TelemetryDataRepository(IFileSystem fileSystem, IFileSystemWatcherFactory fileSystemWatcherFactory) { this.fileSystem = fileSystem; EnsureFileExists(StorageFilePath); ReadFromXmlFile(); fileWatcher = fileSystemWatcherFactory.CreateNew(); fileWatcher.Path = Path.GetDirectoryName(StorageFilePath); fileWatcher.Filter = Path.GetFileName(StorageFilePath); fileWatcher.NotifyFilter = NotifyFilters.LastWrite; fileWatcher.EnableRaisingEvents = true; fileWatcher.Changed += OnStorageFileChanged; }
public SingleFileMonitor(IFileSystemWatcherFactory factory, IFileSystem fileSystem, string filePathToMonitor, ILogger logger) { this.MonitoredFilePath = filePathToMonitor; EnsureDirectoryExists(filePathToMonitor, fileSystem, logger); fileWatcher = factory.CreateNew(); fileWatcher.Path = Path.GetDirectoryName(filePathToMonitor); // NB will throw if the directory does not exist fileWatcher.Filter = Path.GetFileName(filePathToMonitor); fileWatcher.NotifyFilter = System.IO.NotifyFilters.CreationTime | System.IO.NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; fileWatcher.Changed += OnFileChanged; fileWatcher.Created += OnFileChanged; fileWatcher.Deleted += OnFileChanged; fileWatcher.Renamed += OnFileChanged; this.logger = logger; }