private void dayPriceDownloader_Enqueue(String symbolName, int miliseconds) { DayPriceDownloader dayPriceDownloader = new DayPriceDownloader(symbolName); dayPriceDownloader.OnLoadDataComplete += new DayPriceDownloader.LoadDataCompleted(dayPriceDownloader_OnLoadDataComplete); DayPriceDownloaderQueue dayPriceDownloaderQueue = DayPriceDownloaderQueue.Instance(miliseconds); dayPriceDownloaderQueue.Enqueue(dayPriceDownloader); }
void dayPriceDownloader_OnLoadDataComplete(DayPriceDownloader dayPriceDownloader, List<DayPrice> dayPriceList) { try { // Check for existing prices List<DateTime> dayPriceDateList = (from dp in _entities.DayPriceSet where dp.SymbolName.Equals(dayPriceDownloader.SymbolName) select dp.DayPriceDate).ToList<DateTime>(); // Insert new reports foreach (DayPrice dayPrice in dayPriceList) { if (!dayPriceDateList.Contains(dayPrice.DayPriceDate)) { System.Threading.Thread.Sleep(10); // Don't go too fast, or GUIDs are not unique. _entities.DayPriceSet.AddObject(dayPrice); } } _entities.SaveChanges(); _entities.CalculateDayChange(dayPriceDownloader.SymbolName); System.Threading.Thread.Sleep(3000); _entities.CalculateDayDifference(dayPriceDownloader.SymbolName); // Check for process completion if(_symbolNameListDayPrice.Contains(dayPriceDownloader.SymbolName)) _symbolNameListDayPrice.Remove(dayPriceDownloader.SymbolName); if (_symbolNameListDayPrice.Count < 1) { _entities.SetDayPriceHigh(_reportDate); if (OnCompleted != null) OnCompleted(); System.Threading.Thread.Sleep(2000); this.Dispose(); } } catch (Exception ex) { LogOps.LogException(ex); } }