protected virtual void Receive(DataHistoryUpdateMessage message)
 {
     if (OperationalState == OperationalStateEnum.Operational && message.OperationResult && DataHistoryUpdateEvent != null)
     {
         DataHistoryUpdateEvent(this, message.SessionInfo, message.Update);
     }
 }
        public void UpdateDataHistory(DataSessionInfo session, DataHistoryUpdate update)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.Warning("Stub used while not operational, operation ignored.");
                return;
            }

            DataHistoryUpdateMessage message = new DataHistoryUpdateMessage(session, update, true);

            CombinedDataSubscriptionInformation combined;

            lock (this)
            {
                combined = GetUnsafeSessionSubscriptions(session);
            }

            lock (combined)
            {
                foreach (KeyValuePair <TransportInfo, DataSubscriptionInfo> info in combined.SubscriptionsUnsafe.Values)
                {
                    if (info.Value.AcceptsUpdate(update))
                    {
                        SendResponding(info.Key, message);
                    }
                }
            }
        }
        public void UpdateDataHistory(DataSessionInfo session, DataHistoryUpdate update)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.Warning("Stub used while not operational, operation ignored.");
                return;
            }

            DataHistoryUpdateMessage message = new DataHistoryUpdateMessage(session, update, true);

            CombinedDataSubscriptionInformation combined;
            lock(this)
            {
                 combined = GetUnsafeSessionSubscriptions(session);
            }

            lock(combined)
            {
                foreach (KeyValuePair<TransportInfo, DataSubscriptionInfo> info in combined.SubscriptionsUnsafe.Values)
                {
                    if (info.Value.AcceptsUpdate(update))
                    {
                        SendResponding(info.Key, message);
                    }
                }
            }
        }
        void SendToDataSubscribers(CombinedDataSubscriptionInformation session, QuoteUpdateMessage quoteMessage,  
            DataHistoryUpdateMessage updateMessage)
        {
            TracerHelper.TraceEntry();

            lock (this)
            {
                // TODO: make sure proper subscription based filtering is applied here too.
                foreach (KeyValuePair<TransportInfo, DataSubscriptionInfo> pair in session.SubscriptionsUnsafe.Values)
                {

                    if (quoteMessage != null && pair.Value.AcceptsUpdate(quoteMessage.Quote))
                    {
                        TracerHelper.Trace("Sending [" + quoteMessage.GetType().Name + "] to [" + pair.Key.OriginalSenderId.Value.Id.Name + "].");
                        SendResponding(pair.Key, quoteMessage);
                    }

                    if (updateMessage != null && pair.Value.AcceptsUpdate(updateMessage.Update))
                    {
                        TracerHelper.Trace("Sending [" + updateMessage.GetType().Name + "] to [" + pair.Key.OriginalSenderId.Value.Id.Name + "].");
                        SendResponding(pair.Key, updateMessage);
                    }
                }
            }
        }
        /// <summary>
        /// OperationId is not mandatory - but is should be there when the update was requested by a special recepient.
        /// </summary>
        public void TradingValuesUpdate(string symbol, int operationId, double time, int period, int availableBarsCount,
            Int64[] times, decimal[] opens, decimal[] closes, decimal[] highs, decimal[] lows, decimal[] volumes)
        {
            TracerHelper.TraceEntry();

            CombinedDataSubscriptionInformation session = GetDataSession(symbol);
            if (session == null)
            {
                SystemMonitor.Error("Failed to find symbol session [" + symbol + "], quotes not sent.");
                return;
            }

            try
            {
                // History update.
                TimeSpan periodValue = TimeSpan.FromMinutes(period);

                DataHistoryUpdate update = new DataHistoryUpdate(periodValue,
                    GenerateDataBars(periodValue, times, opens, closes, highs, lows, volumes));

                update.AvailableHistorySize = availableBarsCount;

                DataHistoryUpdateMessage message = new DataHistoryUpdateMessage(session.SessionInformation.Info, update, true);

                SendToDataSubscribers(session, null, message);
            }
            catch (Exception ex)
            {// Make sure we handle any possible unexpected exceptions, as otherwise they bring the
                // entire package (MT4 included) down with a bad error.
                SystemMonitor.Error(ex.Message);
            }

            TracerHelper.TraceExit();
        }
 protected virtual void Receive(DataHistoryUpdateMessage message)
 {
     if (OperationalState == OperationalStateEnum.Operational && message.OperationResult && DataHistoryUpdateEvent != null)
     {
         DataHistoryUpdateEvent(this, message.SessionInfo, message.Update);
     }
 }