public void Load(string settingsFile = "Settings.json") { try { settingsFile = $"{Environment.CurrentDirectory}\\{settingsFile}"; if (!File.Exists(settingsFile)) { throw new Exception($"Сохраненные настройки не найдены!"); } MainSettings.Instanse = JsonConvert.DeserializeObject <MainSettings>(File.ReadAllText(settingsFile)); } catch (Exception ex) { MainSettings.Instanse = new MainSettings(); MetroDialogs.MainWindowMd("Ошибка!", ex.Message); } finally { MainModel.Instanse = MainSettings.Instanse.MyMainModel ?? new MainModel(); GraphModel.Instanse = MainSettings.Instanse.MyGraphModel ?? new GraphModel(); SwannModel.Instanse = MainSettings.Instanse.MySwannModel ?? new SwannModel(); DichotomiesModel.Instanse = MainSettings.Instanse.MyDichotomiesModel ?? new DichotomiesModel(); GoldenSelectionModel.Instanse = MainSettings.Instanse.MyGoldenSelectionModel ?? new GoldenSelectionModel(); ParabolasModel.Instanse = MainSettings.Instanse.MyParabolasModel ?? new ParabolasModel(); } }
//================================================================= public void Save(string settingsFile = "Settings.json") { try { settingsFile = $"{Environment.CurrentDirectory}\\{settingsFile}"; if (File.Exists(settingsFile)) { File.Delete(settingsFile); } File.WriteAllText(settingsFile, JsonConvert.SerializeObject(MainSettings.Instanse, Formatting.Indented)); } catch (Exception ex) { MetroDialogs.MainWindowMd("Ошибка!", ex.Message); } }