protected virtual void Receive(QuoteUpdateMessage message)
 {
     if (OperationalState == OperationalStateEnum.Operational && message.OperationResult && QuoteUpdateEvent != null)
     {
         QuoteUpdateEvent(this, message.SessionInfo, message.Quote);
     }
 }
        public void UpdateQuote(DataSessionInfo session, Quote?quote, TimeSpan?period)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.OperationWarning("Stub used while not operational, operation ignored.", TracerItem.PriorityEnum.Low);
                return;
            }

            QuoteUpdateMessage message = new QuoteUpdateMessage(session, quote, true);

            CombinedDataSubscriptionInformation combined;

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

            bool hasActiveSubscriber = false;

            lock (combined)
            {
                foreach (KeyValuePair <TransportInfo, DataSubscriptionInfo> pair in combined.SubscriptionsUnsafe.Values)
                {
                    if (pair.Value.AcceptsUpdate(quote))
                    {
                        hasActiveSubscriber = true;
                        SendResponding(pair.Key, message);
                    }
                }
            }

            SystemMonitor.CheckOperationWarning(hasActiveSubscriber, "Quote update entered for session [" + session.Guid.ToString() + "] symbol [" + session.Symbol.Name + "] and no active subscriber found.");
        }
        void SendQuoteUpdate(TransportInfo[] receivers, DataSessionInfo session)
        {
            DataSourceStub.IImplementation implementation = Implementation;
            if (implementation == null)
            {
                return;
            }

            QuoteUpdateMessage message = new QuoteUpdateMessage(session, implementation.GetQuoteUpdate(session), true);

            SendRespondingToMany(receivers, message);
        }
        void SendQuoteUpdate(TransportInfo[] receivers, DataSessionInfo session)
        {
            DataSourceStub.IImplementation implementation = Implementation;
            if (implementation == null)
            {
                return;
            }

            QuoteUpdateMessage message = new QuoteUpdateMessage(session,  implementation.GetQuoteUpdate(session), true);
            SendRespondingToMany(receivers, message);
        }
        public void UpdateQuote(DataSessionInfo session, Quote? quote, TimeSpan? period)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.OperationWarning("Stub used while not operational, operation ignored.", TracerItem.PriorityEnum.Low);
                return;
            }

            QuoteUpdateMessage message = new QuoteUpdateMessage(session, quote, true);

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

            bool hasActiveSubscriber = false;

            lock(combined)
            {
                foreach (KeyValuePair<TransportInfo, DataSubscriptionInfo> pair in combined.SubscriptionsUnsafe.Values)
                {
                    if (pair.Value.AcceptsUpdate(quote))
                    {
                        hasActiveSubscriber = true;
                        SendResponding(pair.Key, message);
                    }
                }
            }

            if (hasActiveSubscriber == false)
            {
                SystemMonitor.Report("Quote update entered for session [" + session.Guid.ToString() + "] symbol [" + session.Symbol.Name + "] and no active subscriber found.");
            }
        }
        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>
        /// 
        /// </summary>
        public void Quotes(string symbol, int operationId, double ask, double bid, double open, double close,
            double low, double high, double volume, double time)
        {
            TracerHelper.TraceEntry();

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

            try
            {
                QuoteUpdateMessage message = new QuoteUpdateMessage(session.SessionInformation.Info,
                        new Quote((decimal)ask, (decimal)bid, (decimal)open, (decimal)close, (decimal)high, (decimal)low, (decimal)volume,
                            GeneralHelper.GenerateDateTimeSecondsFrom1970((long)time)), true);

                SendToDataSubscribers(session, message, null);
            }
            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);
            }
        }
 protected virtual void Receive(QuoteUpdateMessage message)
 {
     if (OperationalState == OperationalStateEnum.Operational && message.OperationResult && QuoteUpdateEvent != null)
     {
         QuoteUpdateEvent(this, message.SessionInfo, message.Quote);
     }
 }