Esempio n. 1
0
        public ChangeModel Commit(ChangeModel model)
        {
            ChangeModel wrongItem = new ChangeModel();

            foreach (ChangeItem item in model.Items)
            {
                Logger.Log("Try to change item : " + item.ToString());
                string[] lines = File.ReadAllLines(item.DomainPath);
                if (lines[item.Line].Contains(item.From))
                {
                    Logger.Log("OK");
                    lines[item.Line] = lines[item.Line].Replace(item.From, item.To);
                }
                else
                {
                    wrongItem.AddItem(item);
                    continue;
                }
                Logger.Log("");
                using (StreamWriter sw = new StreamWriter(item.DomainPath, false, System.Text.Encoding.Default))
                {
                    foreach (string line in lines)
                    {
                        sw.WriteLine(line);
                    }
                }
            }
            Logger.Log("Done");
            return(wrongItem);
        }
Esempio n. 2
0
        public static ChangeModel Load(string path)
        {
            string json = "";

            using (StreamReader sr = new StreamReader(path))
            {
                // TODO change to StringBuilder
                json += sr.ReadToEnd();
            }
            ChangeModel returnModel = new ChangeModel();
            dynamic     model       = JsonConvert.DeserializeObject(json);

            foreach (dynamic obj in model.Items)
            {
                returnModel.AddItem(new ChangeItem(
                                        (string)obj.DomainPath,
                                        (int)obj.Line,
                                        (string)obj.From,
                                        (string)obj.To));
            }
            return(returnModel);
        }