Пример #1
0
        protected virtual SessionsRuntimeInformationMessage Receive(RequestSymbolsRuntimeInformationMessage message)
        {
            DataSourceStub.IImplementation implementation = Implementation;

            List <RuntimeDataSessionInformation> result = new List <RuntimeDataSessionInformation>();

            if (implementation != null && OperationalState == OperationalStateEnum.Operational)
            {
                foreach (Symbol symbol in message.Symbols)
                {
                    lock (this)
                    {
                        if (_symbolsRunningSessions.ContainsKey(symbol) && _symbolsRunningSessions[symbol] != null)
                        {
                            result.Add(_symbolsRunningSessions[symbol].SessionInformation);
                            continue;
                        }
                    }

                    // Failed to find in already existing, query the implementation to create us a new one.
                    RuntimeDataSessionInformation sessionInformation = implementation.GetSymbolSessionRuntimeInformation(symbol);
                    if (sessionInformation != null)
                    {
                        lock (this)
                        {
                            _symbolsRunningSessions[sessionInformation.Info.Symbol] = new CombinedDataSubscriptionInformation(sessionInformation);
                        }
                        result.Add(sessionInformation);
                    }
                }
            }

            return(new SessionsRuntimeInformationMessage(result,
                                                         implementation != null && OperationalState == OperationalStateEnum.Operational));
        }
        /// <summary>
        ///
        /// </summary>
        public List <RuntimeDataSessionInformation> GetSymbolsRuntimeSessionInformations(Symbol[] symbols)
        {
            List <RuntimeDataSessionInformation> result = new List <RuntimeDataSessionInformation>();

            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.Warning("Using stub when not operational.");
                return(result);
            }

            RequestSymbolsRuntimeInformationMessage request = new RequestSymbolsRuntimeInformationMessage(symbols);

            ResponseMessage response = this.SendAndReceiveResponding <ResponseMessage>(
                SourceTransportInfo, request);

            if (response == null || response.OperationResult == false)
            {
                SystemMonitor.OperationError("Symbol session runtime information obtain failed due to timeout.");
                return(result);
            }

            return(((SessionsRuntimeInformationMessage)response).Informations);
        }
        /// <summary>
        /// Get dataDelivery sessions for baseCurrency, source must be dataDelivery source.
        /// </summary>
        public DataSessionInfo?GetSymbolDataSessionInfo(ComponentId sourceId, Symbol symbol)
        {
            lock (_cachedDataSessions)
            {
                if (_cachedDataSessions.ContainsKey(sourceId) == false)
                {
                    _cachedDataSessions.Add(sourceId, new Dictionary <Symbol, DataSessionInfo?>());
                }

                if (_cachedDataSessions[sourceId].ContainsKey(symbol) == false)
                {
                    _cachedDataSessions[sourceId].Add(symbol, null);
                }
                else if (_cachedDataSessions[sourceId][symbol].HasValue)
                {
                    return(_cachedDataSessions[sourceId][symbol]);
                }
            }

            if (IsLocalSource(sourceId))
            {
                ISourceDataDelivery delivery = ObtainDataDelivery(sourceId);
                if (delivery == null)
                {
                    SystemMonitor.OperationError("Failed to establish local delivery.");
                    return(null);
                }

                RuntimeDataSessionInformation session = delivery.GetSymbolRuntimeSessionInformation(symbol);
                if (session == null)
                {
                    SystemMonitor.OperationError("Failed to establish symbol session [" + symbol.Name + "].");
                    return(null);
                }
                return(session.Info);
            }

            List <ArbiterClientId?> sourcePath;

            if (GetSourcePath(sourceId, out sourcePath) == false)
            {
                SystemMonitor.OperationError("Failed to establish source path.");
                return(null);
            }

            RequestSymbolsRuntimeInformationMessage request = new RequestSymbolsRuntimeInformationMessage(new Symbol[] { symbol });
            ResponceMessage responce = this.SendAndReceiveForwarding <ResponceMessage>(sourcePath, request);

            if (responce != null && responce.OperationResult)
            {
                SessionsRuntimeInformationMessage responceMessage = (SessionsRuntimeInformationMessage)responce;
                if (responceMessage.Informations.Count > 0)
                {
                    lock (_cachedDataSessions)
                    {
                        _cachedDataSessions[sourceId][symbol] = responceMessage.Informations[0].Info;
                    }

                    return(responceMessage.Informations[0].Info);
                }
            }

            return(null);
        }
        protected virtual SessionsRuntimeInformationMessage Receive(RequestSymbolsRuntimeInformationMessage message)
        {
            DataSourceStub.IImplementation implementation = Implementation;

            List<RuntimeDataSessionInformation> result = new List<RuntimeDataSessionInformation>();
            if (implementation != null && OperationalState == OperationalStateEnum.Operational)
            {
                foreach (Symbol symbol in message.Symbols)
                {
                    lock (this)
                    {
                        if (_symbolsRunningSessions.ContainsKey(symbol) && _symbolsRunningSessions[symbol] != null)
                        {
                            result.Add(_symbolsRunningSessions[symbol].SessionInformation);
                            continue;
                        }
                    }

                    // Failed to find in already existing, query the implementation to create us a new one.
                    RuntimeDataSessionInformation sessionInformation = implementation.GetSymbolSessionRuntimeInformation(symbol);
                    if (sessionInformation != null)
                    {
                        lock (this)
                        {
                            _symbolsRunningSessions[sessionInformation.Info.Symbol] = new CombinedDataSubscriptionInformation(sessionInformation);
                        }
                        result.Add(sessionInformation);
                    }
                }
            }

            return new SessionsRuntimeInformationMessage(result,
                implementation != null && OperationalState == OperationalStateEnum.Operational);
        }
        protected virtual SessionsRuntimeInformationMessage Receive(RequestSymbolsRuntimeInformationMessage message)
        {
            List<RuntimeDataSessionInformation> result = new List<RuntimeDataSessionInformation>();
            if (OperationalState == OperationalStateEnum.Operational)
            {
                foreach (Symbol symbol in message.Symbols)
                {
                    lock (this)
                    {
                        if (_dataSessions.ContainsKey(symbol) && _dataSessions[symbol] != null)
                        {
                            result.Add(_dataSessions[symbol].SessionInformation);
                            continue;
                        }
                    }
                }
            }

            return new SessionsRuntimeInformationMessage(result, OperationalState == OperationalStateEnum.Operational);
        }
        /// <summary>
        /// Get dataDelivery sessions for baseCurrency, source must be dataDelivery source.
        /// </summary>
        public DataSessionInfo? GetSymbolDataSessionInfo(ComponentId sourceId, Symbol symbol)
        {
            lock (_cachedDataSessions)
            {
                if (_cachedDataSessions.ContainsKey(sourceId) == false)
                {
                    _cachedDataSessions.Add(sourceId, new Dictionary<Symbol, DataSessionInfo?>());
                }

                if (_cachedDataSessions[sourceId].ContainsKey(symbol) == false)
                {
                    _cachedDataSessions[sourceId].Add(symbol, null);
                }
                else if (_cachedDataSessions[sourceId][symbol].HasValue)
                {
                    return _cachedDataSessions[sourceId][symbol];
                }
            }

            if (IsLocalSource(sourceId))
            {
                ISourceDataDelivery delivery = ObtainDataDelivery(sourceId);
                if (delivery == null)
                {
                    SystemMonitor.OperationError("Failed to establish local delivery.");
                    return null;
                }

                RuntimeDataSessionInformation session = delivery.GetSymbolRuntimeSessionInformation(symbol);
                if (session == null)
                {
                    SystemMonitor.OperationError("Failed to establish symbol session [" + symbol.Name + "].");
                    return null;
                }
                return session.Info;
            }

            List<ArbiterClientId?> sourcePath;
            if (GetSourcePath(sourceId, out sourcePath) == false)
            {
                SystemMonitor.OperationError("Failed to establish source path.");
                return null;
            }

            RequestSymbolsRuntimeInformationMessage request = new RequestSymbolsRuntimeInformationMessage(new Symbol[] { symbol });
            ResponceMessage responce = this.SendAndReceiveForwarding<ResponceMessage>(sourcePath, request);

            if (responce != null && responce.OperationResult)
            {
                SessionsRuntimeInformationMessage responceMessage = (SessionsRuntimeInformationMessage)responce;
                if (responceMessage.Informations.Count > 0)
                {
                    lock (_cachedDataSessions)
                    {
                        _cachedDataSessions[sourceId][symbol] = responceMessage.Informations[0].Info;
                    }

                    return responceMessage.Informations[0].Info;
                }
            }

            return null;
        }
        /// <summary>
        /// 
        /// </summary>
        public List<RuntimeDataSessionInformation> GetSymbolsRuntimeSessionInformations(Symbol[] symbols)
        {
            List<RuntimeDataSessionInformation> result = new List<RuntimeDataSessionInformation>();
            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.Warning("Using stub when not operational.");
                return result;
            }

            RequestSymbolsRuntimeInformationMessage request = new RequestSymbolsRuntimeInformationMessage(symbols);

            ResponceMessage responce = this.SendAndReceiveResponding<ResponceMessage>(
                SourceTransportInfo, request);

            if (responce == null || responce.OperationResult == false)
            {
                SystemMonitor.OperationError("Symbol session runtime information obtain failed due to timeout.");
                return result;
            }

            return ((SessionsRuntimeInformationMessage)responce).Informations;
        }