Ejemplo n.º 1
0
        public string ProvideBrowserDriver()
        {
            _logger.Debug("Checking browser driver.");

            string fullDriverPath        = _customDriverManager.ConstructFullDriverPath();
            bool   canAutoResolveVersion = CanAutoResolveVersion();

            // Check whether browser file exists.
            if (File.Exists(fullDriverPath))
            {
                // If it is exist, check whether we can resolve it version or not.
                if (!canAutoResolveVersion)
                {
                    _logger.Info("Browser driver installed, cannot check version, update will be skipped.");
                    return(fullDriverPath);
                }

                // If we can autoupdate it, check whether we should update it or not.
                if (ChromeVersionChecker.DoesDriverVersionEqualToBrowser(fullDriverPath))
                {
                    _logger.Info("Appropriate browser driver installed, update is not required.");
                    return(fullDriverPath);
                }

                _logger.Info("Browser driver must be updated.");
            }
            else
            {
                _logger.Info("Browser driver is not installed.");
            }

            // Install or update driver.
            return(AutoInstallOrUpdateDriver(canAutoResolveVersion));
        }
Ejemplo n.º 2
0
        public static IHttpWebScrapper Create(
            ISongRequestScriptSettings settings,
            IScriptLogger logger)
        {
            logger.Info($"Creating web scrapper for driver '{settings.SelectedBrowserDriver.Value}'.");
            logger.Info($"WebDriver path: [{settings.BrowserDriverPath.Value}].");
            logger.Info($"WebDriver executable name: [{settings.BrowserDriverExecutableName.GetFullFilename()}].");

            var webDriver = CreateWebDriver(settings, logger);

            return(new HttpWebScrapper(settings, logger, webDriver));
        }
Ejemplo n.º 3
0
        private static void TestAddSongRequest(IReadOnlyList <string> args)
        {
            var httpLink = ParseIntputLink(args);

            var settings = TestSettings.MockSettings(httpLink);

            using var scrapper = HttpWebScrapperFactory.Create(settings, Logger);

            scrapper.OpenUrl();

            var userData = UserData.Create("TestUserId", "TestUserName");
            var number   = SongRequestNumber.All;

            var request = SongRequestModel.CreateNew(userData, TestConfig.SongLink, number);

            request = request.AutoApprove(settings.AutoApproveReason);
            request = request.StartProcessing();
            var result = scrapper.Process(request);

            if (result.IsSuccess)
            {
                Logger.Info("Song request processed successfully!");
            }
            else
            {
                Logger.Error($"Failed to process song request: {result.Description}");
            }
        }
        public void OpenUrl()
        {
            HttpLink httpPageLinkToParse = _settings.HttpPageLinkToParse;

            if (!httpPageLinkToParse.HasValue)
            {
                throw new ArgumentException("Failed to open empty link.", nameof(_settings));
            }

            if (StringComparer.OrdinalIgnoreCase.Equals(_webDriver.Url, httpPageLinkToParse))
            {
                _logger.Warning("Trying to open the same URL. Use Refresh method instead.");
                return;
            }

            _logger.Info($"Opening URL: '{httpPageLinkToParse.Value}'.");
            _webDriver.Navigate().GoToUrl(httpPageLinkToParse.Value);
        }