Esempio n. 1
0
        public static Flight QueryFlight(UpperString departure, UpperString arrival, DateTime flightTime, UpperString airline, string flightNo, Guid oemId)
        {
            if (departure.IsNullOrEmpty())
            {
                throw new ArgumentNullException("departure");
            }
            if (arrival.IsNullOrEmpty())
            {
                throw new ArgumentNullException("arrival");
            }
            if (arrival.IsNullOrEmpty())
            {
                throw new ArgumentNullException("airline");
            }
            if (string.IsNullOrWhiteSpace(flightNo))
            {
                throw new ArgumentNullException("flightNo");
            }

            // 查询历史数据
            var repository          = FlightQuery.Repository.Factory.CreateRepository();
            var flightHistoryRecord = repository.Query(departure.Value, arrival.Value, flightTime, true);

            IEnumerable <Command.Domain.FlightQuery.Flight> commandFlights = null;

            if (flightHistoryRecord == null || string.IsNullOrWhiteSpace(flightHistoryRecord.Content))
            {
                // 如果历史数据中没有,则查询航班
                //var execResult = CommandService.QuerySingleFlight(departure.Value, arrival.Value, flightTime);

                //if(execResult.Success) {
                //    commandFlights = execResult.Result;
                //} else {
                //    throw new CustomException("查询航班失败");
                //}
                commandFlights = FlightDatasCenter.GetFlights(departure.Value, arrival.Value, flightTime.Date, airline.Value, oemId);
            }
            else
            {
                commandFlights = Command.Domain.Utility.Parser.GetFlights(flightHistoryRecord.Content);
                if (!commandFlights.Any(f => f.Airline == airline.Value && f.FlightNo == flightNo))
                {
                    commandFlights = FlightDatasCenter.GetFlights(departure.Value, arrival.Value, flightTime.Date, airline.Value, oemId);
                }
            }
            var flight = commandFlights.FirstOrDefault(f => f.Airline == airline.Value && f.FlightNo == flightNo);

            return(FlightProcessor.GetFlight(flight, flightTime.Date));
        }