private void LoadPresetData(object param) { //IsBusy = true; StatusMessage = string.Empty; BuildingPresets buildingPresets = null; try { buildingPresets = SerializationHelper.LoadFromFile <BuildingPresets>(PresetsVM.SelectedFile); } catch (Exception ex) { var message = $"Error parsing {nameof(BuildingPresets)}."; Trace.WriteLine($"{message}{Environment.NewLine}{ex}"); MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); StatusMessage = $"{message} -> Maybe wrong selected file?"; return; } PresetsVersion = buildingPresets.Version; fillAvailableTemplates(buildingPresets); fillAvailableIdentifiers(buildingPresets); fillTemplateIdentifierMapping(buildingPresets); AvailableColorSchemes.Clear(); ColorPresets colorPresets = null; try { ColorPresetsLoader loader = new ColorPresetsLoader(); colorPresets = loader.Load(ColorsVM.SelectedFile); } catch (Exception ex) { var message = $"Error parsing {nameof(ColorPresets)}."; Trace.WriteLine($"{message}{Environment.NewLine}{ex}"); MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); StatusMessage = $"{message} -> Maybe wrong selected file?"; return; } foreach (var curScheme in colorPresets.AvailableSchemes) { AvailableColorSchemes.Add(new ColorSchemeViewModel(curScheme)); } //var defaultScheme = loader.LoadDefaultScheme(vmColors.SelectedFile); ColorPresetsVersion = colorPresets.Version; ColorPresetsVersionUpdated = ColorPresetsVersion; SelectedColorScheme = AvailableColorSchemes.First(); //IsBusy = false; }
private void AddColorScheme(object param) { var newScheme = new ColorSchemeViewModel(new ColorScheme { Name = NewColorSchemeName }); AvailableColorSchemes.Add(newScheme); SelectedColorScheme = newScheme; }
private void Save(object param) { try { StatusMessage = string.Empty; var colorPresets = new ColorPresets { Version = ColorPresetsVersionUpdated }; colorPresets.AvailableSchemes.AddRange(AvailableColorSchemes.Select(x => new ColorScheme { Name = x.Name, Colors = x.Colors.Select(color => new PredefinedColor { TargetTemplate = color.TargetTemplate, TargetIdentifiers = color.TargetIdentifiers.ToList(), Color = color.SelectedColor.Value }).ToList() })); var backupFilePath = ColorsVM.SelectedFile + ".bak"; logger.Trace($"create backup of \"{ColorsVM.SelectedFile}\" at \"{backupFilePath}\""); File.Copy(ColorsVM.SelectedFile, backupFilePath, true); StatusMessage = $"Backup created \"{backupFilePath}\"."; logger.Info($"save color presets file: \"{ColorsVM.SelectedFile}\" ({colorPresets.Version})"); SerializationHelper.SaveToFile <ColorPresets>(colorPresets, ColorsVM.SelectedFile); MessageBox.Show("New colors.json was saved.", "Saved", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { var message = "Error saving colors.json."; logger.Error(ex, message); MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); StatusMessage = $"{message} -> Could not save to \"{ColorsVM.SelectedFile}\""; return; } }
private void DeleteColorScheme(object param) { AvailableColorSchemes.Remove(SelectedColorScheme); SelectedColorScheme = AvailableColorSchemes.First(); }
private bool CanAddColorScheme(object param) { return(!String.IsNullOrWhiteSpace(NewColorSchemeName) && !AvailableColorSchemes.Any(x => x.Name.Equals(NewColorSchemeName, StringComparison.OrdinalIgnoreCase))); }