Ejemplo n.º 1
0
 public IList<SimpleFlight> GetFlights( DateTime day, Airport from, Airport to )
 {
     IList<SimpleFlight> flights;
     string p = String.Format( "{3}{0:yyyy}\\{0:MM}-{0:dd}\\{1}-{2}.txt", day.Date, from.Code, to.Code, _path );
     if( !_cache.TryGetValue( p, out flights ) )
     {
         if( File.Exists( p ) )
         {
             flights = SimpleFlight.Load( p );
         }
         else
         {
             flights = KayakSession.SimpleFlightSearch( from.Code, to.Code, day );
             Directory.CreateDirectory( Path.GetDirectoryName( p ) );
             SimpleFlight.Save( flights, p );
         }
         _cache.Add( p, flights );
     }
     return flights;
 }
Ejemplo n.º 2
0
 public FlightDatabase(string path)
 {
     _path  = path[path.Length - 1] != '\\' ? path + '\\' : path;
     _cache = new Dictionary <string, IList <SimpleFlight> >();
     Airport.Initialize(_path + "airports.txt");
 }
Ejemplo n.º 3
0
        public Meeting(FlightDatabase db)
        {
            _db = db;

            Location = Airport.FindByCode("LHR");
            Guests   = new List <Guest>()
            {
                new Guest()
                {
                    Name = "Helmut", Location = Airport.FindByCode("BER")
                },
                new Guest()
                {
                    Name = "Bernard", Location = Airport.FindByCode("CDG")
                },
                new Guest()
                {
                    Name = "Marius", Location = Airport.FindByCode("MRS")
                },
                new Guest()
                {
                    Name = "Hubert", Location = Airport.FindByCode("LYS")
                },
                new Guest()
                {
                    Name = "Tom", Location = Airport.FindByCode("MAN")
                },
                new Guest()
                {
                    Name = "Maria", Location = Airport.FindByCode("BIO")
                },
                new Guest()
                {
                    Name = "Bob", Location = Airport.FindByCode("JFK")
                },
                new Guest()
                {
                    Name = "Ahmed", Location = Airport.FindByCode("TUN")
                },
                new Guest()
                {
                    Name = "Luigi", Location = Airport.FindByCode("MXP")
                }
            };
            MaxArrivalTime   = new DateTime(2010, 7, 27, 17, 0, 0);
            MinDepartureTime = new DateTime(2010, 8, 3, 15, 0, 0);

            int iGuest = 0;

            foreach (var g in Guests)
            {
                g.Index = iGuest++;
                var aFlights = _db.GetFlights(MaxArrivalTime.Date, g.Location, Location)
                               .Concat(_db.GetFlights(MaxArrivalTime.Date.AddDays(-1), g.Location, Location))
                               .Where(f => f.ArrivalTime <MaxArrivalTime &&
                                                          f.ArrivalTime> MaxArrivalTime.AddHours(-6));
                g.ArrivalFlights = aFlights.ToList();
                var dFlights = _db.GetFlights(MinDepartureTime.Date, Location, g.Location)
                               .Concat(_db.GetFlights(MinDepartureTime.Date.AddDays(1), Location, g.Location))
                               .Where(f => f.DepartureTime > MinDepartureTime &&
                                      f.DepartureTime < MinDepartureTime.AddHours(6));
                g.DepartureFlights = dFlights.ToList();
            }

            var dimensions = new int[18];

            for (int i = 0; i < 18; i++)
            {
                if (i < 9)
                {
                    dimensions[i] = Guests[i].ArrivalFlights.Count;
                }
                else
                {
                    dimensions[i] = Guests[i - 9].DepartureFlights.Count;
                }
            }
            Initialize(dimensions);
        }