public void LoadData(ProgressIndicator p = null)
        {
            System.Diagnostics.Debug.WriteLine("Now start to load rss data for symbol " + Symbol);
            List <string> sym = new List <string>()
            {
                Symbol
            };

            WebClient client = new WebClient();

            client.DownloadStringCompleted += (obj, e) =>
            {
                try
                {
                    RssCollection = YahooAPI.ParseRssXml(e.Result);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    System.Diagnostics.Debug.WriteLine(ex.Source);
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                }
                if (p != null)
                {
                    p.IsVisible = false;
                }
            };
            client.DownloadStringAsync(YahooAPI.GetRssXmlUrl(sym));
        }
        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));
        }
        // this function is used to trigger new features
        private void PickTopSymbolsFromServer(object sender, EventArgs e)
        {
            if (App.Timer != null)
            {
                App.Timer.Stop();
            }
            progressBar.IsVisible = true;
            WebClient client = new WebClient();

            client.DownloadStringCompleted += (obj, args) =>
            {
                progressBar.IsVisible = false;
                KeywordStr.Text       = args.Result;
                SearchButton_onClick(obj, null);
                KeywordStr.Text = "";
            };
            client.DownloadStringAsync(YahooAPI.GetStockAppTopPickUri());
        }
        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));
        }
        private void UpdateGraph()
        {
            List <string> syms     = App.StrToSymbols(Graph_CompareWith.Text);
            Uri           graphUri = YahooAPI.GetQuoteGraphUrl(CurrentSymbol, GraphIndicator_Prompt.Text, syms);
            WebClient     client   = new WebClient();

            client.OpenReadCompleted += async(obj, args) =>
            {
                Stream stream = new MemoryStream();
                await args.Result.CopyToAsync(stream);

                BitmapImage b = new BitmapImage();
                b.SetSource(stream);
                this.GraphHolder.Source       = b;
                ProgressBar.IsVisible         = false;
                GraphHolder_Prompt.Visibility = Visibility.Collapsed;
            };
            client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(GraphDownloadProgressChanged);
            client.OpenReadAsync(graphUri);
            ProgressBar.IsVisible       = true;
            progressBar.IsIndeterminate = false;
            progressBar.Value           = 0;
        }