示例#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;
        }
示例#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);
            });
        }