Esempio n. 1
0
        private void SubscribeContextFactoryEventHandlers(FlightContextFactory factory)
        {
            // Subscribe to the events so we can propagate 'em via the factory
            factory.OnTakeoff += (sender, args) =>
            {
                var location        = GetLocation(args.Flight.DepartureLocation);
                var immatriculation = GetImmatriculation(args.Flight.Aircraft);

                _logger.LogInformation("{UtcNow}: {Aircraft} {Immatriculation} - Took off from {Location} - Flight Info: {FlightInfo}", DateTime.UtcNow, args.Flight.Aircraft, immatriculation, location, args.Flight.GetFullFlightInformation());
                //OnTakeoff?.Invoke(sender, args);
                OnTakeoff?.Invoke(this, new MovementEventArgs(args.Flight, location, immatriculation));
            };

            factory.OnLaunchCompleted += (sender, args) =>
            {
                var immatriculation = GetImmatriculation(args.Flight.Aircraft);
                _logger.LogInformation("{UtcNow}: {Aircraft} {Immatriculation} - launch completed - Flight Info: {FlightInfo}", DateTime.UtcNow, args.Flight.Aircraft, immatriculation, args.Flight.GetFullFlightInformation());
                OnLaunchCompleted?.Invoke(sender, args);
            };

            factory.OnLanding += (sender, args) =>
            {
                var location        = GetLocation(args.Flight.ArrivalLocation);
                var immatriculation = GetImmatriculation(args.Flight.Aircraft);

                _logger.LogInformation("{UtcNow}: {Aircraft} {Immatriculation} - Landed at {Location} - Flight Info: {FlightInfo}", DateTime.UtcNow, args.Flight.Aircraft, immatriculation, location, args.Flight.GetFullFlightInformation());
                //OnLanding?.Invoke(sender, args);
                OnLanding?.Invoke(this, new MovementEventArgs(args.Flight, location, immatriculation));
            };

            factory.OnRadarContact += (sender, args) =>
            {
                if (args.Flight.PositionUpdates.Any() == false)
                {
                    return;
                }

                var lastPositionUpdate = args.Flight.PositionUpdates.OrderByDescending(q => q.TimeStamp).First();
                var location           = GetLocation(lastPositionUpdate.Location);
                var immatriculation    = GetImmatriculation(args.Flight.Aircraft);

                _logger.LogInformation("{UtcNow}: {Aircraft} {Immatriculation} - Radar contact near {Location} at {LastPositionLatitude}, {LastPositionLongitude} @ {LastPositionAltitude}ft {LastPositionHeading} - Flight Info: {FlightInfo}", DateTime.UtcNow, args.Flight.Aircraft, immatriculation, location, lastPositionUpdate.Latitude, lastPositionUpdate.Longitude, lastPositionUpdate.Altitude, lastPositionUpdate.Heading.ToHeadingArrow(), args.Flight.GetFullFlightInformation());

                //OnRadarContact?.Invoke(sender, args);
                OnRadarContact?.Invoke(this, new MovementEventArgs(args.Flight, location, immatriculation));
            };

            factory.OnCompletedWithErrors += (sender, args) =>
            {
                var immatriculation = GetImmatriculation(args.Flight.Aircraft);
                _logger.LogInformation("{UtcNow}: {Aircraft} {Immatriculation} - Flight completed with errors", DateTime.UtcNow, args.Flight.Aircraft, immatriculation);
                OnCompletedWithErrors?.Invoke(sender, args);
            };

            factory.OnContextDispose += (sender, args) =>
            {
                var immatriculation = GetImmatriculation(args.Context.Flight.Aircraft);
                _logger.LogInformation("{UtcNow}: {Aircraft} {Immatriculation} - Context disposed", DateTime.UtcNow, args.Context.Flight.Aircraft, immatriculation);
                OnContextDispose?.Invoke(sender, args);
            };
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var ff = new FlightContextFactory(options =>
            {
                options.NearbyRunwayAccessor = (Point point, double distance) =>
                {
                    return(new[]
                    {
                        new Runway(
                            new Point(4.942108, 51.572418, 49),
                            new Point(4.933319, 51.555660, 49)
                            ),
                        new Runway(
                            new Point(4.950768, 51.565256, 49),
                            new Point(4.911974, 51.569548, 49))
                    });
                };
            });

            using (var reader = new StreamReader(@"C:\Users\Corstian\Projects\Whaally\Skyhop\EHGR-Sept.csv"))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                    using (var writer = new StreamWriter("./experimental-logs-sept-92.csv"))
                        using (var csvWriter = new CsvWriter(writer, CultureInfo.InvariantCulture))
                        {
                            var lines = csv.GetRecords <CsvData>();

                            var departureCounter = 0;
                            var arrivalCounter   = 0;

                            ff.OnTakeoff += (sender, args) =>
                            {
                                departureCounter++;
                            };

                            ff.OnLanding += (sender, args) =>
                            {
                                arrivalCounter++;

                                var data = new
                                {
                                    args.Flight.Aircraft,
                                    args.Flight.DepartureHeading,
                                    DepartureX = args.Flight.DepartureLocation?.X,
                                    DepartureY = args.Flight.DepartureLocation?.Y,
                                    args.Flight.DepartureTime,
                                    args.Flight.DepartureInfoFound,
                                    args.Flight.LaunchMethod,
                                    args.Flight.ArrivalHeading,
                                    ArrivalX = args.Flight.ArrivalLocation?.X,
                                    ArrivalY = args.Flight.ArrivalLocation?.Y,
                                    args.Flight.ArrivalTime,
                                    args.Flight.ArrivalInfoFound,
                                };

                                csvWriter.WriteRecord(data);
                                csvWriter.NextRecord();
                                csvWriter.Flush();
                            };

                            var timestamp = DateTime.Parse("2020-09-05T15:00:01");

                            ff.Process(lines
                                       //.Where(q => q.Timestamp > timestamp)
                                       .Select(q => new PositionUpdate(q.Aircraft, q.Timestamp, q.Longitude, q.Latitude, q.Altitude, q.Speed, q.Heading))
                                       .ToList());

                            Console.WriteLine(departureCounter);
                            Console.WriteLine(arrivalCounter);
                        }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // On start, execute migrations and retrieve the unfinished flights
            using (var db = new Database()) {
                db.Database.Migrate();

                var flights = db.Flights.Where(q => !q.Completed).ToList();

                FlightContextFactory = new FlightContextFactory(flights);
            }

            FlightContextFactory.OnTakeoff += async(sender, e) => {
                Console.WriteLine($"{DateTime.UtcNow}: {e.Flight.Aircraft} - Took off from {e.Flight.DepartureLocation.X}, {e.Flight.DepartureLocation.Y}");
                await StoreModelChange(e.Flight);
            };

            FlightContextFactory.OnLanding += async(sender, e) => {
                Console.WriteLine($"{DateTime.UtcNow}: {e.Flight.Aircraft} - Landed at {e.Flight.ArrivalLocation.X}, {e.Flight.ArrivalLocation.Y}");
                await StoreModelChange(e.Flight);
            };

            FlightContextFactory.OnRadarContact += async(sender, e) => {
                var lastPositionUpdate = e.Flight.PositionUpdates.OrderByDescending(q => q.TimeStamp).First();

                Console.WriteLine($"{DateTime.UtcNow}: {e.Flight.Aircraft} - Radar contact at {lastPositionUpdate.Latitude}, {lastPositionUpdate.Longitude} @ {lastPositionUpdate.Altitude}ft {lastPositionUpdate.Heading.ToHeadingArrow()}");

                await StoreModelChange(e.Flight);
            };

            FlightContextFactory.OnCompletedWithErrors += async(sender, e) => {
                await StoreModelChange(e.Flight);
            };

            AprsClient = new Listener(new Config
            {
                Callsign        = @"7CB0DBG",
                Password        = "******",
                Uri             = "aprs.glidernet.org",
                UseOgnAdditives = true,
                Port            = 10152
            });

            AprsClient.PacketReceived += (sender, e) => {
                if (e.AprsMessage.DataType == Boerman.AprsClient.Enums.DataType.Status)
                {
                    return;
                }
                if (String.IsNullOrEmpty(e.AprsMessage.Callsign))
                {
                    return;
                }

                FlightContextFactory.Process(new PositionUpdate(
                                                 e.AprsMessage.Callsign,
                                                 e.AprsMessage.ReceivedDate,
                                                 e.AprsMessage.Latitude.AbsoluteValue,
                                                 e.AprsMessage.Longitude.AbsoluteValue,
                                                 e.AprsMessage.Altitude.FeetAboveSeaLevel,
                                                 e.AprsMessage.Speed.Knots,
                                                 e.AprsMessage.Direction.ToDegrees()));
            };

            AprsClient.Open();

            Console.WriteLine("Currently checking to see if we can receive some information!");

            Console.Read();
        }