private void HandleApiMessage(CoronaVirusApiTrackerMessage msg)
        {
            runCount++;

            ParseApiTrackerModel parser = new ParseApiTrackerModel();
            var cv = parser.Parse(msg.PayloadJson);

            var recs = cv.confirmed.locations.Where(r => r.country == "US")
                       .Select(r => new
            {
                r.country,
                r.province,
                r.latest
            });

            string dashes = new String('=', 55);

            Clear();
            WriteLine();
            ForegroundColor = ConsoleColor.Green;
            WriteLine("cvApiTracker - Usually 1 day behind...  runCunt={0}", runCount);
            WriteLine("As of {0}", DateTime.Now.ToString("MM.dd.yyyy hh:mm ss"));
            ForegroundColor = ConsoleColor.White;
            WriteLine(dashes);
            WriteLine($"{"City/State".PadRight(45)} latest");
            WriteLine(dashes);
            foreach (var rec in recs)
            {
                WriteLine($"{rec.province.PadRight(50)} {rec.latest}");
            }
            WriteLine(dashes);
            WriteLine($"{"Total".PadRight(50)} {recs.Sum(r => r.latest)}");
            WriteLine(dashes);
        }
Example #2
0
        private async Task <CoronaVirusApiTrackerMessage> CallApi()
        {
            var    api  = new GetDataFromApi();
            string json = await api.GetJsonData();

            var msg = new CoronaVirusApiTrackerMessage();

            msg.PayloadJson = json;

            return(msg);
        }
Example #3
0
        public void Run()
        {
            while (true)
            {
                Console.WriteLine("(apiTrackerSender) press enter to send another message...");
                Console.ReadLine();
                CoronaVirusApiTrackerMessage msg = CallApi().Result;
                _session.Sender.Send(msg);

                Thread.Sleep(TimeSpan.FromSeconds(30));
            }
        }
Example #4
0
        static void apiTrackerSender()
        {
            _ctx    = new RabbitContext().Create("cv.localhost.json");
            _sender = new RmqSender(_ctx);
            _session.Sender.SetRoutingKey("cvApiTracker", "cvApiTracker");

            while (true)
            {
                Console.WriteLine("(apiTrackerSender) press enter to send another message...");
                Console.ReadLine();
                CoronaVirusApiTrackerMessage msg = CallApi().Result;
                // _session.Sender.Send(msg);
                _sender.SendMessage(msg);
            }
        }