Example #1
0
        private void Commit_Word()
        {
            var create = WordsInfo.Where(i => i.Word == null).ToArray();

            int id = Words[Words.Count - 1].ID;

            foreach (var item in create)
            {
                id++;

                var      root = xdoc.Element("library").Element("GlobalDictionary");
                XElement xe   = new XElement("word");
                xe.Add(new XAttribute("id", id));
                xe.Add(new XAttribute("en", item.En));
                xe.Add(new XAttribute("ru", item.Ru));
                xe.Add(new XAttribute("date_add", DateTime.Now.ToString()));
                xe.Add(new XAttribute("date_modified", DateTime.Now.ToString()));
                root.Add(xe);
            }
        }
Example #2
0
        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
        }