示例#1
0
        public FlightActor()
        {
            snaps = new FlightDataSnapshotArchive();

            Receive <FlightActorInit>(r =>
            {
                flightID   = r.flightId.Trim();
                icaoLookup = r.icao;
                dataSaver  = r.saver;
            });

            // if a common aircraft, then more details in here
            Receive <ICAOLookupActor.AircraftResponse>(r =>
            {
                snaps.icaoAircraft = r.ICAOAircraft;
            });

            // info about the plane
            Receive <ICAOLookupActor.HexResponse>(r =>
            {
                snaps.hex      = r.Hex;
                snaps.icaoData = r.ICAOData;
                if (snaps.icaoData != null)
                {
                    if (!string.IsNullOrWhiteSpace(snaps.icaoData.t))
                    {
                        icaoLookup.Tell(new ICAOLookupActor.AircraftRequest(r.ICAOData.t));
                    }
                }
            });

            // this is the data from the ADS-B receiver
            Receive <FlightDataRequest>(r =>
            {
                if (string.IsNullOrWhiteSpace(snaps.hex))
                {
                    icaoLookup.Tell(new ICAOLookupActor.HexRequest(r.flightData.hex));
                }

                // ensure that current reading is newer than previous
                // as some packets come in out of order
                bool isOutOrder = false;
                if (currentSnapshot != null && currentSnapshot.now > r.now)
                {
                    Console.WriteLine("not new came in " + snaps.flightCode);
                    isOutOrder = true;
                }

                // create snapshot for basic web view
                buildSnapshot(r.now, r.flightData);

                // make sure in time order
                snaps.archive.Add(currentSnapshot);
                snaps.archive = snaps.archive.OrderBy(z => z.now).ToList();

                // only update status if this is newer than previous
                if (!isOutOrder)
                {
                    dataSaver.Tell(new CosmosSaveActor.SaveRequest(currentSnapshot, "flights"));
                }

                // full object info - incase web user wants to see
                var ex = new FlightDataExtended(r.flightData)
                {
                    altDelta     = currentSnapshot.altDelta,
                    spdDelta     = currentSnapshot.spdDelta,
                    icoaAircraft = snaps.icaoAircraft,
                    icoaData     = snaps.icaoData,
                };
                dataSaver.Tell(new CosmosSaveActor.SaveRequest(ex, "flights"));
            });
        }
示例#2
0
        public FlightActor(string flightID, IMongoDatabase mongo, IActorRef icao)
        {
            this.flightID = flightID;
            mongoActor    = Context.ActorOf(MongoActor.Props(mongo));

            snaps = new FlightSnapshotHistory()
            {
                flight = this.flightID,
                id     = "snap:" + this.flightID,
            };

            Receive <Actors.AircraftDataActor.AircraftResponse>(r =>
            {
                snaps.icaoAircraft = r.ICAOAircraft;
            });

            Receive <Actors.AircraftDataActor.DataResponse>(r =>
            {
                snaps.hex      = r.Hex;
                snaps.icaoData = r.ICAOData;
                if (!string.IsNullOrWhiteSpace(snaps.icaoData.t))
                {
                    icao.Tell(new Actors.AircraftDataActor.AircraftRequest(r.ICAOData.t));
                }
            });

            // this is the
            Receive <FlightRequest>(r =>
            {
                if (string.IsNullOrWhiteSpace(snaps.hex))
                {
                    icao.Tell(new Actors.AircraftDataActor.DataRequest(r.Reading.data.hex));
                }

                // ensure that current reading is newer than previous
                // as some packets come in out of order
                bool isOutOrder = false;
                if (currentSnapshot != null && currentSnapshot.now > r.Reading.now)
                {
                    Console.WriteLine("not new came in " + snaps.flight);
                    isOutOrder = true;
                }

                // create snapshot for basic web view
                buildSnapshot(r.Reading.now, r.Reading.data);

                snaps.snapshots.Add(currentSnapshot);

                // make sure in time order
                snaps.snapshots = snaps.snapshots.OrderBy(z => z.now).ToList();

                // only update status if this is newer than previous
                if (!isOutOrder)
                {
                    currentSnapshot.id = "activeSnap:" + this.flightID;
                    mongoActor.Tell(new MongoActor.MongoSaveRequest <FlightSnapshotData>(currentSnapshot));
                }

                // once I get my
                // full object info - incase web user wants to see
                var ex = new FlightDataExtended(r.Reading.data)
                {
                    altDelta     = currentSnapshot.altDelta,
                    spdDelta     = currentSnapshot.spdDelta,
                    icoaAircraft = snaps.icaoAircraft,
                    icoaData     = snaps.icaoData,
                };
                mongoActor.Tell(new MongoActor.MongoSaveRequest <FlightDataExtended>(ex));
            });
        }