Exemplo n.º 1
0
        /// <summary>
        /// Send message.
        /// </summary>
        /// <param name="message">Message.</param>
        public void SendInMessage(Message message)
        {
            if (!IsOpened)
            {
                throw new InvalidOperationException();
            }

            var clearMsg = message as ClearQueueMessage;

            if (clearMsg != null)
            {
                _messageQueue.Clear(clearMsg);
            }
            else
            {
                //if (!(message is TimeMessage) && message.GetType().Name != "BasketMessage")
                //	Console.WriteLine(">> ({0}) {1}", System.Threading.Thread.CurrentThread.Name, message);

                _msgStat.Add(message);
                _messageQueue.Enqueue(new KeyValuePair <DateTime, Message>(message.LocalTime, message));
            }
        }
        private void OnLoad()
        {
            try
            {
                var messageTypes = new[] { MessageTypes.Time, ExtendedMessageTypes.Clearing };
                var token        = _cancellationToken.Token;

                while (!token.IsCancellationRequested)
                {
                    _syncRoot.WaitSignal();
                    _messageQueue.Clear();

                    _isInitialized = true;
                    _isChanged     = false;

                    _moveNextSyncRoot.PulseSignal();

                    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 ex)
            {
                EnqueueMessage(ex.ToErrorMessage());
                EnqueueMessage(new LastMessage {
                    IsError = true
                });
            }
        }
Exemplo n.º 3
0
 void IMessageProcessor.Clear(ClearMessageQueueMessage message)
 {
     _messageQueue.Clear(message);
 }