Esempio n. 1
0
        public static void SendActiveGames()
        {
            foreach (var link in _links)
            {
                try
                {
                    LiveEvent live;
                    switch (link.Sport)
                    {
                    case SportEnum.Dota2:
                        live = ParseDota2(link);
                        if (live != null)
                        {
                            live.UpdateDate = DateTime.UtcNow;
                            RabbitMQMessageSender.Send(live);
                        }
                        break;

                    case SportEnum.LeagueOfLegends:
                        live = ParseLeagueOfLegends(link);
                        if (live != null)
                        {
                            live.UpdateDate = DateTime.UtcNow;
                            RabbitMQMessageSender.Send(live);
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
        }
Esempio n. 2
0
        void Loop()
        {
            while (true)
            {
                int openIncidents = incRepository.CountOpenIncidents();
                if (openIncidents < 10)
                {
                    // start a new incident at a random location
                    var incidentLat  = (float)(minlat + random.NextDouble() * (maxlat - minlat));
                    var incidentLong = (float)(minlon + random.NextDouble() * (maxlon - minlon));

                    var m = new IncidentForm(incidentLat, incidentLong);
                    sender.Send(m, "incident_queue");
                }
                else
                {
                    logger.Info("10 incidents are yet open");
                }
                // Scenario 2
                //if (DateTime.Now - startTime > TimeSpan.FromMinutes(12)) {
                //	if (DateTime.Now - startTime < TimeSpan.FromMinutes(30)) {
                //		var time = 20 - ((DateTime.Now - startTime - TimeSpan.FromMinutes(12)).Minutes);
                //		logger.Info("Sleep " + Math.Max(5, time) + " seconds");
                //		Thread.Sleep(TimeSpan.FromSeconds(Math.Max(5, time)));
                //	} else {
                //		var time = 5 + ((DateTime.Now - startTime - TimeSpan.FromMinutes(30)).Minutes);
                //		logger.Info("Sleep "+Math.Min(20, time)+" seconds");
                //		Thread.Sleep(TimeSpan.FromSeconds(Math.Min(20, time)));
                //	}
                //} else {
                //logger.Info("Sleep 20 seconds");
                Thread.Sleep(TimeSpan.FromSeconds(20));
                //}
            }
        }
Esempio n. 3
0
        void Register()
        {
            var sender  = new RabbitMQMessageSender();
            var message = new RegisterAmbulanceStation(StationId, Name, PrinterId, Coordinates.Latitude, Coordinates.Longitude);

            sender.Send(message, "internal_comm_queue");
        }
Esempio n. 4
0
        void Start()
        {
            foreach (var i in incidentsToProcess.GetConsumingEnumerable())
            {
                var allocations = incidentRepository.GetOpenAllocation(i.IncidentId).ToList();
                if (allocations.Count() == 0)
                {
                    // could not find the allocation...
                    continue;
                }
                Allocation allocation = allocations.First();
                if (allocations.Count() > 1)
                {
                    logger.Info("Oops, multiple allocations found. Pick one, cancel the others.");
                    foreach (var a in allocations.Skip(1))
                    {
                        allocationRepository.CancelAllocation(a.AllocationId, false);
                    }
                }

                var ambulance = ambulanceRepository.Get(allocation.AmbulanceId);
                try {
                    if (DateTime.Now - allocation.AllocationTimestamp > TimeSpan.FromSeconds(5 * 60 / 10))
                    {
                        logger.Info("Cancel allocation '{0}'", allocation.AllocationId);

                        //ambulanceRepository.UpdateStatus(allocation.AmbulanceId,
                        //								 AmbulanceStatus.Unavailable);
                        allocationRepository.CancelAllocation(allocation.AllocationId, false);
                    }
                    else
                    {
                        logger.Info("Mobilize ambulance {0} for incident {1}",
                                    allocation.AmbulanceId,
                                    allocation.IncidentId);

                        var m = new MobilizationMessage(allocation.AmbulanceId,
                                                        allocation.AllocationId,
                                                        i.Latitude,
                                                        i.Longitude,
                                                        allocation.HospitalId);

                        // Send mobilization order to MDT
                        sender.Send(m, ambulance.Port);

                        // Send fax to home station

                        // Make radio or phone call

                        OnMobilizationSent(allocation);
                    }
                } catch (Exception e) {
                    logger.Error("Error during mobilization: {0}", e.Message);
                    logger.Error(e.StackTrace);
                    logger.Info("Cancel allocation '{0}'", allocation.AllocationId);
                    allocationRepository.CancelAllocation(allocation.AllocationId, true);
                }
            }
        }
Esempio n. 5
0
        void Start()
        {
            foreach (var i in allocationsToProcess.GetConsumingEnumerable())
            {
                var ambulance = ambulanceRepository.Get(i.AmbulanceId);
                var m         = new MobilizationCancelled(i.AllocationId);

                sender.Send(m, ambulance.Port);
            }
        }
Esempio n. 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            QualifyNewClientCommand q = new Lib.Commands.QualifyNewClientCommand();

            q.FirstName = "Keith";
            q.LastName  = "Elder";
            q.State     = "MS";
            q.Zip       = "39401";
            q.City      = "Hattiesburg";
            q.Address1  = "somwhere";
            q.Id        = 1000;
            _Queue.Send <QualifyNewClientCommand>(q);
        }
Esempio n. 7
0
File: MDT.cs Progetto: mavady/ADS
 internal void Send(Message m)
 {
     logger.Info("Sending ({0}): {1}", ambulanceId, m.ToString());
     sender.Send(m, "internal_comm_queue");
 }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var sender = new RabbitMQMessageSender();

            // bounds for the map
            var minlat = 50.645f;
            var minlon = 3.981f;
            var maxlat = 51.053f;
            var maxlon = 4.761f;

            // Ixelles / WB
            maxlat = 50.836502f;
            minlon = 4.358462f;
            minlat = 50.804618f;
            maxlon = 4.413308f;

            // Smaller big brussels
            //minlat = 50.784339f;
            //minlon = 4.258908f;
            //maxlat = 50.896534f;
            //maxlon = 4.475030f;

            var random = new Random();

            var incidentLat  = (float)(minlat + random.NextDouble() * (maxlat - minlat));
            var incidentLong = (float)(minlon + random.NextDouble() * (maxlon - minlon));


            var  httpClient = new HttpClient();
            bool _stop      = false;

            while (!_stop)
            {
                Console.Write("> ");
                var address = Console.ReadLine().Trim();

                if (address.Equals("quit") | address.Equals("exit"))
                {
                    _stop = true;
                    continue;
                }

                try
                {
                    var httpResult = httpClient.GetAsync("http://nominatim.openstreetmap.org/search?q=" + address + "&format=json&polygon=1&addressdetails=1");

                    var    result        = httpResult.Result.Content.ReadAsStringAsync().Result;
                    JArray parsed_result = JsonConvert.DeserializeObject <JArray>(result);

                    Console.WriteLine(parsed_result[0]["lat"]);
                    Console.WriteLine(parsed_result[0]["lon"]);

                    var m = new IncidentForm(incidentLat, incidentLong);
                    sender.Send(m, "incident_queue");
                } catch (Exception e) {
                    Console.WriteLine("An error occured (" + e.Message + ")");
                }
            }
        }