Exemplo n.º 1
0
        private static async Task Run()
        {
            var configLoader = new AprsConfigProvider();
            var config       = await configLoader.LoadAsync();

            var streamListener   = new StreamProvider(config);
            var aircraftProvider = new AircraftProvider(config);

            await aircraftProvider.Initialize();

            streamListener.Stream
            .Subscribe(line =>
            {
                var result = StreamConversionService.ConvertData(line);
                if (result != null)
                {
                    Console.WriteLine(result);
                    Console.WriteLine(aircraftProvider.Load(result.AircraftId));
                }
                else
                {
                    Console.WriteLine($"Not parsable: {line}");
                }
            });

            await streamListener.Stream;
        }
Exemplo n.º 2
0
        public OgnConvertActor(
            IActorRefFactory actorSystem,
            AircraftProvider aircraftProvider,
            GatewayConfiguration gatewayConfiguration
            )
        {
            // When receiving the raw string from the listener, convert it to FlightData and pass it to the next Actor
            Receive <string>(message =>
            {
                var convertedMessage = StreamConversionService.ConvertData(message);
                if (convertedMessage == null)
                {
                    // Ignore non-parseable messages
                    return;
                }

                // The next step also happens on this Actor so tell another "Self" to handle the FlightData
                actorSystem.ActorSelection(Self.Path).Tell(convertedMessage, Self);
            });

            // When receiving FlightData, convert it into FlightDataDto and pass it to the next actor
            Receive <FlightData>(message =>
            {
                var aircraft = aircraftProvider.Load(message.AircraftId);
                if (!aircraft.Visible)
                {
                    // The aircraft should not be visible, therefore drop the message.
                    return;
                }

                var flying = message.Altitude >= gatewayConfiguration.MinimalAltitude &&
                             message.Speed >= gatewayConfiguration.MinimalSpeed;

                var convertedMessage = new FlightDataDto(
                    message.Speed,
                    message.Altitude,
                    message.VerticalSpeed,
                    message.TurnRate,
                    message.Course,
                    message.Position,
                    message.DateTime,
                    new AircraftDto(aircraft),
                    flying
                    );

                // Pass the convertedMessage to the IMessageProcessActor so it can be further processed.
                actorSystem
                .ActorSelection($"user/{ActorControlService.MessageProcessActorName}")
                .Tell(convertedMessage, Self);
            });
        }
Exemplo n.º 3
0
 public ActorPropsFactory(
     GatewayConfiguration gatewayConfiguration,
     ActorSystem actorSystem,
     AircraftProvider aircraftProvider,
     IHubContext <DefaultHub> hubContext,
     LatestDataProvider latestDataProvider
     )
 {
     _gatewayConfiguration = gatewayConfiguration;
     _actorSystem          = actorSystem;
     _aircraftProvider     = aircraftProvider;
     _hubContext           = hubContext;
     _latestDataProvider   = latestDataProvider;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Configures all services & providers that are based on the appsettings.json
        /// </summary>
        /// <param name="services">The systems' IServiceCollection</param>
        private void ConfigureConfigBasedServices(IServiceCollection services)
        {
            var gatewayConfiguration = new GatewayConfiguration();

            Configuration.GetSection("GatewayOptions").Bind(gatewayConfiguration);
            services.AddSingleton(gatewayConfiguration);

            var aprsConfig = new AprsConfig();

            Configuration.GetSection("AprsConfig").Bind(aprsConfig);
            services.AddSingleton(aprsConfig);

            services.AddSingleton(_ =>
            {
                var provider = new AircraftProvider(aprsConfig);
                provider.Initialize().GetAwaiter().GetResult();
                return(provider);
            });
        }