示例#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);
        }
示例#2
0
        private void ResultCheckLoop(Search searchInp, BrowserSimulator browser)
        {
            while (
                   !(browser.IsDocumentReady && browser.Source.AbsoluteUri == "http://www.liligo.hu/air/SearchFlights.jsp"))
            {
                Thread.Sleep(100);
            }

            Thread.Sleep(500);

            bool end = false;
            while (!end)
            {
                Awesomium.Core.JSValue[] res = browser.ExecuteJavascriptWithResult("objArrayToString(getResults());");
                if (res.Count() > 0 && !res[0].IsUndefined)
                    _searchResults[searchInp] = (from r in res select new Ticket("liligo", r.ToString())).ToArray();
                else _searchResults[searchInp] = new Ticket[0];

                var isOver = browser.ExecuteJavascriptWithResult(
                        "(function(){return document.getElementsByClassName('stopped-finished').length == 1})()");
                if (isOver.IsBoolean && (bool)isOver)
                {
                    _searchProgresses[searchInp] = 80;
                    --_activeSearches;
                    end = true;
                }
                else if (_searchProgresses[searchInp] < 79) _searchProgresses[searchInp]++;
            }
            Thread ignored;
            _searchThreads.TryRemove(searchInp, out ignored);
            if (_searchQueue.Count > 0) StartSearches();
        }