Пример #1
0
        private static List <Timer> StartPublishing(CachingPublisher cachingPublisher)
        {
            // Prepare some data.
            Dictionary <string, Dictionary <string, object> > lseData = new Dictionary <string, Dictionary <string, object> >
            {
                {
                    "VOD",
                    new Dictionary <string, object>
                    {
                        { "NAME", "Vodafone Group PLC" },
                        { "BID", 140.60 },
                        { "ASK", 140.65 }
                    }
                },
                {
                    "TSCO", new Dictionary <string, object>
                    {
                        { "NAME", "Tesco PLC" },
                        { "BID", 423.15 },
                        { "ASK", 423.25 }
                    }
                },
                {
                    "SBRY",
                    new Dictionary <string, object>
                    {
                        { "NAME", "J Sainsbury PLC" },
                        { "BID", 325.30 },
                        { "ASK", 325.35 }
                    }
                }
            };

            Dictionary <string, Dictionary <string, Dictionary <string, object> > > marketData = new Dictionary <string, Dictionary <string, Dictionary <string, object> > >();

            marketData.Add("LSE", lseData);

            // Publish the data.
            foreach (var feedItem in marketData)
            {
                var feed      = feedItem.Key;
                var topicData = feedItem.Value;

                cachingPublisher.AddNotification(feed);

                foreach (var topicItem in topicData)
                {
                    var topic = topicItem.Key;
                    var data  = topicItem.Value;

                    cachingPublisher.Publish(feed, topic, data);
                }
            }

            var timers = new List <Timer>();

            foreach (var feedItem in marketData)
            {
                var feed      = feedItem.Key;
                var topicData = feedItem.Value;

                foreach (var topicItem in topicData)
                {
                    var topic = topicItem.Key;
                    var data  = topicItem.Value;

                    var timer = new Timer();
                    timers.Add(timer);

                    ScheduleUpdate(cachingPublisher, feed, topic, data, timer);
                }
            }

            return(timers);
        }