private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { progressBar.Visible = false; KeyValuePair<SnippetSearchResult, Dictionary<string, string[]>> returnedValue = (KeyValuePair<SnippetSearchResult, Dictionary<string, string[]>>)e.Result; SnippetSearchResult result = returnedValue.Key as SnippetSearchResult; Dictionary<string, string[]> mispellings = returnedValue.Value as Dictionary<string, string[]>; if (result == null) result = new SnippetSearchResult(); int numReturnedSnippets = result.snippetNum; // log.Debug("bgw_RunWorkerCompleted - currentSearchText: " + currentSearchText + " - SearchCombobox.Text: " + SearchCombobox.Text); SearchCombobox.Text = currentSearchText; if (numReturnedSnippets == 0) { if (result.errorMsg.CompareTo(Utilities.GetResourceLocalizedMsg<ErrorCodes>(ErrorCodes.OK)) == 0) { ResultsRecap.Text = Properties.Resources.NoResults; } else { SetErrorMsg(result.errorMsg); } } else { if (listSnippetWiew.Controls.Count == 0) { ResultsRecap.Text = Properties.Resources.NoResults; } else { ResultsRecap.Text = string.Format(Properties.Resources.SearchSnippetRecap1, numReturnedSnippets); if (numReturnedSnippets > listSnippetWiew.Controls.Count) { // there are more snippets available ResultsRecap.Text += string.Format(": " + Properties.Resources.SearchSnippetRecap2, listSnippetWiew.Controls.Count); showMoreBox.Visible = true; } else { // we are displaying everything showMoreBox.Visible = false; } } } // cleanup the panel containing mispelling labels SuggestedPanel.Controls.Clear(); // populate mispellings if ((mispellings != null) && (mispellings.Count > 0)) { // split current Search terms by words List<string> mispellingArr = currentSearchText.SplitWords(); for (int i = 0; i < mispellingArr.Count; i++) { // prepare the label to be added to the panel TODO Label suggestedLbl = new Label(); suggestedLbl.TextAlign = ContentAlignment.TopLeft; suggestedLbl.Margin = new Padding(2, 6, 0, 0); suggestedLbl.Name = "SuggestedLbl" + i; suggestedLbl.Padding = new Padding(0, 0, 0, 0); suggestedLbl.Cursor = Cursors.Hand; suggestedLbl.Visible = true; bool foundMispelling = false; // Search if the word must be replaced by a suggestion foreach (string key in mispellings.Keys) { if ((mispellingArr[i].Equals(key, StringComparison.InvariantCultureIgnoreCase)) && (!mispellings[key].IsNullOrEmpty())) { mispellingArr[i] = mispellings[key][0]; foundMispelling = true; break; } } // style and add the label to the panel suggestedLbl.Text = mispellingArr[i]; if (foundMispelling) suggestedLbl.Font = new Font(new FontFamily("Verdana"), 11, FontStyle.Bold); else suggestedLbl.Font = new Font(new FontFamily("Verdana"), 11, FontStyle.Italic); SuggestedPanel.Controls.Add(suggestedLbl); } suggestedSearchText = string.Join(" ", mispellingArr); SuggestedStr.Visible = true; } ResultsRecap.Visible = true; SearchClicked = false; }
private void bgw_DoWork(object sender, DoWorkEventArgs e) { SnippetSearchResult result = new SnippetSearchResult(); e.Result = result; KeyValuePair<string, int> search_count = (KeyValuePair<string, int>)e.Argument; // read snippets and populate the List SnippetsWS snippetRepo = new SnippetsWS(); int searchBlock = 20; // length of each block of snippets read via web call int startIndex = search_count.Value; // current block of snippets int numReturnedSnippets = 0; int numReturnedSnippetsWithNonDefOperator = 0; Dictionary<string, string[]> mispelling = null; SortedDictionary<string, int> tags = null; IList<Snippet> snipList = snippetRepo.GetSnippetsForSearch(search_count.Key, out mispelling, out numReturnedSnippets, out numReturnedSnippetsWithNonDefOperator, out tags, searchBlock, startIndex); //TODO: display results with non default operator result.snippetNum = numReturnedSnippets; if (result.snippetNum <= 0) { try { result.errorMsg = Utilities.GetResourceLocalizedMsg<ErrorCodes>(snippetRepo.LastErrorCode); } catch (Exception) { result.errorMsg = null; } if (string.IsNullOrEmpty(result.errorMsg)) result.errorMsg = Properties.Resources.ErrorCodes_UNKNOWN; } int p = 1; foreach (Snippet s in snipList) { SnipInfo sinfo = new SnipInfo(); if (s != null) { sinfo.snip_image = PictureManager.GetImageOfUser(s.CreatorID, new System.Drawing.Size(50, 50), s.CreatorImageNum); sinfo.snip_name = s.Name; sinfo.snip_description = s.Description; sinfo.snip_creator = s.CreatorName; sinfo.snip_ID = s.ID; bgw.ReportProgress(p++, sinfo); } } e.Result = new KeyValuePair<SnippetSearchResult, Dictionary<string, string[]>>(result, mispelling); }