Exemple #1
0
        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns><see langword="true" /> if the enumerator was successfully advanced to the next element; <see langword="false" /> if the enumerator has passed the end of the collection.</returns>
        public bool MoveNext()
        {
            if (_messageQueue.Count == 0 && !_isInitialized)
            {
                return(false);
            }

            if (_isChanged)
            {
                _moveNextSyncRoot.Wait();
            }

            var pair    = _messageQueue.Dequeue();
            var message = pair.Value;

            var serverTime = message.GetServerTime();

            if (serverTime != null)
            {
                _currentTime = serverTime.Value;
            }

            _currentMessage = (T)message;

            return(true);
        }
Exemple #2
0
        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
                });
            }
        }