Пример #1
0
 private void SubscribeContextEventHandlers(FlightContext context)
 {
     // Subscribe to the events so we can propagate 'em via the factory
     context.OnTakeoff             += (sender, args) => OnTakeoff?.Invoke(sender, args);
     context.OnLaunchCompleted     += (sender, args) => OnLaunchCompleted?.Invoke(sender, args);
     context.OnLanding             += (sender, args) => OnLanding?.Invoke(sender, args);
     context.OnRadarContact        += (sender, args) => OnRadarContact?.Invoke(sender, args);
     context.OnCompletedWithErrors += (sender, args) => OnCompletedWithErrors?.Invoke(sender, args);
 }
Пример #2
0
 /*
  * By wrapping the event invocation in try catch blocks we can prevent that the context abruptly ends because
  * of an exception through the event handler.
  */
 internal void InvokeOnTakeoffEvent()
 {
     try
     {
         OnTakeoff?.Invoke(this, new OnTakeoffEventArgs(Flight));
     }
     catch (Exception ex)
     {
         Trace.Write(ex);
         throw;
     }
 }
Пример #3
0
 public void Outgoing(Airplane airplane)
 {
     Airplanes.Remove(airplane);
     OnTakeoff?.Invoke(this, airplane);
 }
Пример #4
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);
            };
        }