private static void DirSearch(string sDir) { try { foreach (string f in Directory.GetFiles(sDir)) { string fileName = Path.GetFileName(f); bool exclude = extensionExclude.Any(item => fileName.EndsWith(item)) || fileExclude.Any(item => fileName == item); if (!exclude) { string subdir = GetRelativePath(currentDir, Path.GetDirectoryName(f)); DownloadElement element = new DownloadElement(fileName, subdir); downloadList.Add(element); } } foreach (string d in Directory.GetDirectories(sDir)) { DirSearch(d); } } catch { Console.WriteLine("Failed during dir seach"); } }
/// <summary> /// Translate the file and download to new path /// </summary> public async Task Translate() { // check may be file already translated if (FileTranslatedExists()) { Logger.Info($"translated file already exists: {_filename}"); return; } Logger.Info($"starting translate file: {_filename}"); //FirefoxProfile profile = new FirefoxProfile(@"C:\Users\Dmitry\AppData\Local\Mozilla\Firefox\Profiles\t21lgdab.default-1456481888344"); var options = GetOptions(_config.DirOutput); // options.Profile = profile; _driver = new FirefoxDriver(FirefoxDriverService.CreateDefaultService(), options, TimeSpan.FromSeconds(_maxSecondsWaiting)); _driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(_maxSecondsWaiting); _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(_maxSecondsWaiting); _driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromMinutes(_maxSecondsWaiting); _driver.Manage().Window.Maximize(); string url = _config.GetUrlTranslate(); Logger.Info($"open url: {url}"); try { _driver.Navigate().GoToUrl(url); } catch (WebDriverException e) { Logger.Error($"Open url failed: {e}"); } try { new UploadFile(_driver, null, _filename).Action(); Logger.Info($"set file: {_filename}"); await Task.Delay(GetPause()); new SelectedElement(_driver, "//select[@name='from']", _config.FromLang).Action(); Logger.Info($"set lang from: {_config.FromLang}"); new SelectedElement(_driver, "//select[@name='to']", _config.ToLang).Action(); Logger.Info($"set lang to: {_config.ToLang}"); new ButtonWaiteElement(_driver, "//input[@id='translation-button']").Action(); Logger.Info($"click on button"); await Task.Delay(GetPause()); var downloadUrl = new DownloadElement(_driver, ".download-link", Path.GetFullPath(_config.DirOutput), _config.Timeout); downloadUrl.Action(); Logger.Info($"downloaded url: {downloadUrl.UrlDownload}, file: {downloadUrl.FileDownload}"); } catch (Exception e) { Logger.Info($"unexpected exception in transalte process: {e}"); } }