Пример #1
0
        private static void LoadRoutes(IEmbeddedObjectContainer cache, FirefoxDriver driver)
        {
            foreach (var route in cache.AsQueryable <Route>())
            {
                cache.Delete(route);
            }

            driver.Url = "http://www.ryanair.com/en";
            driver.ExecuteScript("window.moveTo(0, 0); window.resizeTo(1280, 1024);");
            var fromPicker = new FromPicker(driver);
            var toPicker   = new ToPicker(driver);

            foreach (var fromCode in fromPicker.GetAirportCodes().ToArray())
            {
                fromPicker.PickAirportByCode(fromCode);

                foreach (var toCode in toPicker.GetAirportCodes().ToArray())
                {
                    var route = new Route(fromCode, toCode);
                    Console.WriteLine(route);
                    cache.Store(route);
                }
            }
        }
Пример #2
0
        private static void LoadFlights(IEmbeddedObjectContainer cache, Route route, FirefoxDriver driver, DateTime when, int weeks)
        {
            var fromFlights = cache.AsQueryable <Flight>()
                              .Where(flight => flight.Source == route.Source && flight.Target == route.Target);

            foreach (var flight in fromFlights)
            {
                cache.Delete(flight);
            }

            var toFlights = cache.AsQueryable <Flight>()
                            .Where(flight => flight.Source == route.Target && flight.Target == route.Source);

            foreach (var flight in toFlights)
            {
                cache.Delete(flight);
            }

            driver.Url = "http://www.ryanair.com/en";
            driver.ExecuteScript("window.moveTo(0, 0); window.resizeTo(1280, 1024);");
            var fromPicker = new FromPicker(driver);
            var toPicker   = new ToPicker(driver);
            var search     = new Search(driver);

            fromPicker.PickAirportByCode(route.Source);
            toPicker.PickAirportByCode(route.Target);
            fromPicker.PickWhen(when);
            toPicker.PickWhen(when);
            search.Submit();

            var fromPlanner = new FromPlanner(driver);
            var toPlanner   = new ToPlanner(driver);

            foreach (var week in Enumerable.Range(1, weeks))
            {
                if (FromPlanner.Exists(driver))
                {
                    foreach (var info in fromPlanner.GetInfos())
                    {
                        var flight = new Flight(route.Source, route.Target, info);
                        Console.WriteLine(flight);
                        cache.Store(flight);
                    }
                }

                if (ToPlanner.Exists(driver))
                {
                    foreach (var info in toPlanner.GetInfos())
                    {
                        var flight = new Flight(route.Target, route.Source, info);
                        Console.WriteLine(flight);
                        cache.Store(flight);
                    }
                }

                if (week < weeks && FromPlanner.Exists(driver) && ToPlanner.Exists(driver))
                {
                    toPlanner.ShowNextWeek();
                    fromPlanner.ShowNextWeek();
                }
            }
        }