/////////////////////////////////////////////////////////////////////////////// private void AddFindHistoryItem() { if (m_client != null) { if (m_client.FoundVerses != null) { if (m_client.FoundVerses.Count > 0) { FindHistoryItem item = new FindHistoryItem(); item.FindType = m_find_type; item.NumberSearchType = m_numbers_result_type; item.Text = (m_find_type == FindType.Numbers) ? null : FindByTextTextBox.Text; item.LanguageType = m_language_type; if (TranslatorComboBox.SelectedItem != null) { item.Translation = TranslatorComboBox.SelectedItem.ToString(); } item.Verses = new List<Verse>(m_client.FoundVerses); if (m_client.FoundPhrases == null) { item.Phrases = null; } else { item.Phrases = new List<Phrase>(m_client.FoundPhrases); } item.Header = m_find_result_header; m_client.AddHistoryItem(item); UpdateBrowseHistoryButtons(); } } } }
public void LoadHistoryItems() { string filename = Globals.HISTORY_FOLDER + "/" + m_username + "/" + "History" + ".txt"; if (File.Exists(filename)) { using (StreamReader reader = File.OpenText(filename)) { try { while (!reader.EndOfStream) { string line = reader.ReadLine(); string[] parts = null; if (line == "") { continue; } else if (line == "BrowseHistoryItem") { line = reader.ReadLine(); SelectionScope scope = (SelectionScope)Enum.Parse(typeof(SelectionScope), line); List<int> indexes = new List<int>(); line = reader.ReadLine(); parts = line.Split(','); foreach (string part in parts) { try { int index = int.Parse(part); indexes.Add(index); } catch { continue; } } SelectionHistoryItem item = new SelectionHistoryItem(m_book, scope, indexes); AddHistoryItem(item); } else if (line == "FindHistoryItem") { FindHistoryItem item = new FindHistoryItem(); line = reader.ReadLine(); parts = line.Split('\t'); if ((parts.Length == 2) && (parts[0].Trim() == "FindType")) { item.FindType = (FindType)Enum.Parse(typeof(FindType), parts[1].Trim()); } line = reader.ReadLine(); parts = line.Split('\t'); if ((parts.Length == 2) && (parts[0].Trim() == "NumberSearchType")) { item.NumberSearchType = (NumberSearchType)Enum.Parse(typeof(NumberSearchType), parts[1].Trim()); } line = reader.ReadLine(); parts = line.Split('\t'); if ((parts.Length == 2) && (parts[0].Trim() == "Text")) { item.Text = parts[1].Trim(); } line = reader.ReadLine(); parts = line.Split('\t'); if ((parts.Length == 2) && (parts[0].Trim() == "Header")) { item.Header = parts[1].Trim(); } line = reader.ReadLine(); parts = line.Split('\t'); if ((parts.Length == 2) && (parts[0].Trim() == "Language")) { item.LanguageType = (LanguageType)Enum.Parse(typeof(LanguageType), parts[1].Trim()); } line = reader.ReadLine(); parts = line.Split('\t'); if ((parts.Length == 2) && (parts[0].Trim() == "Translation")) { item.Translation = parts[1].Trim(); } // CSV: Phrase.Verse.Number, Phrase.Text, Phrase.Position while (true) { line = reader.ReadLine(); if (line == END_OF_HISTORY_ITME_MARKER) { break; } parts = line.Split(','); if (parts.Length == 1) // verse.Number { //TODO: Load NumberQuery with each search result int verse_index = int.Parse(parts[0].Trim()) - 1; if ((verse_index >= 0) && (verse_index < m_book.Verses.Count)) { Verse verse = m_book.Verses[verse_index]; if (!item.Verses.Contains(verse)) { item.Verses.Add(verse); } } } else if (parts.Length == 3) // phrase.Verse.Number,phrase.Text,phrase.Position { int verse_index = int.Parse(parts[0].Trim()) - 1; if ((verse_index >= 0) && (verse_index < m_book.Verses.Count)) { Verse verse = m_book.Verses[verse_index]; if (!item.Verses.Contains(verse)) { item.Verses.Add(verse); } string phrase_text = parts[1].Trim(); if (phrase_text.Length > 0) { int phrase_position = int.Parse(parts[2].Trim()); Phrase phrase = new Phrase(verse, phrase_position, phrase_text); item.Phrases.Add(phrase); } } } } // while AddHistoryItem(item); } } // while } catch { throw new Exception("Invalid " + filename + " format."); } } } }