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); }
internal void InvokeOnRadarContactEvent() { try { OnRadarContact?.Invoke(this, new OnRadarContactEventArgs(Flight)); } catch (Exception ex) { Trace.Write(ex); throw; } }
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); }; }