private void bRequestTradingPostData_Click(object sender, RoutedEventArgs e) { // first, clear existing component if (this.priceItems != null && this.priceItems.Count > 0) { this.priceItems.Remove(this.tpdItem); } this.tpdItem = null; // re-init data list this.priceItems = new List <TradingPostDataItem>(); BackgroundWorker _worker = new BackgroundWorker(); _worker.WorkerReportsProgress = true; _worker.DoWork += (object _sender, DoWorkEventArgs _e) => { try { _worker.ReportProgress(0, this._recipe.GetTradingPostData()); } catch (Exception) { // Ignore exceptions at this point - failed to take from queue } }; _worker.ProgressChanged += (object _sender, ProgressChangedEventArgs _e) => { Data.TradingPostData _data = (Data.TradingPostData)_e.UserState; this.pricesView = new ListCollectionView(this.priceItems); this.pricesContainer.ItemsSource = this.pricesView; this.tpdItem = new TradingPostDataItem(_data, _parentWindow); if (!this.tpdItem.WrongState) { this.priceItems.Add(this.tpdItem); this.pricesView.Refresh(); this.pricesContainer.UpdateLayout(); } }; _worker.RunWorkerAsync(); }
public TradingPostDataItem(Data.TradingPostData tradingPostData, MainWindow parentWindow) { InitializeComponent(); this._parentWindow = parentWindow; if (tradingPostData.Exception != null) { this.gTradingPostData.Visibility = System.Windows.Visibility.Collapsed; this.tbNoDataFound.Visibility = System.Windows.Visibility.Visible; } else { if (tradingPostData == null) { this._wrongState = true; return; } if (tradingPostData.HavingMaxBuyCopperPart) { this.tbMaxBuyCopperPart.Text = tradingPostData.MaxBuyCopperPart.ToString(); this.iMaxBuyCopperIcon.Source = new BitmapImage(new Uri(Config.COPPER_ICON_URL)); this.iMaxBuyCopperIcon.Visibility = System.Windows.Visibility.Visible; } else { this.tbMaxBuyCopperPart.Visibility = System.Windows.Visibility.Collapsed; this.iMaxBuyCopperIcon.Visibility = System.Windows.Visibility.Collapsed; } if (tradingPostData.HavingMaxBuySilverPart) { this.tbMaxBuySilverPart.Text = tradingPostData.MaxBuySilverPart.ToString(); this.iMaxBuySilverIcon.Source = new BitmapImage(new Uri(Config.SILVER_ICON_URL)); this.iMaxBuySilverIcon.Visibility = System.Windows.Visibility.Visible; } else { this.tbMaxBuySilverPart.Visibility = System.Windows.Visibility.Collapsed; this.iMaxBuySilverIcon.Visibility = System.Windows.Visibility.Collapsed; } if (tradingPostData.HavingMaxBuyGoldPart) { this.tbMaxBuyGoldPart.Text = tradingPostData.MaxBuyGoldPart.ToString(); this.iMaxBuyGoldIcon.Source = new BitmapImage(new Uri(Config.GOLD_ICON_URL)); this.iMaxBuyGoldIcon.Visibility = System.Windows.Visibility.Visible; } else { this.tbMaxBuyGoldPart.Visibility = System.Windows.Visibility.Collapsed; this.iMaxBuyGoldIcon.Visibility = System.Windows.Visibility.Collapsed; } if (tradingPostData.HavingMinSellCopperPart) { this.tbMinSellCopperPart.Text = tradingPostData.MinSellCopperPart.ToString(); this.iMinSellCopperIcon.Source = new BitmapImage(new Uri(Config.COPPER_ICON_URL)); this.iMinSellCopperIcon.Visibility = System.Windows.Visibility.Visible; } else { this.tbMinSellCopperPart.Visibility = System.Windows.Visibility.Collapsed; this.iMinSellCopperIcon.Visibility = System.Windows.Visibility.Collapsed; } if (tradingPostData.HavingMinSellSilverPart) { this.tbMinSellSilverPart.Text = tradingPostData.MinSellSilverPart.ToString(); this.iMinSellSilverIcon.Source = new BitmapImage(new Uri(Config.SILVER_ICON_URL)); this.iMinSellSilverIcon.Visibility = System.Windows.Visibility.Visible; } else { this.tbMinSellSilverPart.Visibility = System.Windows.Visibility.Collapsed; this.iMinSellSilverIcon.Visibility = System.Windows.Visibility.Collapsed; } if (tradingPostData.HavingMinSellGoldPart) { this.tbMinSellGoldPart.Text = tradingPostData.MinSellGoldPart.ToString(); this.iMinSellGoldIcon.Source = new BitmapImage(new Uri(Config.GOLD_ICON_URL)); this.iMinSellGoldIcon.Visibility = System.Windows.Visibility.Visible; } else { this.tbMinSellGoldPart.Visibility = System.Windows.Visibility.Collapsed; this.iMinSellGoldIcon.Visibility = System.Windows.Visibility.Collapsed; } this.tbOffer.Text = tradingPostData.BuyCount.ToString(THOUSAND_SEPARATOR_FORMAT); this.tbSale.Text = tradingPostData.SellCount.ToString(THOUSAND_SEPARATOR_FORMAT); this.gTradingPostData.Visibility = System.Windows.Visibility.Visible; this.tbNoDataFound.Visibility = System.Windows.Visibility.Collapsed; } }