/// <summary> /// Creates a new file with the info proviede from the settings object. /// </summary> /// <param name="settings"></param> private void writetoFile(SettingsClass settings) { JsonSerializer serializer = new JsonSerializer() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented, }; if(File.Exists(settings.Filepath)) { File.Delete(settings.Filepath); } FileStream fs = new FileStream(settings.Filepath, FileMode.CreateNew); fs.Position = fs.Length; using (StreamWriter sw = new StreamWriter(fs)) using (JsonWriter js = new JsonTextWriter(sw)) { try { serializer.Serialize(js, settings); } catch (Exception e) { throw new Exception("Problem writing to the file", e); } } }
private void objectFromJSON() { if(!File.Exists(this.settings.Filepath)) { objectToJson(); } // strings the json file string jsonString = File.ReadAllText(settings.Filepath); //Converts it to an object from Settings class this.settings = JsonConvert.DeserializeObject<SettingsClass>(jsonString); //SettingsClass sc1 = JsonConvert.DeserializeObject<SettingsClass>(jsonString); }
public SettingsClass(SettingsClass c) { this.FaceUN = c.FaceUN; this.FacePW = c.FacePW; this.FaceCHK = c.FaceCHK; this.MailUN = c.MailUN; this.MailPW = c.MailPW; this.mailCHK = c.mailCHK; this.TwitCHK = c.TwitCHK; this.Filepath = c.Filepath; }
public void write(SettingsClass settings) { this.writetoFile(settings); }
public JsonHandler() { settings = new SettingsClass(); this.settings.Filepath = "SettingsJson.json"; }
public void load() { this.settings = handler.getSettings(); }