private void HandleSettingsChange(object sender, FileSystemEventArgs e) { string jsonSettings; try { jsonSettings = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Configuration.JsonConfig)); } catch (IOException) { return; } FolderWatcherSettings settings; try { settings = JsonConvert.DeserializeObject <FolderWatcherSettings>(jsonSettings); } catch (JsonReaderException) { return; } if (_currentTimeOut == settings.timeout) { return; } _currentTimeOut = settings.timeout; var message = new FolderWatcherSettings { timeout = settings.timeout }; _centralActor.Tell(message); }
public void SaveSettings(FolderWatcherSettings settings) { var serializer = new DataContractJsonSerializer(typeof(FolderWatcherSettings)); using (var fileStream = new FileStream(this.SettingsPath, FileMode.Create)) { using (var jsonWriter = JsonReaderWriterFactory.CreateJsonWriter(fileStream, Encoding.GetEncoding("utf-8"))) { serializer.WriteObject(jsonWriter, settings); jsonWriter.Flush(); } } }
public FolderWatcherSettings GetSettings() { if (File.Exists(this.SettingsPath)) { FolderWatcherSettings settings = null; var serializer = new DataContractJsonSerializer(typeof(FolderWatcherSettings)); using (var fileStream = new FileStream(this.SettingsPath, FileMode.Open)) { try { using (var jsonReader = JsonReaderWriterFactory.CreateJsonReader(fileStream, Encoding.GetEncoding("utf-8"), XmlDictionaryReaderQuotas.Max, null)) { settings = (FolderWatcherSettings)serializer.ReadObject(jsonReader); } } catch (Exception) { settings = null; } } return(settings ?? new FolderWatcherSettings { Folders = new ObservableCollection <FolderDetails>() }); } var blankSettings = new FolderWatcherSettings { Folders = new ObservableCollection <FolderDetails>() }; this.SaveSettings(blankSettings); return(blankSettings); }
private void ReapplySettings() { logger.Info("Reapplying settings ..."); // clear everything that has been wired up so far this.StopWatching(); this.settings = this.iocContainer.Resolve <ISettingsService>().GetSettings(); // add watchers var watchers = new List <IFolderWatcher>(); foreach (var folder in this.settings.Folders) { var watcher = this.iocContainer.Resolve <IFolderWatcher>(); watcher.FolderContentChanged += FolderContentChanged; watcher.Watch(folder); watchers.Add(watcher); } this.watchers = watchers; // load unread notifications var notifications = this.notificationHistoryService.ReadAll(); foreach (var notification in notifications) { var vm = new NotificationViewModel(notification, this.iocContainer); vm.OnDismiss += this.NotificationDismissed; this.Notifications.Add(vm); } this.NotifyOfPropertyChanges("Icon"); this.NotifyOfPropertyChanges("ToolTip"); this.NotifyOfPropertyChanges("IsIconVisible"); }