Exemplo n.º 1
0
        public IObservable <IEnumerable <Flight> > GetFlightsFrom(Airport fromAirport)
        {
            var airports = new AirportNamesService().GetAirports();
            var airlines = new AirlineNamesService().GetAirlines();
            var statuses = new StatusService().GetStautses();


            var referenceData = airports
                                .ForkJoin(airlines, (allAirports, allAirlines) =>
            {
                Airports.AddRange(allAirports);
                Airlines.AddRange(allAirlines);
                return(new Unit());
            })
                                .ForkJoin(statuses, (nothing, allStatuses) =>
            {
                Statuses.AddRange(allStatuses);
                return(new Unit());
            });

            string url = string.Format(_serviceUrl, 1, 5, fromAirport.Code);

            var flights = from data in referenceData
                          from flight in GetFlightsFrom(url)
                          select flight;

            return(flights);
        }
Exemplo n.º 2
0
        public void GetFlightsFrom(Action <Result <IEnumerable <Flight> > > callback, Airport fromAirport)
        {
            if (Airports.Count == 0)
            {
                _airportService.GetAirports(r => {
                    if (r.HasError())
                    {
                        callback(new Result <IEnumerable <Flight> >(r.Error));
                    }
                    Airports.AddRange(r.Value);
                    GetFlightsIfAllDone(callback, fromAirport);
                });
            }

            if (Airlines.Count == 0)
            {
                _airlineService.GetAirlines(r =>
                {
                    if (r.HasError())
                    {
                        callback(new Result <IEnumerable <Flight> >(r.Error));
                    }
                    Airlines.AddRange(r.Value);
                    GetFlightsIfAllDone(callback, fromAirport);
                });
            }

            if (Statuses.Count == 0)
            {
                _statusService.GetStautses(r =>
                {
                    if (r.HasError())
                    {
                        callback(new Result <IEnumerable <Flight> >(r.Error));
                    }
                    Statuses.AddRange(r.Value);
                    GetFlightsIfAllDone(callback, fromAirport);
                });
            }

            GetFlightsIfAllDone(callback, fromAirport);
        }