Exemplo n.º 1
0
        private void StartSearch(Search searchInp)
        {
            if (searchInp.Adults > 6 || searchInp.Infants > 6 || searchInp.Children > 6 || searchInp.Adults < 0 ||
                searchInp.Children < 0 || searchInp.Infants < 0)
            {
                _searchResults[searchInp] = new Ticket[0];
                _searchProgresses[searchInp] = 80;

                return;
            }
            var browser = new BrowserSimulator("http://liligo.hu");
            browser.DocumentReady += browser_DocumentReady;
            browser.JavaScriptDialog += (s,e) => browser_OnJavaScriptDialog(s,e,searchInp);
            browser.Source = new Uri("http://liligo.hu");

            while (!browser.IsDocumentReady)
            {
                Thread.Sleep(100);
            }
            Thread.Sleep(1000);
            BrowserSimulator.Update();

            browser.ClickElementPersistent("air-from");
            browser.Type(searchInp.From);
            Thread.Sleep(1000);
            _searchProgresses[searchInp] += 2;
            browser.ClickElementPersistent("air-to");
            browser.Type(searchInp.To);
            Thread.Sleep(1000);
            _searchProgresses[searchInp] += 2;
            browser.ClickElementPersistent("air-out-date");
            browser.ExecuteJavascriptWithResult("liligo.DatePicker2.actual.select(Date.parse('" + searchInp.Date.ToShortDateString() + "'),false)");
            Thread.Sleep(1000);
            _searchProgresses[searchInp] += 2;

            if (searchInp.RetDate.HasValue)
            {
                browser.ClickElementPersistent("air-ret-date");
                browser.ExecuteJavascriptWithResult("liligo.DatePicker2.actual.select(Date.parse('" + searchInp.RetDate.Value.ToShortDateString() + "'),false)");
            }
            else
            {
                browser.ClickElementPersistent("air-subcategory-oneway");
            }

            browser.ExecuteJavascriptWithResult("document.getElementById('air-adults').value=" + searchInp.Adults + ";");
            browser.ExecuteJavascriptWithResult("document.getElementById('air-children').value=" + searchInp.Children + ";");
            browser.ExecuteJavascriptWithResult("document.getElementById('air-infants').value=" + searchInp.Infants + ";");

            Thread.Sleep(1000);
            _searchProgresses[searchInp] += 2;
            browser.ClickElementPersistent("air-flexibility");
            browser.ClickElementPersistent("air-submit");
            browser.ClickElementPersistent("air-submit");
            ResultCheckLoop(searchInp, browser);
        }