Ejemplo 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();
        }
Ejemplo n.º 2
0
        private void StudyBtn_Click(object sender, RoutedEventArgs e)
        {
            if (chapterList.SelectedItems.Count > 0)
            {
                foreach (chapterItem i in chapterList.SelectedItems)
                {
                    Debug.WriteLine("{0} {1}", i.Name, i.Count);
                    i.c.selected = true;
                    m_config.selectedChapters.Add(i.c.path);
                }

                //save selected chaptes
                m_config.save();

                //load chater marked info to cache
                s_cp.m_db.loadMarkeds(m_config.selectedChapters);

                this.Frame.Navigate(typeof(study));
            }
            else
            {
                showError();
            }
        }
Ejemplo n.º 3
0
        private void bg_process(object sender, BgTask e)
        {
            Debug.WriteLine(string.Format("bg_process {0}", (bgTaskType)e.type));
            switch ((bgTaskType)e.type)
            {
            case bgTaskType.saveFolder:
            {
                //not used
                throw new Exception("not use");

                StorageFolder folder = (StorageFolder)e.data;
                //save last selected folder
                if (folder.Path != m_chapterPgCfg.lastPath)
                {
                    m_chapterPgCfg.lastPath = folder.Path;
                    //clear prev data
                    m_chapterPgCfg.clean();
                    m_chapterPgCfg.save();

                    m_content.m_chapters.Clear();
                }
                var mru = StorageApplicationPermissions.MostRecentlyUsedList;
                mru.Clear();
                string mruToken = mru.Add(folder, folder.Path);
            }
            break;

            case bgTaskType.saveLessonFolder:
            {
                StorageFolder folder = (StorageFolder)e.data;
                //save last selected folder
                if (folder.Path != m_lessonPgCfg.lastPath)
                {
                    m_lessonPgCfg.lastPath = folder.Path;
                    //clear prev data
                    m_lessonPgCfg.selectedLessons.Clear();
                    m_lessonPgCfg.save();

                    m_content.m_lessons.Clear();
                }
                var mru = StorageApplicationPermissions.MostRecentlyUsedList;
                mru.Clear();
                string mruToken = mru.Add(folder, folder.Path);
            }
            break;

            case bgTaskType.loadData:
            {
                m_bgwork.qryFgTask(new FgTask {
                        type = (int)fgTaskType.prepareProgress
                    });

                StorageFolder folder = (StorageFolder)e.data;
                IReadOnlyList <StorageFile> fileList = null;
                var t = Task.Run(async() => {
                        fileList = await folder.GetFilesAsync();
                    });
                t.Wait();
                int n   = fileList.Count;
                int ret = 0;
                for (int i = 0; i < n; i++)
                {
                    t = Task.Run(async() => {
                            ret = await m_content.loadSingleChapter(fileList[i]);
                        });
                    t.Wait();

                    m_bgwork.qryFgTask(new FgTask {
                            type = (int)fgTaskType.updateProgress, data = (double)i * 100 / n
                        });
                }

                m_bgwork.qryFgTask(new FgTask {
                        type = (int)fgTaskType.hideProgress
                    });
            }
            break;

            case bgTaskType.loadLessons:
            {
                m_bgwork.qryFgTask(new FgTask {
                        type = (int)fgTaskType.prepareProgress
                    });

                StorageFolder folder = (StorageFolder)e.data;
                IReadOnlyList <StorageFile> fileList = null;
                var t = Task.Run(async() => {
                        fileList = await folder.GetFilesAsync();
                    });
                t.Wait();
                int n   = fileList.Count;
                int ret = 0;
                for (int i = 0; i < n; i++)
                {
                    t = Task.Run(async() => {
                            ret = await m_content.loadSingleLesson(fileList[i]);
                        });
                    t.Wait();

                    m_bgwork.qryFgTask(new FgTask {
                            type = (int)fgTaskType.updateProgress, data = (double)i * 100 / n
                        });
                }

                m_bgwork.qryFgTask(new FgTask {
                        type = (int)fgTaskType.hideProgress
                    });
            }
            break;

            case bgTaskType.loadDict:
            {
                m_bgwork.qryFgTask(new FgTask {
                        type = (int)fgTaskType.updateStatus, data = "Loading dict ..."
                    });
                m_bgwork.qryFgTask(new FgTask {
                        type = (int)fgTaskType.prepareProgress
                    });
                Task t = Task.Run(() => { myDict.Load(); });
                while (t.Status != TaskStatus.RanToCompletion)
                //while (myDict.loadProgress < 100)
                {
                    m_bgwork.qryFgTask(new FgTask {
                            type = (int)fgTaskType.updateProgress, data = (double)myDict.loadProgress
                        });
                    //myWorker.sleep(100);
                    t.Wait(100);
                }
                Debug.Assert(myDict.loadProgress == 100);
                //Debug.Assert(t.Status == TaskStatus.RanToCompletion);
                m_bgwork.qryFgTask(new FgTask {
                        type = (int)fgTaskType.hideProgress
                    });
                m_bgwork.qryFgTask(new FgTask {
                        type = (int)fgTaskType.updateStatus, data = "Loading completed!"
                    });
            }
            break;

            case bgTaskType.delayNext:
            {
                m_bgwork.qryFgTask(new FgTask {
                        type = (int)fgTaskType.delayNext
                    });
            }
            break;
            }
        }