public void BeginSearch(SearchItem item) { var worker = new BackgroundWorker(); worker.RunWorkerCompleted += (s,e) => { try { if (e.Result != null) { OnSearchComplete(e.Result as IEnumerable<SearchResult>); } } catch(WebException ex) { Debug.WriteLine(ex.Message); } }; worker.DoWork += (s, e) => { var client = new WebClient(); var uri = new Uri(e.Argument.ToString()); var xml = client.DownloadString(uri); if (!String.IsNullOrEmpty(xml)) { e.Result = ParseResults(xml, item); } }; string url = String.Format(urlFormat, HttpUtility.UrlEncode(item.Phrase)); worker.RunWorkerAsync(url); }
private void RaiseCompleteEvent(SearchItem item) { var asm = Assembly.GetExecutingAssembly(); var stream = asm.GetManifestResourceStream(_resourceName); if (stream != null && SearchComplete != null) { var doc = XDocument.Load(XmlReader.Create(stream)); var converter = new TwitterSearchAtomConverter(doc, item); SearchComplete(this, new SearchCompleteEventArgs() { Results = converter.Convert().ToList()} ); } }
public void DeleteTerm(SearchItem item) { _searchItems.Remove(item); }
public void AddCurrentWordAsSearchTerm() { _searchItems.AddSearchItem(SearchItem.CreateFrom(CurrentWord)); CurrentWord = String.Empty; }
public TwitterSearchAtomConverter(XDocument atomDoc, SearchItem item) { _document = atomDoc; _item = item; }
private IEnumerable<SearchResult> ParseResults(string xml, SearchItem item) { var doc = XDocument.Parse(xml); var converter = new TwitterSearchAtomConverter(doc, item); return converter.Convert(); }
public void BeginSearch(SearchItem item) { LastTermSeen = item.Phrase; RaiseCompleteEvent(item); }