Exemple #1
0
        public void Start(int countCube)
        {
            if (!Directory.Exists(ResultPath))
            {
                Directory.CreateDirectory(ResultPath);
            }
            if (!Directory.Exists(DifferencePath))
            {
                Directory.CreateDirectory(DifferencePath);
            }
            AccessesExcel[0].DoAccess($"{ResultPath}Relative.xlsx");
            AccessesExcel[1].DoAccess($"{ResultPath}RelativeDiff.xlsx");
            AccessesExcel[2].DoAccess($"{ResultPath}Absolutly.xlsx");
            AccessesExcel[3].DoAccess($"{ResultPath}AbsolutlyDiff.xlsx");
            double[] lastArray    = new double[countCube * countCube * countCube];
            double[] lastArrayInt = new double[countCube * countCube * countCube];
            int      i            = 0;

            foreach (var fileName in FilesPaths)
            {
                if (i < FilesPaths.Count - 2)
                {
                    Analyzis(fileName, countCube, i, FilesPaths[i++], ref lastArray, ref lastArrayInt,
                             FilesPaths[i + 1]);
                }
                Increment?.Invoke(this, i);
            }
            AccessesExcel[0].FinishAccess();
            AccessesExcel[1].FinishAccess();
            AccessesExcel[2].FinishAccess();
            AccessesExcel[3].FinishAccess();
        }
 public static T Increase <T>(T value)
 => Increment <T, T> .Invoke(value);
 public static R Increase <T, R>(T value)
 => Increment <T, R> .Invoke(value);
Exemple #4
0
 /// <summary>
 /// This is called when Value is incremented by pressing Keys.Right.
 /// </summary>
 public void OnIncrement()
 {
     Increment?.Invoke(this, EventArgs.Empty);
 }
Exemple #5
0
        //NOTE: This function will change the internal state of the object
        public void QueryTickets(string url)
        {
            var driverService = ChromeDriverService.CreateDefaultService();

            driverService.HideCommandPromptWindow = true;
            ChromeOptions option = new ChromeOptions();

            if (headless)
            {
                option.AddArguments("--window-position=-10000,0");
            }
            ChromeDriver driver = new ChromeDriver(driverService, option);

            //driver.Manage().Window.Position = new System.Drawing.Point(-10000, 0);
            this.openDrivers.Add(driver);
            driver.Navigate().GoToUrl(this.GenerateURL());
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(40));

            wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(@"//span[contains(@class, 'SummaryInfo_itineraryCountContainer')]")));
            var          html = driver.PageSource;
            HtmlDocument doc  = new HtmlDocument();

            doc.LoadHtml(html);
            var validNode = doc.DocumentNode.SelectSingleNode(@"//input[contains(@name, 'direct')]");
            var valid     = validNode.Attributes.Contains("checked");

            if (!valid)
            {
                logData?.Invoke($"No direct flights found for {this.source}->{this.destination} on {this.date.ToShortDateString()}");
                driver.Quit();
                this.openDrivers.Remove(driver);
                Increment?.Invoke(1);
                return;
            }
            var ticketNodes = doc.DocumentNode.SelectNodes(@"//div[contains(@class, 'FlightsTicket_container__3yvwg')]");

            logData?.Invoke($"Direct flight(s) found for {this.source}->{this.destination} on {this.date.ToShortDateString()}");
            foreach (HtmlNode node in ticketNodes)
            {
                var          priceNode = node.SelectSingleNode(@".//div[contains(@class,'Price_mainPriceContainer__1dqsw')]").ChildNodes[0];
                string       detailLink = @"https://www.tianxun.com" + node.FirstChild.Attributes["href"].Value;
                ChromeDriver detailDriver = new ChromeDriver(driverService, option);
                detailDriver.Manage().Window.Position = new System.Drawing.Point(-10000, 0);
                this.openDrivers.Add(detailDriver);
                detailDriver.Navigate().GoToUrl(detailLink);
                var detailWait = new WebDriverWait(detailDriver, TimeSpan.FromSeconds(40));
                detailWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(@"//span[contains(@class,'localTimeNotice')]")));
                detailDriver.FindElementByClassName("LegSummary_chevron__1pbHt").Click();
                System.Threading.Thread.Sleep(100);
                HtmlDocument detailDoc = new HtmlDocument();
                detailDoc.LoadHtml(detailDriver.PageSource);
                bool         plusone      = detailDoc.DocumentNode.SelectSingleNode(@"//span[contains(@class,'TimeWithOffsetTooltip')]") != null;
                var          timeNodeList = detailDoc.DocumentNode.SelectSingleNode(@"//div[contains(@class,'Times_segmentTimes__2eToH')]");
                var          generalNode  = detailDoc.DocumentNode.SelectSingleNode(@"//div[contains(@class,'AirlineLogoTitle_container__2k6xV')]");
                var          numNode      = generalNode.ChildNodes[2];
                var          nameNode     = generalNode.ChildNodes[0].ChildNodes[1];
                Regex        rgx          = new Regex("[^a-zA-Z0-9 -]");
                var          fln          = rgx.Replace(numNode.InnerText, "").Trim();
                DirectTicket ticket       = new DirectTicket
                {
                    carrier     = nameNode.InnerText.Replace("&nbsp;", ""),
                    flightNum   = fln,
                    source      = this.source,
                    destination = this.destination,
                    price       = int.Parse(priceNode.InnerText.Replace("¥", "").Replace(",", "")),
                    targetLink  = detailLink
                };
                logData?.Invoke($"Ticket {ticket.carrier} from {ticket.source} to {ticket.destination} carrier {ticket.carrier} found.");
                int      hourDepart    = int.Parse(timeNodeList.ChildNodes[0].ChildNodes[0].InnerText.Split(':')[0]);
                int      minuteDepart  = int.Parse(timeNodeList.ChildNodes[0].ChildNodes[0].InnerText.Split(':')[1]);
                int      hourArrival   = int.Parse(timeNodeList.ChildNodes[2].ChildNodes[0].InnerText.Split(':')[0]);
                int      minuteArrival = int.Parse(timeNodeList.ChildNodes[2].ChildNodes[0].InnerText.Split(':')[1]);
                DateTime DepartDT      = this.date.Date + new TimeSpan(hourDepart, minuteDepart, 0);
                DateTime ArriveDT      = this.date.Date + new TimeSpan(hourArrival, minuteArrival, 0);
                if (plusone)
                {
                    ArriveDT = ArriveDT.AddDays(1);
                }
                ticket.departure = DepartDT; ticket.arrival = ArriveDT;
                Console.WriteLine(detailLink);
                this.ticketsToday.Add(ticket);
                detailDriver.Quit();
                this.openDrivers.Remove(detailDriver);
                this.Increment?.Invoke(ticketNodes.Count);
            }
            driver.Quit();
            this.openDrivers.Remove(driver);
        }