Beispiel #1
0
        private void Init_Progress()
        {
            var root = xdoc.Element(root_xml_name).Element(xml_traing_progress_applest_name);

            foreach (var e in root.Elements())
            {
                AppletData app_info = new AppletData();
                {
                    app_info.AppletID      = e.Attribute("uid").Value.ToString();
                    app_info.AppletDisplay = e.Attribute("display").Value.ToString();
                    app_info.WordProgress  = new Dictionary <Word, int>();

                    foreach (var e_ in e.Elements())
                    {
                        int  id       = int.Parse(e_.Attribute("ref").Value.ToString());
                        Word w        = GetWord(id);
                        int  progress = int.Parse(e_.Attribute("progress").Value.ToString());

                        if (w != null)
                        {
                            app_info.WordProgress.Add(w, progress);
                        }
                        else
                        {
                            throw new Exception("Some exception in PersonalDictionary.DB.Init_Progress(). Check invariant of xml data");
                        }
                    }
                };

                ApplestsData.Add(app_info);
            }
        }
Beispiel #2
0
        private void Commit_Progress(XDocument doc)
        {
            doc.Element(root_xml_name).Add(new XElement(xml_traing_progress_applest_name));
            var root = doc.Element(root_xml_name).Element(xml_traing_progress_applest_name);

            #region Часть 1. Вносим изменения в прогресс апплетов

            AppletsDataInfo.ForEach(delegate(AppletDataInfo info)
            {
                if (info.AppletData.WordProgress.Keys.Contains(info.Word))
                {
                    info.AppletData.WordProgress[info.Word] = info.Progress;
                }
                else
                {
                    info.AppletData.WordProgress.Add(info.Word, info.Progress);
                }
            });

            #endregion

            #region Часть 2. Записываем все в XDocument

            ApplestsData.ForEach(delegate(AppletData data)
            {
                XElement xe = new XElement("applet");
                xe.Add(new XAttribute("uid", data.AppletID));
                xe.Add(new XAttribute("display", data.AppletDisplay));
                data.WordProgress.Keys.ToList().ForEach(delegate(Word w)
                {
                    XElement temp = new XElement("appletdata");
                    temp.Add(new XAttribute("ref", w.ID));
                    temp.Add(new XAttribute("progress", data.WordProgress[w]));
                    xe.Add(temp);
                });

                root.Add(xe);
            });

            #endregion
        }
Beispiel #3
0
        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();
        }
Beispiel #4
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
        }