private void Init()
 {
     using (var db = new StockQuotesDbContext())
     {
         var query = from b in db.StockQuotes
                     orderby b.Name
                     select b;
         stockQuotes = new ObservableCollection<StockQuote>(query);
     }
 }
Пример #2
0
        private async void DoIt()
        {
            var quotes = new List<StockQuote>();
            var reuters = new StockQuoteServiceClient();
            reuters.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(20);
            reuters.Open();                        

            using (var db = new StockQuotesDbContext())
            {
                var r = Parallel.ForEach(SymbolLibrary.StockSymbols, (x)=> {

                    var quote = reuters.GetStockQuote(x);
                    if (quote.Name != "N/A")
                        quotes.Add(quote);
                });
                //foreach (var symbol in SymbolLibrary.StockSymbols)
                //{
                //    var quote = await reuters.GetStockQuoteAsync(symbol);
                //    if (quote.Name == "N/A")
                //        continue;
                //    quotes.Add(quote);
                //}
                while (!r.IsCompleted) ;

                db.StockQuotes.AddRange(quotes);                
                await db.SaveChangesAsync();

                var query = from b in db.StockQuotes
                            orderby b.Name
                            select b;
                if (query.Any())
                    Tag = true;
            }

            reuters.Close();
        }