Exemplo n.º 1
0
        public void save(myChapterPgCfg cfg)
        {
            Debug.Assert(m_bLoaded);

            //m_dbfile.save();
            List <chapterRec> tmpLst = new List <chapterRec>();

            for (int i = 0; i < cfg.markedInfo.Count; i++)
            {
                string   str = cfg.markedInfo[i];
                string[] arr = str.Split(new char[] { '|' });
                if (arr.Count() != 2)
                {
                    throw new Exception("invalid data");
                }
                chapterRec rec = null;
                string     key = arr[0];
                if (m_dict.ContainsKey(key))
                {
                    rec = m_dict[key];
                    cfg.markedInfo[i] = rec.key + '|' + rec.marked;
                    m_dict.Remove(key);
                    tmpLst.Add(rec);
                }
            }
            foreach (chapterRec rec in m_dict.Values)
            {
                cfg.markedInfo.Add(rec.key + '|' + rec.marked);
            }
            foreach (chapterRec rec in tmpLst)
            {
                m_dict.Add(rec.key, rec);
            }
            cfg.save();
        }
Exemplo n.º 2
0
        //myDbFileCfg m_dbfile;
        public void load(myChapterPgCfg cfg)
        {
            if (m_bLoaded)
            {
                return;
            }
            m_bLoaded = true;
#if use_xml
            //m_dbfile = myDbFileCfg.getInstance();
            //foreach(var ch in m_dbfile.chapters)
            //{
            //    m_dict.Add(ch.key, ch);
            //}
            foreach (string str in cfg.markedInfo)
            {
                string[] arr = str.Split(new char[] { '|' });
                if (arr.Count() != 2)
                {
                    throw new Exception("invalid data");
                }
                chapterRec rec = new chapterRec();
                rec.key    = arr[0];
                rec.marked = arr[1];
                m_dict.Add(arr[0], rec);
            }
#endif
#if !use_xml
            //open file db
            m_file.load();

            //check file db malform

            //load marked info
            chapterRec ch;
            var        error = firstChapter(out ch);
            while (error != readBdError.eof)
            {
                if (error == readBdError.dbMalform)
                {
                    m_file.drop();
                    m_dict.Clear();
                    m_deltedItem.Clear();
                    Debug.Assert(m_cache.Count == 0);
                    break;
                }
                if (ch.isDeleted)
                {
                    m_deltedItem.Add(ch);
                }
                else
                {
                    m_dict.Add(ch.key, ch);
                }
                error = nextChapter(out ch);
            }
#endif
        }
Exemplo n.º 3
0
        contentProvider()
        {
            m_content      = new content();
            m_chapters     = new Dictionary <string, chapter>();
            m_lessons      = new Dictionary <string, lessons>();
            m_db           = new myDb();
            m_mainPgCfg    = myMainPgCfg.getInstance();
            m_chapterPgCfg = myChapterPgCfg.getInstance();
            m_lessonPgCfg  = myLessonPgCfg.getInstance();

            m_content.SaveCompleted += M_content_SaveCompleted;
            m_content.LoadCompleted += M_content_LoadCompleted;
        }
Exemplo n.º 4
0
 public static myChapterPgCfg getInstance()
 {
     if (m_config == null)
     {
         var newCfg = new myChapterPgCfg();
         var t      = Task.Run(async() => m_config = (myChapterPgCfg)await newCfg.load <myChapterPgCfg>());
         t.Wait();
         if (m_config == null)
         {
             m_config = newCfg;
         }
     }
     return(m_config);
 }
Exemplo n.º 5
0
        public void unload(myChapterPgCfg cfg)
        {
            if (!m_bLoaded)
            {
                return;
            }
            m_bLoaded = false;
#if use_xml
            //m_dbfile.save();
#endif
#if !use_xml
            m_file.unload();
#endif
            m_dict.Clear();
            m_cache.Clear();
            m_deltedItem.Clear();
        }
Exemplo n.º 6
0
        private void loadData()
        {
            m_config = myChapterPgCfg.getInstance();

            //load chapter data
            chapterList.Items.Clear();
            int iCur = 0;

            chapterList.ItemsSource = m_data;
            foreach (var i in s_cp.m_chapters)
            {
                var chapter = i.Value;
                var item    = new chapterItem()
                {
                    Name  = chapter.name,
                    Count = chapter.words.Count,
                    c     = chapter
                };
                s_cp.m_db.getMarked(chapter);
                if (chapter.words.Count < chapter.markedIndexs.Count)
                {
                    //db malform
                    Debug.WriteLine("[error] {0} loadData chapter {1} marked data malform", this, chapter.path);
                    chapter.markedIndexs.Clear();
                }

                m_data.Add(item);

                //check selected chapter
                if (m_config.selectedChapters.Contains(chapter.path))
                {
                    m_config.selectedChapters.Remove(chapter.path);
                    chapterList.SelectedItems.Add(item);
                    chapter.selected = false;
                }
                iCur++;
            }

            //load mydb file
            //s_cp.loadDb();
        }
Exemplo n.º 7
0
        public MainPage()
        {
            this.InitializeComponent();

            m_content      = contentProvider.getInstance();
            m_config       = m_content.m_mainPgCfg;
            m_lessonPgCfg  = m_content.m_lessonPgCfg;
            m_chapterPgCfg = m_content.m_chapterPgCfg;

            //test();
            //testWriteData();
            //ApplicationView.PreferredLaunchViewSize = new Size(480, 800);
            //ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;

            //s_content.LoadChapterCompleted += C_LoadCompleted;
            //s_content.LoadMultiChapterCompleted += S_content_LoadMultiChapterCompleted;

            //this page events
            Loaded += MainPage_Loaded;
            //LayoutUpdated += MainPage_LayoutUpdated;
            Unloaded += MainPage_Unloaded;

            initCtrls();

            browserBtn.Tapped += browserBtn_ClickAsync;
            openBtn.Click     += browserBtn_ClickAsync;
            reloadBtn.Click   += reloadBtn_Click;
            addBtn.Click      += btnAdd_Click;
            nextBtn.Click     += btnNext_Click;
            prevBtn.Click     += PrevBtn_Click;
            clean.Click       += btnClean_Click;
            clearBtn.Click    += btnClean_Click;

            //background work
            m_bgwork            = new myWorker();
            m_bgwork.BgProcess += bg_process;
            m_bgwork.FgProcess += fg_process;
        }