Пример #1
0
        internal static void BuildHtmlDocs(FrmBuildHtmlDocument.ProcessInfo ProcessInfoHandler)
        {
            string[] all_cards_paths = Globals.GetPathOfEachCard();
            foreach (string card_path in all_cards_paths)
            {
                try
                {
                    BuildHtmlDocs(card_path, ProcessInfoHandler);
                }
                catch
                {
                    continue;
                }
            }

            string[] all_groups = Globals.GetPathOfEachGroup();
            if (all_groups != null)
            {
                foreach (string group in all_groups)
                {
                    try
                    {
                        BuildHtmlGroupInfo(group, ProcessInfoHandler);
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            BuildRootDocument(ProcessInfoHandler);
        }
Пример #2
0
        public static string[] GetPathOfEachCard(string Group, int Stage)
        {
            string[]      all_cards = Globals.GetPathOfEachCard(Group);
            List <string> card_list = new List <string>();

            foreach (string c in all_cards)
            {
                try
                {
                    string     manifest_file = c + "\\manifest.man";
                    KeyValPair kv            = new KeyValPair(';', ':');
                    kv.Load(manifest_file);
                    int stg = int.Parse(kv.GetVal("stage"));
                    if (stg == Stage)
                    {
                        card_list.Add(c);
                    }
                }
                catch
                {
                    continue;
                }
            }
            return(card_list.ToArray());
        }
Пример #3
0
        internal static string[] GetPathOfEachMissedCard()
        {
            string[] all_cards = Globals.GetPathOfEachCard();
            if (all_cards == null)
            {
                // MessageBox.Show("No cards found.");
                return(null);
            }
            List <string> pending_cards = new List <string>();

            foreach (string c in all_cards)
            {
                try
                {
                    MultiCalendar mc            = MultiCalendar.FromDateTime(DateTime.Now);
                    double        gdp_now       = mc.GetGdp();
                    string        manifest_file = c + "\\manifest.man";
                    KeyValPair    kv            = new KeyValPair(';', ':');
                    kv.Load(manifest_file);
                    double nv_gdp = double.Parse(kv.GetVal("next_visit"));
                    if (nv_gdp < gdp_now)
                    {
                        pending_cards.Add(c);
                    }
                }
                catch
                {
                    continue;
                }
            }
            return(pending_cards.ToArray());
        }
Пример #4
0
        internal static string[] GetPathOfEachMissedCard(string GroupPath)
        {
            string[]      cards        = Globals.GetPathOfEachCard(GroupPath);
            List <string> missed_cards = new List <string>();

            foreach (string c in cards)
            {
                try
                {
                    MultiCalendar mc            = MultiCalendar.FromDateTime(DateTime.Now);
                    double        gdp_now       = mc.GetGdp();
                    string        manifest_file = c + "\\manifest.man";
                    KeyValPair    kv            = new KeyValPair(';', ':');
                    kv.Load(manifest_file);
                    double nv_gdp = double.Parse(kv.GetVal("next_visit"));
                    if (nv_gdp < gdp_now)
                    {
                        missed_cards.Add(c);
                    }
                }
                catch
                {
                    continue;
                }
            }
            return(missed_cards.ToArray());
        }
Пример #5
0
        public bool Init(InitCondition Condition)
        {
            CurrentFace = Faces.QuestionFace;
            bool is_ok = CheckCardsFolder();

            if (is_ok == false)
            {
                MessageBox.Show("Initialization failed");
            }

            switch (Condition)
            {
            case InitCondition.AllCards:
                this.Cards = Globals.GetListOfCards(Globals.GetPathOfEachCard());
                break;

            case InitCondition.PendingCards:
                this.Cards = Globals.GetListOfCards(Globals.GetPathOfEachPendingCard());
                break;

            case InitCondition.MissedCards:
                this.Cards = Globals.GetListOfCards(Globals.GetPathOfEachMissedCard());
                break;

            case InitCondition.SingleSpecifiedCard:
                this.Cards = Globals.GetListOfCards(new string[] { this.SingleSpecifiedCardFolder });
                break;
            }
            this.CurrentCardIndex = 0;
            Present();
            return(is_ok);
        }
Пример #6
0
        private static void BuildHtmlGroupInfo(string group, FrmBuildHtmlDocument.ProcessInfo ProcessInfoHandler)
        {
            if (ProcessInfoHandler != null)
            {
                ProcessInfoHandler(group);
            }

            string[] card_paths = Globals.GetPathOfEachCard(group);
            if (card_paths == null)
            {
                return;
            }

            byte[] file_bytes     = GroupTemplate;
            string card_group_doc = ASCIIEncoding.ASCII.GetString(file_bytes);

            card_group_doc = card_group_doc.Replace("$home", GetButton("Home", 100, 30, "../RememberIt.html"));
            card_group_doc = card_group_doc.Replace("$group_name", Globals.GetLastPartOfDir(group));
            card_group_doc = card_group_doc.Replace("$missed_cards", GetButtonsForMissedCards(group));
            card_group_doc = card_group_doc.Replace("$pending_cards", GetButtonsForPendingCards(group));
            card_group_doc = card_group_doc.Replace("$stage_0", GetButtonsForStage(group, 0));
            card_group_doc = card_group_doc.Replace("$stage_1", GetButtonsForStage(group, 1));
            card_group_doc = card_group_doc.Replace("$stage_2", GetButtonsForStage(group, 2));
            card_group_doc = card_group_doc.Replace("$stage_3", GetButtonsForStage(group, 3));
            card_group_doc = card_group_doc.Replace("$stage_4", GetButtonsForStage(group, 4));
            card_group_doc = card_group_doc.Replace("$stage_5", GetButtonsForStage(group, 5));
            file_bytes     = ASCIIEncoding.ASCII.GetBytes(card_group_doc);

            if (file_bytes.Length <= 3)
            {
                return;
            }
            file_bytes[0] = 0xEF;
            file_bytes[1] = 0xBB;
            file_bytes[2] = 0xBF;
            File.WriteAllBytes(group + "/Group.html", file_bytes);


            //foreach (string cp in card_paths)
            //{
            //    try
            //    {

            //    }
            //    catch
            //    {
            //        continue;
            //    }
            //}
        }
Пример #7
0
        internal static string[] GetPathOfEachCard()
        {
            List <string> all_cards = new List <string>();

            string[] all_groups = GetPathOfEachGroup();
            if (all_groups == null)
            {
                return(null);
            }

            for (int i = 0; i < all_groups.Length; i++)
            {
                string[] cards_in_group = Globals.GetPathOfEachCard(all_groups[i]);
                all_cards.AddRange(cards_in_group);
            }
            return(all_cards.ToArray());
        }
Пример #8
0
        void PresentAllCards(string CardGroupPath)
        {
            string[] paths = null;
            if (CardGroupPath == "[ALL]")
            {
                paths = Globals.GetPathOfEachCard();
            }
            else
            {
                paths = Globals.GetPathOfEachCard(CardGroupPath);
            }

            var             cards = Globals.GetListOfCards(paths);
            CtrlCardBrowser cb    = new CtrlCardBrowser();

            cb.Init(cards);
            wndMainWindow.PresentContent(cb);
        }
Пример #9
0
        private static string GetButtonsForStage(string CardGroup, int Stage)
        {
            string buttons = "";

            string[] pending_cards = Globals.GetPathOfEachCard(CardGroup, Stage);
            if (pending_cards == null)
            {
                return("");
            }
            var cards = Globals.GetListOfCards(pending_cards);

            foreach (Card card in cards)
            {
                string btn_text = Globals.GetLastPartOfDir(card.CardAbsPath);
                string href     = string.Format("{0}/Q.html", btn_text);
                buttons += GetButton(btn_text, 200, 30, href);
                buttons += "<br />";
                buttons += "\r\n";
            }
            return(buttons);
        }
Пример #10
0
        public static List <string> GetListOfDefectiveCards()
        {
            List <string> defective_cards = new List <string>();

            string[] all_cards_paths = Globals.GetPathOfEachCard();
            if (all_cards_paths == null)
            {
                return(defective_cards);
            }

            foreach (string cp in all_cards_paths)
            {
                string question_dir = cp + "\\Q\\";
                if (Directory.Exists(question_dir) == false)
                {
                    defective_cards.Add(cp);
                    continue;
                }
                string[] question_files = Directory.GetFiles(question_dir);
                if (question_files == null || question_files.Length == 0)
                {
                    defective_cards.Add(cp);
                    continue;
                }

                string answer_dir = cp + "\\A\\";
                if (Directory.Exists(answer_dir) == false)
                {
                    defective_cards.Add(cp);
                    continue;
                }
                string[] answer_files = Directory.GetFiles(answer_dir);
                if (answer_files == null || answer_files.Length == 0)
                {
                    defective_cards.Add(cp);
                    continue;
                }
            }
            return(defective_cards);
        }
        private List <Card> FindMatch(string TextToSearch)
        {
            List <Card> matched_cards = new List <Card>();

            string[] card_paths = null;
            if (cmbCardGroups.SelectedIndex == 0)
            {
                card_paths = Globals.GetPathOfEachCard();
            }
            else
            {
                card_paths = Globals.GetPathOfEachCard(CardGroupPaths[cmbCardGroups.SelectedIndex - 1]);
            }

            var cards = Globals.GetListOfCards(card_paths);

            foreach (Card card in cards)
            {
                List <string> text_file_list = new List <string>();

                string[] question_text_files = Globals.GetListOfTextFiles(card.QuestionAbsPath);
                string[] answer_text_files   = Globals.GetListOfTextFiles(card.AnswerAbsPath);
                string[] reminder_text_files = Globals.GetListOfTextFiles(card.ReminderAbsPath);

                text_file_list.AddRange(question_text_files);
                text_file_list.AddRange(answer_text_files);
                text_file_list.AddRange(reminder_text_files);

                foreach (string file in text_file_list)
                {
                    string file_text = File.ReadAllText(file);
                    if (file_text.IndexOf(TextToSearch) >= 0)
                    {
                        matched_cards.Add(card);
                        break;
                    }
                }
            }
            return(matched_cards);
        }
        private void FrmSendCardsToPhone_Load(object sender, EventArgs e)
        {
            string[] all_cards = Globals.GetPathOfEachCard();
            lbCards.Items.AddRange(all_cards);

        }
Пример #13
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            dgvCards.Rows.Clear();
            string[] Phone_cards = com.GetListOfCards(cmbPhoneCardGroup.SelectedItem.ToString());
            string[] Pc_cards =null;
            int row = 0;

            foreach (string phone_side_card in Phone_cards)
            {
                int indx = dgvCards.Rows.Add(1);
                dgvCards.Rows[indx].Cells[clmnRow.Index].Value = ++row;
                dgvCards.Rows[indx].Cells[clmnSelectPcCard.Index].Value = false;
                dgvCards.Rows[indx].Cells[clmnCard.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnAction.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnSelectPhCard.Index].Value = false;
                dgvCards.Rows[indx].Cells[clmnCardPhone.Index].Value = Globals.GetLastPartOfDir(phone_side_card);
                dgvCards.Rows[indx].Cells[clmnCardPathPc.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnCardPathPhone.Index].Value = phone_side_card;
                dgvCards.Rows[indx].Cells[clmnCroup.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnManifestDataPc.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnManifestDataPhone.Index].Value = "";

            }


            if (cmbPcCardGroup.SelectedIndex == 0)
            {
                List<string> all_cards = new List<string>();
                string[] groups = Globals.GetPathOfEachGroup();
                foreach (string group in groups)
                {
                    string[] cards = Globals.GetPathOfEachCard(group);
                    foreach (string card in cards)
                    {
                        all_cards.Add(card);
                    }
                }
                Pc_cards = all_cards.ToArray();
            }
            else
            {
                string group = group = Globals.GetCardsPath() + "\\" + cmbPcCardGroup.SelectedItem.ToString();
                Pc_cards = Globals.GetPathOfEachCard(group);
            }

            if (Phone_cards != null)
            {

                if (Pc_cards!=null) foreach (string card_dir_path in Pc_cards)
                {
                    string card_name = Globals.GetLastPartOfDir(card_dir_path);
                    int idx = Lookup(card_name, dgvCards);
                    if (idx == -1)
                    {
                        int indx = dgvCards.Rows.Add(1);
                        dgvCards.Rows[indx].Cells[clmnRow.Index].Value = ++row;
                        dgvCards.Rows[indx].Cells[clmnSelectPcCard.Index].Value = false;
                        dgvCards.Rows[indx].Cells[clmnCard.Index].Value = card_name;
                        dgvCards.Rows[indx].Cells[clmnAction.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnSelectPhCard.Index].Value = false;
                        dgvCards.Rows[indx].Cells[clmnCardPhone.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnCardPathPc.Index].Value = card_dir_path;
                        dgvCards.Rows[indx].Cells[clmnCardPathPhone.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnCroup.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnManifestDataPc.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnManifestDataPhone.Index].Value = "";

                    }
                    else
                    {
                        dgvCards.Rows[idx].Cells[clmnCard.Index].Value = card_name;
                        dgvCards.Rows[idx].Cells[clmnCardPathPc.Index].Value = card_dir_path;
                    }
                }
            }


            // Extract manifest data
            for (int i = 0; i < dgvCards.Rows.Count; i++)
            {
                
                // Extract manifest data of phone-side cards
                string card_path_phone = (string)dgvCards.Rows[i].Cells[clmnCardPathPhone.Index].Value;
                string manifest_phone = "";
                if (card_path_phone != "")
                {
                    manifest_phone = com.GetManifestData(card_path_phone);
                    dgvCards.Rows[i].Cells[clmnManifestDataPhone.Index].Value = manifest_phone;
                }
                

                // Extract manifest data of pc-side cards
                string card_path_pc = (string)dgvCards.Rows[i].Cells[clmnCardPathPc.Index].Value;
                string manifest_pc = "";
                if (card_path_pc != "")
                {
                    manifest_pc = File.ReadAllText(card_path_pc+"/manifest.man");
                    KeyValPair kvp = new KeyValPair('\n','=');
                    kvp.Fill(manifest_pc);
                    manifest_pc = kvp.GetString(';',':');
                    dgvCards.Rows[i].Cells[clmnManifestDataPc.Index].Value = manifest_pc;
                }
            }


            // Define proper action for transfering cards to/from pc from/to phone.
            for (int i = 0; i < dgvCards.Rows.Count; i++)
            {
                string manifest_phone = (string)dgvCards.Rows[i].Cells[clmnManifestDataPhone.Index].Value;
                string manifest_pc = (string)dgvCards.Rows[i].Cells[clmnManifestDataPc.Index].Value;

                if (manifest_phone == "" && manifest_pc == "") continue;
                else if (manifest_phone == "") dgvCards.Rows[i].Cells[clmnAction.Index].Value = "--->";
                else if (manifest_pc == "") dgvCards.Rows[i].Cells[clmnAction.Index].Value = "<---";
                else
                {
                    KeyValPair kvp_phone = new KeyValPair(';', ':');
                    kvp_phone.Fill(manifest_phone);

                    KeyValPair kvp_pc = new KeyValPair(';', ':');
                    kvp_pc.Fill(manifest_pc);


                    double ph_last_modified = 0; 
                    double pc_last_modified = 0;
                    try
                    {
                       ph_last_modified = Double.Parse(kvp_phone.GetVal("last_modified"));
                       pc_last_modified = Double.Parse(kvp_pc.GetVal("last_modified"));
                    }
                    catch
                    {
                        dgvCards.Rows[i].Cells[clmnAction.Index].Value = "!";
                        continue;
                    }

                    if (pc_last_modified == ph_last_modified) dgvCards.Rows[i].Cells[clmnAction.Index].Value = "<--->";
                    else if (pc_last_modified > ph_last_modified) dgvCards.Rows[i].Cells[clmnAction.Index].Value = "--->";
                    else dgvCards.Rows[i].Cells[clmnAction.Index].Value = "<---";
                }

            }

            if (chbxShowDiffs.Checked) ShowOnlyDiffs();
        }