예제 #1
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);
            });
        }
예제 #2
0
 /// <summary>
 /// Adds new flight-data that we should store.
 /// </summary>
 /// <param name="flightData">New flight-data</param>
 public void Push(FlightDataDto flightData)
 {
     _activeFlightData[flightData.Aircraft.Id] = flightData;
 }