public void Save(JsonConfigModel json) { StreamWriter sw = new StreamWriter(Application.UserAppDataPath + "\\processes.json", false); string jsonString = JsonConvert.SerializeObject(json, Formatting.None); sw.Write(jsonString); sw.Close(); }
public MainWindow() { InitializeComponent(); json = PersistenceProvider.Load(); //SwitchProfile(json.defaultProfile, true); Registrar.Updated += Registrar_Changed; Registrar.Added += Registrar_Changed; Registrar.Removed += Registrar_Changed; BuildProfileSelector(); }
public JsonConfigModel ParseVersionOne(JObject jsconfig) { JsonConfigModel json = new JsonConfigModel(); try { json.version = (String)jsconfig.GetValue("version"); json.defaultProfile = (int)jsconfig.GetValue("defaultProfile"); IList<JToken> processes = jsconfig["profiles"].Children().ToList(); ProfileConfigModel p = new ProfileConfigModel(); foreach (JToken conf in processes) { Config c = JsonConvert.DeserializeObject<Config>(conf.ToString()); Console.WriteLine("getting config is ok"); if (c.uid == null || c.uid == "") { c.uid = Guid.NewGuid().ToString(); } //json.processes.Add(c); p.processes.Add(c); } json.profiles.Add(p); Save(json); // update to the new format } catch (Exception ex) { Console.WriteLine("File read problem: " + ex.Data.ToString()); json = new JsonConfigModel(); json.version = "1.1"; json.defaultProfile = 0; json.profiles = new List<ProfileConfigModel>(); ProfileConfigModel profile = new ProfileConfigModel(); profile.name = "Default"; profile.processes = new List<Config>(); json.profiles.Add(profile); } return json; }
public JsonConfigModel Load() { Console.WriteLine(Application.UserAppDataPath + "\\process.json"); JsonConfigModel json; try { StreamReader configReader = File.OpenText(Application.UserAppDataPath + "\\processes.json"); JObject jsconfig = (JObject)JToken.ReadFrom(new JsonTextReader(configReader)); String version = (String)jsconfig.GetValue("version"); if (version == "1.0") { json = ParseVersionOne(jsconfig); } else if (version == "1.1") { json = ParseVersionOneOne(jsconfig); } else { throw new Exception("No config version, falling back to 1.1"); } configReader.Close(); } catch (Exception ex) { Console.WriteLine("File read problem: " + ex.Data.ToString()); json = new JsonConfigModel(); json.version = "1.1"; json.defaultProfile = 0; json.profiles = new List<ProfileConfigModel>(); ProfileConfigModel profile = new ProfileConfigModel(); profile.name = "Default"; profile.processes = new List<Config>(); json.profiles.Add(profile); //json.profiles //json.processes = new List<Config>(); } return json; }
public JsonConfigModel ParseVersionOneOne(JObject jsconfig) { JsonConfigModel json = new JsonConfigModel(); try { json.version = (String)jsconfig.GetValue("version"); json.defaultProfile = (int)jsconfig.GetValue("defaultProfile"); IList<JToken> profiles = jsconfig["profiles"].Children().ToList(); json.profiles = new List<ProfileConfigModel>(); foreach (JToken profile in profiles) { ProfileConfigModel p = JsonConvert.DeserializeObject<ProfileConfigModel>(profile.ToString()); json.profiles.Add(p); } Console.WriteLine("---- CORRECTLY LOADED CONFIG ----"); } catch (Exception ex) { json = new JsonConfigModel(); json.version = "1.1"; json.defaultProfile = 0; json.profiles = new List<ProfileConfigModel>(); ProfileConfigModel profile = new ProfileConfigModel(); profile.name = "Default"; profile.processes = new List<Config>(); json.profiles.Add(profile); } return json; }