int IComparable.CompareTo(object obj) { SearchHistoryEntry b = obj as SearchHistoryEntry; if (b == null) { return(1); } else { if (this.HitCount > b.HitCount) { return(1); } else if (this.HitCount < b.HitCount) { return(-1); } else { return(this.LastSearchTime.CompareTo(b.LastSearchTime)); } } }
public void LoadSearchHistoryFromFile() { m_searchEntries.Clear(); // populate the dictionary with the history of searches: if (System.IO.File.Exists(SearchHistoryFile)) { try { IEnumerable<string> savedHistory = System.IO.File.ReadLines(SearchHistoryFile, Encoding.Default); if (savedHistory != null) { foreach (string line in savedHistory) { string[] entries = line.Split(','); if (entries.Length < 3) log.ErrorFormat("Search History cannot be parsed. DecodedContent={0} ", line); SearchHistoryEntry she = new SearchHistoryEntry(); she.HitCount = int.Parse(entries[0]); she.LastSearchTime = DateTime.ParseExact(entries[1], SearchHistoryEntry.SEARCH_TIME_DATE_FORMAT, CultureInfo.InvariantCulture); she.SearchText = string.Join(",", entries, 2, entries.Length - 2); m_searchEntries.Add(she.SearchText, she); } } } catch (Exception ioex) { log.ErrorFormat("Cannot read Search History: {0} ", ioex.Message); } } if (m_searchEntries.IsNullOrEmpty()) { m_searchEntries.Add("singleton", new SearchHistoryEntry("singleton")); m_searchEntries.Add("replace character in string", new SearchHistoryEntry("replace character in string")); m_searchEntries.Add("create excel file c#", new SearchHistoryEntry("create excel file c#")); m_searchEntries.Add("Open URL in external browser \"Windows Version\"=Windows8", new SearchHistoryEntry("Open URL in external browser \"Windows Version\"=Windows8")); m_searchEntries.Add("metro style file exist*", new SearchHistoryEntry("metro style file exist*")); } }