public override DataSource CreateDataSource() { DataSource dataSource = new DataSource(this); dataSource.BarDataScale = _newDSScale; dataSource.DSString = SymbolDescription.SerializeList(_newDSSymbols); return(dataSource); }
public override string ModifySymbols(DataSource ds, List <string> symbols) { List <SymbolDescription> symbolsDescription = SymbolDescription.DeserializeList(ds.DSString); // Удаление инструментов // List <SymbolDescription> removeQuery = (from description in symbolsDescription where !symbols.Exists(x => x == description.FullCode) select description).ToList(); foreach (SymbolDescription description in removeQuery) { symbolsDescription.Remove(description); } // Добавление инструментов // var addQuery = from symbol in symbols where !symbolsDescription.Exists(x => x.FullCode == symbol) select symbol; int errorsCount = 0; foreach (string symbol in addQuery) { SymbolDescription description = GetSymbolDescription(symbol); if (description != null) { symbolsDescription.Add(description); } else { errorsCount++; } } if (errorsCount > 0) { MessageBox.Show(string.Format("В формате имени одного или нескольких инструментов была допущена ошибка. Всего ошибок: {0}.", errorsCount), "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(SymbolDescription.SerializeList(symbolsDescription)); }
public override void UpdateProvider(IDataUpdateMessage dataUpdateMsg, List <DataSource> dataSources, bool updateNonDSSymbols, bool deleteNonDSSymbols) { foreach (BarDataScale scale in this._dataStore.GetExistingBarScales()) { if (_cancelTokenSource != null && _cancelTokenSource.IsCancellationRequested) { dataUpdateMsg.DisplayUpdateMessage("Обновление провайдера отменено"); break; } dataUpdateMsg.DisplayUpdateMessage("Обновление таймфрейма " + scale.ToString()); var visibleSymbols = from dataSource in dataSources where dataSource.BarDataScale == scale select SymbolDescription.DeserializeList(dataSource.DSString); List <SymbolDescription> symbols = new List <SymbolDescription>(); foreach (List <SymbolDescription> visibleSymbol in visibleSymbols) { symbols.AddRange(visibleSymbol); } if (updateNonDSSymbols) { var nonDSSymbols = from symbol in _dataStore.GetExistingSymbols(scale.Scale, scale.BarInterval) where !symbols.Exists(x => x.FullCode == symbol) select GetSymbolDescription(symbol); symbols.AddRange(nonDSSymbols); } DataSource dsVirtual = new DataSource(this); dsVirtual.Name = "VirtualDSr"; dsVirtual.BarDataScale = scale; dsVirtual.DSString = SymbolDescription.SerializeList(symbols); UpdateDataSource(dsVirtual, dataUpdateMsg); if (deleteNonDSSymbols) { dataUpdateMsg.DisplayUpdateMessage("--------------"); dataUpdateMsg.DisplayUpdateMessage("Удаление истории инструментов не входящих ни в один набор данных данного таймфрейма:"); var nonDSSymbols = from symbol in _dataStore.GetExistingSymbols(scale.Scale, scale.BarInterval) where !symbols.Exists(x => x.FullCode == symbol) select symbol; foreach (string symbol in nonDSSymbols) { lock (_locker) _dataStore.RemoveFile(symbol, scale.Scale, scale.BarInterval); dataUpdateMsg.DisplayUpdateMessage(string.Format("[DELETED] Инструмент {0} - История удалена", symbol)); } if (nonDSSymbols.Count() == 0) { dataUpdateMsg.DisplayUpdateMessage(string.Format("[NA] Инструменты для удаления не найдены")); } } dataUpdateMsg.DisplayUpdateMessage("--------------"); } }
public override void UpdateDataSource(DataSource ds, IDataUpdateMessage dataUpdateMsg) { _cancelTokenSource = new CancellationTokenSource(); dataUpdateMsg.ReportUpdateProgress(0); if (string.IsNullOrWhiteSpace(ds.DSString)) { List <SymbolDescription> symbolDescriptions = (from symbol in ds.Symbols select GetSymbolDescription(symbol)).ToList(); ds.DSString = SymbolDescription.SerializeList(symbolDescriptions); } List <SymbolDescription> updateRequired = (from description in SymbolDescription.DeserializeList(ds.DSString) where UpdateRequired(description, ds.BarDataScale) select description).ToList(); dataUpdateMsg.DisplayUpdateMessage(string.Format("Количество инструментов требующих обновления: {0}", updateRequired.Count)); if (updateRequired.Count > 0) { dataUpdateMsg.DisplayUpdateMessage("Запуск обновления инструментов:"); Task[] tasks = new Task[updateRequired.Count]; for (int i = 0; i < updateRequired.Count; i++) { dataUpdateMsg.DisplayUpdateMessage(string.Format("[START] Инструмент: {0} - Обновление запущено", updateRequired[i].FullCode)); tasks[i] = Task.Factory.StartNew((object updateRequiredSymbol) => { string symbol = (string)updateRequiredSymbol; DateTime currentDate = DateTime.Now; Bars bars = new Bars(symbol, ds.Scale, ds.BarInterval); _dataStore.LoadBarsObject(bars); try { string suffix = GetSuffix(ds.BarDataScale); int corrections = 0; bars.AppendWithCorrections(GetHistory(ds.BarDataScale, symbol, suffix), out corrections); if (bars.Count > 0 && bars.Date[bars.Count - 1] > currentDate) { bars.Delete(bars.Count - 1); } lock (_locker) _dataStore.SaveBarsObject(bars); dataUpdateMsg.DisplayUpdateMessage(string.Format("[COMPLETE] Инструмент: {0} - Обновление завершено", symbol)); } catch (Exception exception) { logger.Error(exception); dataUpdateMsg.DisplayUpdateMessage(string.Format("[ERROR] Инструмент {0} - {1}", symbol, exception.Message)); } }, updateRequired[i].FullCode); } try { Task.WaitAll(tasks); } catch (AggregateException exception) { exception.Handle((inner) => { if (inner is OperationCanceledException) { return(true); } else { logger.Error(inner); return(false); } }); } } }