public FileMdeRepository(MdeConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (string.IsNullOrEmpty(config.MessagesSourcePath)) { throw new ArgumentNullException(nameof(config.MessagesSourcePath)); } _filename = config.MessagesSourcePath; _encoding = config.MessagesSourceEncoding ?? throw new ArgumentNullException(nameof(config.MessagesSourcePath)); }
public FileMdeHub(MdeConfig repositoryConfigs) { if (repositoryConfigs == null) { throw new ArgumentNullException(nameof(repositoryConfigs)); } if (string.IsNullOrWhiteSpace(repositoryConfigs.MessagesSourcePath)) { throw new ArgumentNullException(nameof(repositoryConfigs.MessagesSourcePath)); } string path = Path.GetFullPath(repositoryConfigs.MessagesSourcePath); string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { throw new DirectoryNotFoundException(dir); } _logger.Debug("Initing FileHub: path='{0}'", path); #if DEBUG if (!Directory.Exists(dir)) { _logger.Debug("FileWatcher's directory is not exists: '{0}'", dir); try { var dirInfo = Directory.CreateDirectory(dir); _logger.Debug("FileWatcher's directory '{0}' created", dirInfo.Name); } catch (Exception e) { _logger.Error("{0} | {1}", e.Message, e.InnerException?.Message); throw; } } #endif _fileWatcher = new FileSystemWatcher(dir) { Filter = Path.GetFileName(path), NotifyFilter = NotifyFilters.LastWrite, }; _logger.Debug("FileWatcher inited for file = '{0}'", _fileWatcher.Filter); }