private void Init_Dic() { var root = xdoc.Element(root_xml_name).Element(xml_personal_dictionaries_name); foreach (var e in root.Elements()) { Dictionary dic = new Dictionary(); { dic.Name = e.Attribute("name").Value.ToString(); dic.Description = e.Attribute("descr").Value.ToString(); dic.COST = bool.Parse(e.Attribute("cost").Value.ToString()); if (dic.COST) { dic.Words = this.Words; } else { string[] ids = e.Attribute("words").Value.ToString().Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries); dic.Words = new List <Word>(); dic.Words.AddRange(GetWord(ids)); } }; Dictionaties.Add(dic); } Dictionaties.Sort(); string currentDic = Settings.Get()["PersonalDictionary.CurrentDictionaty"]; if (currentDic != null) { var findDic = Dictionaties.Where(d => d.Name == currentDic).ToArray(); if (findDic.Length == 1) { CurrentDictionaty = findDic[0]; } else if (Dictionaties.Where(d => d.COST).ToArray().Length > 0) { CurrentDictionaty = Dictionaties.Where(d => d.COST).ToArray()[0]; } else { throw new Exception("Не найден словарь по умолчанию, системный словарь не обнаружен."); } } else { CurrentDictionaty = Dictionaties[0]; } }
private void Commit_Dic(XDocument doc) { doc.Element(root_xml_name).Add(new XElement(xml_personal_dictionaries_name)); var root = doc.Element(root_xml_name).Element(xml_personal_dictionaries_name); #region Часть 1. Вносятся изменения в существующие словари и создаются новые DictionariesInfo.Where(i => (i.Dictionary != null)).ToList().ForEach(delegate(DictionaryInfo info) { if (info.Description != null) //Изменения в описание словаря { if (info.Description != string.Empty) { info.Dictionary.Description = info.Description; } } if (info.Name != null) //Изменение в наименование словаря { if (info.Name != string.Empty) { info.Dictionary.Name = info.Name; } } if (info.WordsNew != null && info.WordsNew.Count != 0) //Добавляем новые слова { info.Dictionary.Words.AddRange(info.WordsNew); } if (info.WordsExclude != null && info.WordsExclude.Count != 0) //Исключаем слова из словаря { info.WordsExclude.ForEach(delegate(Word w) { info.Dictionary.Words.Remove(w); }); } }); DictionariesInfo.Where(i => (i.Dictionary == null)).ToList().ForEach(delegate(DictionaryInfo info) { Dictionary dic = new Dictionary(); dic.Name = info.Name; dic.Description = info.Description; this.Dictionaties.Add(dic); }); #endregion #region Часть 2. Удаляем словари DictionariesInfoDelete.ForEach(delegate(DictionaryInfo info) { Dictionaties.Remove(info.Dictionary); }); #endregion #region Часть 3. Записываем все в XDocument Dictionaties.ForEach(delegate(Dictionary d) { XElement xe = new XElement("dictionary"); xe.Add(new XAttribute("name", d.Name)); xe.Add(new XAttribute("descr", d.Description)); xe.Add(new XAttribute("cost", d.COST)); if (d.COST) { xe.Add(new XAttribute("words", string.Empty)); } else { string words = string.Empty; d.Words.ForEach(delegate(Word w) { words += "#" + w.ID; }); xe.Add(new XAttribute("words", words)); } root.Add(xe); }); #endregion }
internal void Init() { if (Words == null) { Words = new List <Word>(); } else { Words.Clear(); } if (Dictionaties == null) { Dictionaties = new List <Dictionary>(); } else { Dictionaties.Clear(); } if (ApplestsData == null) { ApplestsData = new List <AppletData>(); } else { ApplestsData.Clear(); } if (WordsInfo == null) { WordsInfo = new List <WordInfo>(); } else { WordsInfo.Clear(); } if (WordsInfoDelete == null) { WordsInfoDelete = new List <WordInfo>(); } else { WordsInfoDelete.Clear(); } if (DictionariesInfo == null) { DictionariesInfo = new List <DictionaryInfo>(); } else { DictionariesInfo.Clear(); } if (DictionariesInfoDelete == null) { DictionariesInfoDelete = new List <DictionaryInfo>(); } else { DictionariesInfoDelete.Clear(); } if (AppletsDataInfo == null) { AppletsDataInfo = new List <AppletDataInfo>(); } else { AppletsDataInfo.Clear(); } if (AppletsDataInfoDelete == null) { AppletsDataInfoDelete = new List <AppletDataInfo>(); } else { AppletsDataInfoDelete.Clear(); } currentDictionaty = null; xdoc = XDocument.Load(Environment.CurrentDirectory + "\\" + xml_Name); Init_Word(); Init_Dic(); Init_Progress(); }
private void Commit_Word(XDocument doc) { doc.Element(root_xml_name).Add(new XElement(xml_global_dictionary_name)); var root = doc.Element(root_xml_name).Element(xml_global_dictionary_name); #region Часть 1. Удаление слов из всех словарей и прогрессов WordsInfoDelete.ForEach(delegate(WordInfo info) { Dictionaties.ForEach(delegate(Dictionary d) //Удаляем из всех словарей { d.Words.Remove(info.Word); }); ApplestsData.ForEach(delegate(AppletData applet) //Из прогресса всех апплетов { applet.WordProgress.Remove(info.Word); }); Words.Remove(info.Word); // Из глобальной коллелкции (хотя словарь "все" ссылается на нее, так что как правило слово уже удалено) }); #endregion #region Часть 2. Вносятся изменения в существующие слова WordsInfo.Where(i => (i.Word != null)).ToList().ForEach(delegate(WordInfo info) { if (info.Ru != string.Empty) { info.Word.Ru = info.Ru; } if (info.En != string.Empty) { info.Word.En = info.En; } info.Word.Modified = DateTime.Now; }); #endregion #region Часть 3. Записываем все в XDocument Words.ForEach(delegate(Word w) { XElement xe = new XElement("word"); xe.Add(new XAttribute("id", w.ID)); xe.Add(new XAttribute("en", w.En)); xe.Add(new XAttribute("ru", w.Ru)); xe.Add(new XAttribute("date_add", w.Add)); xe.Add(new XAttribute("date_modified", w.Modified)); root.Add(xe); }); #endregion #region Часть 4. Записываем новыве слова int id = (Words.Count == 0) ? 0 : Words[Words.Count - 1].ID; WordsInfo.Where(i => (i.Word == null)).ToList().ForEach(delegate(WordInfo info) { id++; XElement xe = new XElement("word"); xe.Add(new XAttribute("id", id)); xe.Add(new XAttribute("en", info.En)); xe.Add(new XAttribute("ru", info.Ru)); xe.Add(new XAttribute("date_add", DateTime.Now.ToString())); xe.Add(new XAttribute("date_modified", DateTime.Now.ToString())); root.Add(xe); }); #endregion }