예제 #1
0
        IList <TopicDetails> GetFieldDetails(TopicDetails details)
        {
            // We have a completely new entry
            if (!_fieldToDetails.ContainsKey(details.BrokerUrl))
            {
                var newTopics = new Dictionary <string, IList <TopicDetails> >();
                _fieldToDetails.Add(details.BrokerUrl, newTopics);
                var newFieldList = new List <TopicDetails>();
                newTopics.Add(details.Topic, newFieldList);

                return(newFieldList);
            }

            var topics = _fieldToDetails[details.BrokerUrl];

            // We have a new field with a NMS Topic
            if (!topics.ContainsKey(details.Topic))
            {
                var newFieldList = new List <TopicDetails>();
                topics.Add(details.Topic, newFieldList);

                return(newFieldList);
            }

            return(topics[details.Topic]);
        }
예제 #2
0
        public string BrokerUrl; // Broker URL

        public bool Equals(TopicDetails other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            return(Equals(other.BrokerUrl, BrokerUrl) && other.TopicId == TopicId && Equals(other.Topic, Topic) && Equals(other.Field, Field));
        }
예제 #3
0
        /// <summary>
        /// Create a new Excel topic.
        ///
        /// An Excel topic is a cell.  We may have multiple Excel topics listening to the same
        /// NMS topic.
        ///
        /// Parse the supplied values and create a mapping so that the application can
        /// send data back to the correct topic/cell.
        /// </summary>
        /// <param name="topicId"></param>
        /// <param name="strings">
        /// The first value is a string representing the topic.
        /// The second value is the field of interest.
        /// The third (optional) value is the broker.
        /// </param>
        /// <param name="getNewValues"></param>
        /// <returns></returns>
        public object ConnectData(int topicId, ref Array strings, ref bool getNewValues)
        {
            getNewValues = true; // over-write any saved values in the spreadsheet
            TopicDetails details = null;

            try {
                _log.Info("Creating subscriber for Excel topic " + topicId);
                // If we have a brokerUrl use it, otherwise use the default broker
                details = new TopicDetails {
                    TopicId   = topicId,
                    Topic     = ((string)strings.GetValue(0)),
                    Field     = ((string)strings.GetValue(1)),
                    BrokerUrl = _config.MarketDataBrokerUrl
                };

                if (strings.Length > 2)
                {
                    details.BrokerUrl = (string)strings.GetValue(2);
                }

                // setup our mappings
                lock (_topicToDetails) {
                    _topicToDetails.Add(topicId, details);

                    var detailList = GetFieldDetails(details);
                    if (!detailList.Contains(details))
                    {
                        detailList.Add(details);
                    }

                    var broker     = BrokerFactory.Broker(details.BrokerUrl);
                    var subscriber = broker.TopicSubscriber(details.Topic, _topicHandler.OnMessageHandler);
                    if (!_brokers.ContainsKey(details.BrokerUrl))
                    {
                        _brokers.Add(details.BrokerUrl, broker);
                    }

                    var rt = LookupValueFor(details.BrokerUrl, details.Topic, details.Field);
                    if (rt != null)
                    {
                        return(rt);
                    }
                }
                switch (details.Field)
                {
                case "productVersion":
                    return(_version);

                case "brokerUrl":
                    return(_config.MarketDataBrokerUrl);
                }
                return("N/A");
            } catch (Exception e) {
                _log.Error("Tried to subscribe to topic " + strings, e);

                if (details != null)
                {
                    SetLookupValue(details.BrokerUrl, details.Topic, details.Field, "#Error");
                }
                return("#Error");
            }
        }
예제 #4
0
 string LookupValueFor(TopicDetails details)
 {
     return(LookupValueFor(details.BrokerUrl, details.Topic, details.Field));
 }