public FlightDataService(
            IObservable <long> pollInterval,
            IFlightDataProvider flightDataProvider)
        {
            _flightDataProvider = flightDataProvider;

            _rawFlightData = pollInterval
                             .Select(i => _flightDataProvider.GetCurrentFlightData())
                             .Publish();

            FlightArmed = _rawFlightData
                          .DistinctUntilChanged(i => i.Armed)
                          .Where(i => i.Armed)
                          .Select(flightData => new Models.FlightData(flightData)
            {
                HomePosition = flightData.CurrentPosition
            });

            FlightDisarmed = _rawFlightData
                             .DistinctUntilChanged(i => i.Armed)
                             .Where(i => !i.Armed);

            ArmedFlightData = _rawFlightData
                              .Where(i => i.Armed)
                              .Select(flightData => new Models.FlightData(flightData)
            {
                HomePosition = _homePosition
            });
        }
Exemple #2
0
        public FlightDataService(
            TimeSpan pollInterval,
            IFlightDataProvider flightDataProvider)
        {
            _rawFlightData = Observable.Interval(pollInterval)
                .Select(_ => flightDataProvider.GetCurrentFlightData())
                .Publish();

            FlightArmed = _rawFlightData
                .DistinctUntilChanged(i => i.Armed)
                .Where(i => i.Armed)
                .Select(flightData => new Models.FlightData(flightData) {HomePosition = flightData.CurrentPosition});

            FlightDisarmed = _rawFlightData
                .DistinctUntilChanged(i => i.Armed)
                .Where(i => !i.Armed);

            ArmedFlightData = _rawFlightData
                .Where(i => i.Armed)
                .Select(flightData => new Models.FlightData(flightData) {HomePosition = _homePosition});

            FlightArmed
                .Subscribe(i => _homePosition = i.CurrentPosition);

            FlightDisarmed
                .Subscribe(i => _homePosition = null, () => _homePosition = null);

            _rawFlightDataSubscription = _rawFlightData.Connect();
        }
        public FlightDataService(
            IObservable<long> pollInterval,
            IFlightDataProvider flightDataProvider)
        {
            _flightDataProvider = flightDataProvider;

            _rawFlightData = pollInterval
                .Select(i => _flightDataProvider.GetCurrentFlightData())
                .Publish();

            FlightArmed = _rawFlightData
                .DistinctUntilChanged(i => i.Armed)
                .Where(i => i.Armed)
                .Select(flightData => new Models.FlightData(flightData) {HomePosition = flightData.CurrentPosition});

            FlightDisarmed = _rawFlightData
                .DistinctUntilChanged(i => i.Armed)
                .Where(i => !i.Armed);

            ArmedFlightData = _rawFlightData
                .Where(i => i.Armed)
                .Select(flightData => new Models.FlightData(flightData) {HomePosition = _homePosition});
        }