private void SearchButton_onClick(object sender, RoutedEventArgs e) { if (App.Timer != null) { App.Timer.Stop(); } List <string> syms = App.StrToSymbols(KeywordStr.Text); if (syms.Count == 0) { string message = "Please provide symbol(s) to search, separated by a comma.\nE.g., QQQ,SPY"; string caption = "Empty symbol to search"; MessageBoxButton buttons = MessageBoxButton.OK; MessageBoxResult result = MessageBox.Show(message, caption, buttons); return; } progressBar.IsVisible = true; WebClient client = new WebClient(); client.DownloadStringCompleted += (obj, args) => { try { YahooAPI.UpdateQuotes(args.Result); PortfolioViewModel currentView = (PortfolioViewModel)PortfolioPivot.SelectedItem; Portfolio currentPortfolio = App.GetPortfolio(currentView.Title); foreach (string s in syms) { Quote quote = App.GetQuote(s); if (quote == null) { System.Diagnostics.Debug.WriteLine("Symbol " + s + " was not found in db."); continue; } if (currentPortfolio.AddQuote(quote)) { currentView.AddStockToView(quote); } } } catch (Exception ex) { // can be caused by network issue System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(ex.Source); System.Diagnostics.Debug.WriteLine(ex.StackTrace); } if (App.Timer != null) { App.Timer.Start(); } progressBar.IsVisible = false; }; client.DownloadStringAsync(YahooAPI.GetQuotesXmlUrl(syms)); }
private void RefreshView(int panoramaIndex) { if (panoramaIndex < 2) { WebClient client = new WebClient(); client.DownloadStringCompleted += (obj, args) => { YahooAPI.UpdateQuotes(args.Result.ToString()); if (CurrentQuote.Change > 0) { Change.Foreground = new SolidColorBrush(Colors.Green); } else if (CurrentQuote.Change < 0) { Change.Foreground = new SolidColorBrush(Colors.Red); } }; client.DownloadStringAsync(YahooAPI.GetQuotesXmlUrl(new List <string>() { CurrentSymbol })); } if (panoramaIndex == 2) { // graph page UpdateGraph(); } else if (panoramaIndex == 3) { // rss news page ProgressBar.IsIndeterminate = true; ProgressBar.IsVisible = true; RssView.LoadData(ProgressBar); } else if (panoramaIndex == 4) { // tweets page ProgressBar.IsIndeterminate = true; ProgressBar.IsVisible = true; TweetView.Symbol = CurrentSymbol; TweetView.LoadData(ProgressBar); } }
private void CurrentList_RefreshView() { if (App.Timer != null) { App.Timer.Stop(); } PortfolioViewModel currentView = (PortfolioViewModel)PortfolioPivot.SelectedItem; Portfolio currentPortfolio = App.GetPortfolio(currentView.Title); List <string> currentStockList = currentPortfolio.StockList; // do not refresh if the portfolio has nothing if (currentStockList.Count == 0) { return; } WebClient client = new WebClient(); client.DownloadStringCompleted += (obj, args) => { try { YahooAPI.UpdateQuotes(args.Result.ToString()); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(ex.Source); System.Diagnostics.Debug.WriteLine(ex.StackTrace); } if (App.Timer != null) { App.Timer.Start(); } }; client.DownloadStringAsync(YahooAPI.GetQuotesXmlUrl(currentStockList)); }