public List <SaveStockInfo> GetSavedStockSymbolInfo(ApiClient client) { List <SaveStockInfo> infoes = new List <SaveStockInfo>(); string rootPath = "Stocks\\" + client.ToString(); if (Directory.Exists(rootPath)) { foreach (var item in _exchanges) { SaveStockInfo stockInfo; var filePath = rootPath + "\\" + item + "_Stocks.config"; if (File.Exists(filePath)) { FileInfo filInfo = new FileInfo(filePath); try { var stocks = XSerializer.Instance.GetConfiguration <List <Instrument> >(filePath); stockInfo = new SaveStockInfo() { Exchange = item, LastUpdatedOn = filInfo.LastWriteTime, TotalItems = stocks.Count }; } catch (Exception) { stockInfo = new SaveStockInfo() { Exchange = item }; } } else { stockInfo = new SaveStockInfo() { Exchange = item }; } infoes.Add(stockInfo); } } else { infoes = _exchanges.Select(s => new SaveStockInfo() { Exchange = s, LastUpdatedOn = null, TotalItems = 0 }).ToList(); } return(infoes); }
private void UpdateStocks(SaveStockInfo s) { s.IsUpdatingStocks = true; Task.Factory.StartNew(() => { var count = new ExchangeSymbolUpdate().UpdateSymbol(this.CurrentApiClient, KiteInstance.Kite, s.Exchange); return(count); }).ContinueWith((res) => { switch (res.Status) { case TaskStatus.RanToCompletion: s.LastUpdatedOn = DateTime.Now; s.FailedReason = string.Empty; s.TotalItems = res.Result; break; case TaskStatus.Faulted: s.FailedReason = res.Exception.Message; break; } s.IsUpdatingStocks = false; }, TaskScheduler.FromCurrentSynchronizationContext()); }