void transactionScraper_Finished(object sender, ScrapeFinishedEventArgs e) { var result = new SearchResult(e.Value, e.Arg.ToString(), e.Uri, JsonResultType.Transactions, e.TransactionType); for (int i = 0; i < Items.Count; i++) { for (int j = 0; j < result.Items.Count; j++) { if (Items[i].DataId == result.Items[j].DataId) { result.Items[j].Notify = Items[i].Notify; } } } MainWindowViewModel.Dispatcher.BeginInvoke(new Action(() => { for (int i = 0; i < result.Items.Count; i++) { result.Items[i].IsExpanded = false; var item = Items.FirstOrDefault(x => x.DataId == result.Items[i].DataId); if (item == null) { Items.Add(result.Items[i]); } else { for (int j = 0; j < result.Items[i].Items.Count; j++) { var innerItem = item.Items.FirstOrDefault(x => x.ListingId == result.Items[i].Items[j].ListingId); if (innerItem == null) { var child = result.Items[i].Items[j]; item.Items.Add(child); item.GroupItem(child, item.Items); } } } } })); //Items = new ObservableCollection<HotItem>(result.Items); if (HotItemController.Config.IsTransactionNotificationEnabled) { FindBoughtAndSoldItems(TransactionType, Items.ToList()); } }
/// <summary> /// Basically the same as <seealso cref="Get"/> but more specially and it requires the instance of ScrapeHelper. /// </summary> /// <param name="uri">Uri to request</param> /// <param name="id">Unique id per <seealso cref="ScrapeHelper"/> to keep track of it when the event fires</param> /// <param name="arg">Object argument for the for the event</param> /// <param name="api">Dataprovider Api which is used</param> /// <remarks type="caution">Requires Refactoring</remarks> public void CrawlString(String uri, int id, object arg, ITradingPostApi api) { if (String.IsNullOrEmpty(uri)) { throw new ArgumentException("Uri must be not null or empty"); } if (Finished != null) // it makes no sense to start without attached handlers { try { var sw = Stopwatch.StartNew(); String response = ""; int responseCode = 0; try { PrepareScraper(_client); // setting headers and what not... response = _client.DownloadString(uri); } catch (WebException ex) { HttpStatusCode code = (((HttpWebResponse)ex.Response).StatusCode); responseCode = (int)code; } sw.Stop(); ScrapeFinishedEventArgs e = new ScrapeFinishedEventArgs(id, uri, response, arg) { ResponseCode = responseCode, TransactionType = this.TransactionType }; e.Duration = sw.Elapsed; if (Finished != null) // check again to be sure there was no dettaching in the processing time { Finished(this, e); } } catch { } } }