예제 #1
0
        void BeginGetQuotes(HashSet <Security> toFetch)
        {
            if (_services.Count == 0 || toFetch.Count == 0)
            {
                return;
            }

            UiDispatcher.BeginInvoke(new Action(() =>
            {
                OutputPane output = (OutputPane)provider.GetService(typeof(OutputPane));
                output.Clear();
                output.AppendHeading(Walkabout.Properties.Resources.StockQuoteCaption);
            }));

            List <string> batch = new List <string>();

            foreach (Security s in toFetch)
            {
                if (string.IsNullOrEmpty(s.Symbol))
                {
                    continue; // skip it.
                }
                batch.Add(s.Symbol);
            }

            bool foundService             = false;
            IStockQuoteService service    = GetHistoryService();
            HistoryDownloader  downloader = GetDownloader(service);

            if (service != null)
            {
                downloader.BeginFetchHistory(batch);
                foundService = true;
            }

            service = GetQuoteService();
            if (service != null)
            {
                foundService = true;
                if (service.SupportsBatchQuotes)
                {
                    service.BeginFetchQuotes(batch);
                }
                else
                {
                    foreach (var item in batch)
                    {
                        service.BeginFetchQuote(item);
                    }
                }
            }

            if (!foundService)
            {
                AddError(Walkabout.Properties.Resources.ConfigureStockQuoteService);
                UiDispatcher.BeginInvoke(new Action(UpdateUI));
            }
        }
예제 #2
0
        private void ProcessResults()
        {
            try
            {
                processingResults = true;  // lock out Enqueue.

                // Now batch update the securities instead of dribbling them in one by one.
                this.myMoney.Securities.BeginUpdate(true);
                foreach (XElement e in newQuotes.Root.Elements())
                {
                    ProcessResult(e);
                }
                this.myMoney.Securities.EndUpdate();

                busy = false;

                if (status != null)
                {
                    status.ShowProgress("", 0, 0, 0);
                }
                quotesThread = null;
                if (newQuotes != null)
                {
                    string dir = ProcessHelper.StartupPath + "\\OfxLogs";
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    string path = dir + "\\Stocks.xml";
                    newQuotes.Save(dir + "\\Stocks.xml");

                    if (hasError && !stop)
                    {
                        Paragraph p = new Paragraph();
                        p.Inlines.Add(errorLog.ToString());
                        p.Inlines.Add(new LineBreak());
                        p.Inlines.Add(new LineBreak());
                        p.Inlines.Add("See ");
                        var link = new Hyperlink()
                        {
                            NavigateUri = new Uri("file://" + path)
                        };
                        link.Cursor = Cursors.Arrow;
                        link.PreviewMouseLeftButtonDown += OnShowLogFile;
                        link.Inlines.Add("Log File");
                        p.Inlines.Add(link);
                        p.Inlines.Add(" for details");

                        OutputPane output = (OutputPane)provider.GetService(typeof(OutputPane));
                        output.AppendHeading(Walkabout.Properties.Resources.StockQuoteErrorCaption);
                        output.AppendParagraph(p);
                        output.Show();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBoxEx.Show(e.ToString(), Walkabout.Properties.Resources.StockQuotesException, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                processingResults = false;
            }
        }