/// <summary> /// Initializes a new instance of the <see cref="T:System.Object" /> class. /// </summary> public FileMonitorViewModel(string filePath, string fileName, string encodingName, bool bufferedRead) { Preconditions.CheckNotEmptyOrNull(filePath); Preconditions.CheckNotEmptyOrNull(fileName); FilePath = filePath; _fileName = fileName; FileExists = File.Exists(filePath); try { _encoding = Encoding.GetEncoding(encodingName); } catch (Exception) { MessageBox.Show($"Could not use encoding {encodingName}. Defaulting to UTF8 instead.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } _encoding = _encoding ?? Encoding.UTF8; _encodingName = _encoding.BodyName; _fileMonitor = new TimedFileMonitor(filePath, _encoding, TimeSpan.FromSeconds(Settings.Default.TimerIntervalSeconds)) { BufferedRead = bufferedRead }; _fileMonitor.FileUpdated += FileMonitorOnFileUpdated; _fileMonitor.FileDeleted += FileMonitorOnFileDeleted; _fileMonitor.FileCreated += FileMonitorOnFileCreated; _fileMonitor.FileRenamed += FileMonitorOnFileRenamed; Settings.Default.PropertyChanged += SettingsChanged; }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object" /> class. /// </summary> public FileMonitorViewModel(string filePath, string fileName, string encodingName, bool bufferedRead) { Preconditions.CheckNotEmptyOrNull(filePath); Preconditions.CheckNotEmptyOrNull(fileName); FilePath = filePath; _fileName = fileName; FileExists = File.Exists(filePath); try { _encoding = Encoding.GetEncoding(encodingName); } catch (Exception) { MessageBox.Show($"Could not use encoding {encodingName}. Defaulting to UTF8 instead.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } _encoding = _encoding ?? Encoding.UTF8; _encodingName = _encoding.BodyName; _fileMonitor = new TimedFileMonitor(filePath, _encoding, TimeSpan.FromSeconds(Settings.Default.TimerIntervalSeconds)) { BufferedRead = bufferedRead }; _fileMonitor.FileUpdated += FileMonitorOnFileUpdated; _fileMonitor.FileDeleted += FileMonitorOnFileDeleted; _fileMonitor.FileCreated += FileMonitorOnFileCreated; _fileMonitor.FileRenamed += FileMonitorOnFileRenamed; Settings.Default.PropertyChanged += SettingsChanged; }