/// <summary> /// Executes the <see cref="OpenConfigCommand"/> /// </summary> private void ExecuteOpenConfigCommand() { var vm = new BudgetConfigViewModel(this.Thing, this.BudgetConfig); var result = (BudgetConfigDialogResult)this.DialogNavigationService.NavigateModal(vm); if (result != null && result.Result.HasValue && result.Result.Value) { this.BudgetConfig = result.BudgetConfig; } }
/// <summary> /// Executes the <see cref="LoadConfigCommand"/> /// </summary> private void ExecuteLoadConfigCommand() { var result = this.openSaveFileDialogService.GetOpenFileDialog(true, true, false, "JSON(.json) | *.json", ".json", "", 1); if (result == null || result.Length != 1) { return; } var filePath = result.Single(); try { BudgetConfigDto fileconfig; using (var filestream = new FileStream(filePath, FileMode.Open)) using (var sr = new StreamReader(filestream)) using (var reader = new JsonTextReader(sr)) { var serializer = new JsonSerializer { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Include }; serializer.Converters.Add(new BudgetConfigJsonConverter()); fileconfig = serializer.Deserialize <BudgetConfigDto>(reader); } var vm = new BudgetConfigViewModel(this.Thing, fileconfig); var configResult = (BudgetConfigDialogResult)this.DialogNavigationService.NavigateModal(vm); if (configResult != null && configResult.Result.HasValue && configResult.Result.Value) { this.BudgetConfig = configResult.BudgetConfig; } } catch (Exception e) { logger.Error("An exception occurred when reading the configuration file {0}", e.Message); } }