/// <summary> /// Add inner market data storage. /// </summary> /// <param name="storage"></param> public void AddStorage(IMarketDataStorage storage) { if (storage == null) { throw new ArgumentNullException(nameof(storage)); } _isChanged = true; _actions.Add(Tuple.Create(storage, true)); _syncRoot.Pulse(); }
private void OnLoad() { try { var messageTypes = new[] { MessageTypes.Time, ExtendedMessageTypes.Clearing }; var token = _cancellationToken.Token; while (!token.IsCancellationRequested) { _syncRoot.Wait(); _messageQueue.Clear(); _isInitialized = true; _isChanged = false; _moveNextSyncRoot.Pulse(); foreach (var action in _actions.CopyAndClear()) { if (action.Item2) { _basketStorage.InnerStorages.Add(action.Item1); } else { _basketStorage.InnerStorages.Remove(action.Item1); } } var boards = Boards.ToArray(); var loadDate = _currentTime != DateTimeOffset.MinValue ? _currentTime : StartDate; while (loadDate.Date <= StopDate.Date && !_isChanged && !token.IsCancellationRequested) { if (boards.Length == 0 || boards.Any(b => b.IsTradeDate(loadDate, true))) { this.AddInfoLog("Loading {0}", loadDate.Date); using (var enumerator = _basketStorage.Load(loadDate.UtcDateTime.Date)) { // storage for the specified date contains only time messages and clearing events var noData = !enumerator.DataTypes.Except(messageTypes).Any(); if (noData) { EnqueueMessages(loadDate, token, GetSimpleTimeLine(loadDate).GetEnumerator()); } else { EnqueueMessages(loadDate, token, enumerator); } } } loadDate = loadDate.Date.AddDays(1).ApplyTimeZone(loadDate.Offset); } if (!_isChanged) { EnqueueMessage(new LastMessage { LocalTime = StopDate }); } _isInitialized = false; } } catch (Exception excp) { EnqueueMessage(new ErrorMessage { Error = excp }); EnqueueMessage(new LastMessage { IsError = true }); } }