Example #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.WaitSignal();
            }

            Message message;

            if (!_messageQueue.TryDequeue(out message))
            {
                return(_isChanged);
            }

            var serverTime = message.GetServerTime();

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

            _currentMessage = (T)message;

            return(true);
        }
            public void Open()
            {
                _messageQueue.Open();

                ThreadingHelper
                .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() =>
                {
                    while (!_messageQueue.IsClosed)
                    {
                        try
                        {
                            var sended = _historyMessageAdapter.SendOutMessage();
                            var block  = !sended;

                            Message message;

                            while (_messageQueue.TryDequeue(out message, true, block))
                            {
                                NewOutMessage?.Invoke(message);
                                block = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            _errorHandler(ex);
                        }
                    }
                }))
                .Name("History emulation channel thread.")
                .Launch();
            }
Example #3
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 (MarketTimeChangedInterval != TimeSpan.Zero && !_isTimeLineAdded)
            {
                AddStorage(new InMemoryMarketDataStorage <TimeMessage>(null, null, GetTimeLine));

                _isTimeLineAdded = true;
                _moveNextSyncRoot.WaitSignal();
            }

            if (_messageQueue.Count == 0 && !_isInitialized)
            {
                return(false);
            }

            var isChanged = _isChanged;

            if (isChanged)
            {
                _moveNextSyncRoot.WaitSignal();
            }

            Message message;

            if (!isChanged)
            {
                if (!_messageQueue.TryDequeue(out message))
                {
                    return(false);
                }
            }
            else
            {
                message = _messageQueue.Dequeue().Value;
            }

            var serverTime = message.GetServerTime();

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

            _currentMessage = (T)message;

            return(true);
        }