Beispiel #1
0
        public void AddToJsonRuleList(Rule rule)
        {
            JArray RulesArray;

            using (StreamReader r = new StreamReader(FilePath))
            {
                string json = r.ReadToEnd();
                RulesArray = JArray.Parse(json); // Va chercher la liste storée en JSON.
            }

            RulesArray.Add(JToken.Parse(JsonConvert.SerializeObject(rule))); // Ajoute la nouvelle règle dans le tableau.

            AddToFile(FilePath, RulesArray);
        }
Beispiel #2
0
        public ObservableCollection <Rule> GetRulesListFromJson()
        {
            JArray RulesArray;
            ObservableCollection <Rule> rules = new ObservableCollection <Rule>();

            using (StreamReader r = new StreamReader(FilePath))
            {
                string json = r.ReadToEnd();
                RulesArray = JArray.Parse(json);
            }
            if (!(RulesArray is null))
            {
                foreach (var item in RulesArray.Children())
                {
                    rules.Add(JsonConvert.DeserializeObject <Rule>(item.ToString()));
                }
            }
            return(rules);
        }