Esempio n. 1
0
        /// <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); 
                }
            }
        }
Esempio n. 2
0
        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);

        }
Esempio n. 3
0
        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; 
        }
Esempio n. 4
0
 public void write(SettingsClass settings)
 {
     this.writetoFile(settings); 
 }
Esempio n. 5
0
 public JsonHandler()
 {
     settings = new SettingsClass();
     this.settings.Filepath = "SettingsJson.json";
 }
Esempio n. 6
0
 public  void load()
 {
     this.settings = handler.getSettings();
 }