Ejemplo n.º 1
0
        public void DownloadS3()
        {
            try
            {
                setts = ser.Deserialize <Settings>((string)File.ReadAllText(@"Settings.xml"));
                if (nextRefreshS3 > DateTime.Parse(FimS3.Text))
                {
                    nextRefreshS3 = DateTime.Parse(InicioS3.Text);
                }
                else
                {
                    nextRefreshS3 = DateTime.Now.AddMinutes(Int32.Parse(intervaloS3.Text));
                }
                foreach (Settings.Clientes url in setts.ClientesList.Where(x => x.Active == "true"))
                {
                    try { S3.FindElement(By.Id("RandstadTheme_wt101_block_wtHeader_wt99_wt4_wtLogoutLink")).Click(); } catch {
                        //string uploadURL = "https://i.randstad.pt/PortalS3/UploadWizard.aspx?CloudClientId=4";
                        //S3.Navigate().GoToUrl(uploadURL);

                        //foreach (Settings.UploadFile item in setts.UploadFiles)
                        //{
                        //    string tempFile = item.Documento;
                        //    if (tempFile.Contains("{Now}")) tempFile = tempFile.Replace("{Now}", DateTime.Now.AddDays(-1).ToString("dd-MM-yyyy"));
                        //    S3.FindElement(By.CssSelector("#WebPatterns_wt3_block_wtMainContent_wt2_wtfiles input[type=file]")).SendKeys(tempFile);
                        // }
                    }
                    try { Thread.Sleep(1000); S3.Navigate().GoToUrl(DownSetts.Read("S3")); LoginS3(S3); } catch (Exception ex) { WriteLogFile.WriteLog("Log.txt", String.Format("[{0}]:{1}->Function:DownloadS3", DateTime.Now, ex.Message)); }
                    Thread.Sleep(1000);
                    S3.FindElement(By.Id("RandstadTheme_wt101_block_wtMainContent_WebPatterns_wt42_block_wtColumn1_wtStartDate")).Clear(); S3.FindElement(By.Id("RandstadTheme_wt101_block_wtMainContent_WebPatterns_wt42_block_wtColumn1_wtEndDate")).Clear();
                    S3.FindElement(By.Id("RandstadTheme_wt101_block_wtMainContent_WebPatterns_wt42_block_wtColumn1_wtStartDate")).SendKeys(DateTime.Now.Date.ToString("yyyy-MM-dd")); S3.FindElement(By.Id("RandstadTheme_wt101_block_wtMainContent_WebPatterns_wt42_block_wtColumn1_wtEndDate")).SendKeys(DateTime.Now.Date.ToString("yyyy-MM-dd"));
                    S3.FindElement(By.Id("RandstadTheme_wt101_block_wtMainContent_wt68")).Click(); //botao Filtrar

                    Thread.Sleep(1000);
                    System.Collections.ObjectModel.ReadOnlyCollection <IWebElement> options = S3.FindElements(By.CssSelector(".select2-results-dept-0.select2-result.select2-result-selectable"));
                    IWebElement item2 = options.Where(x => x.Text == url.Cliente).FirstOrDefault();
                    item2.Click();
                    Thread.Sleep(1000);
                    System.Collections.ObjectModel.ReadOnlyCollection <IWebElement> linhas = S3.FindElements(By.CssSelector("table.TableRecords.OSFillParent.OSAutoMarginTop tbody tr "));
                    foreach (IWebElement d in linhas)
                    {
                        IWebElement file = d.FindElement(By.CssSelector("td:nth-of-type(2)"));
                        if (File.Exists(pathDownloadS3.Text + "\\" + file.Text))
                        {
                            continue;
                        }
                        d.FindElement(By.CssSelector("td div:not(.OSAutoMarginTop) a")).Click();
                        Thread.Sleep(1000);
                    }
                    Thread.Sleep(1000);
                }
            }catch (Exception ex) { WriteLogFile.WriteLog("LogS3.txt", String.Format("[{0}]:{1}->Function:DownloadS3", DateTime.Now, ex.Message)); }
            ctrlS3 = true;
            S3.Navigate().GoToUrl(DownSetts.Read("S3"));
            delaytimeS3 = DateTime.Now.AddSeconds(30);
            // lastRunS3LB.Text = DateTime.Now.ToString();
        }