Example #1
0
 public static void CheckOnline(this SolutionMeta meta, string geckodriverExecName)
 {
     meta.OnlineTime      = GetOnlineTime(meta, geckodriverExecName);
     meta.IsOnlineCorrect = meta.OnlineTime == meta.OurTime;
     meta.IsOnlineChecked = true;
     meta.SaveToDb();
 }
        public static void SaveToDb(this SolutionMeta meta, bool isBlockSolution = false)
        {
            if (meta.Id == ObjectId.Empty)
            {
                meta.Id = ObjectId.GenerateNewId();
            }

            meta.SavedAt = DateTimeOffset.Now.ToUnixTimeSeconds();
            var collection = isBlockSolution ? Storage.BlockMetaCollection : Storage.MetaCollection;

            collection.ReplaceOne(x => x.Id == meta.Id, meta, new UpdateOptions {
                IsUpsert = true
            });
        }
Example #3
0
        private static int GetOnlineTime(this SolutionMeta meta, string geckodriverExecName)
        {
            var problemPath = ProblemReader.GetProblemPath(meta.ProblemId);

            var solutionPath = Path.GetTempFileName();

            File.WriteAllText(solutionPath, meta.SolutionBlob);

            var driverDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).FullName;
            var service         = FirefoxDriverService.CreateDefaultService(driverDirectory, geckodriverExecName);
            var options         = new FirefoxOptions {
                LogLevel = FirefoxDriverLogLevel.Error
            };

            options.AddArgument("-headless");
            var driver = new FirefoxDriver(service, options);

            driver.Navigate().GoToUrl("https://icfpcontest2019.github.io/solution_checker/");

            var problemField  = driver.FindElement(By.Id("submit_task"));
            var solutionField = driver.FindElement(By.Id("submit_solution"));
            var submitButton  = driver.FindElement(By.Id("execute_solution"));
            var outputElement = driver.FindElement(By.Id("output"));

            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(100));

            problemField.SendKeys(problemPath);
            wait.Until(drv => outputElement.Text == "Done uploading task description");

            solutionField.SendKeys(solutionPath);
            wait.Until(drv => outputElement.Text == "Done uploading solution");

            submitButton.Click();
            wait.Until(drv => outputElement.Text != "Done uploading solution");

            var result = outputElement.Text;

            driver.Quit();

            var match     = Regex.Match(result, "Success! Your solution took (\\d+) time units\\.");
            var timeUnits = int.Parse(match.Groups[1].Captures[0].Value);

            return(timeUnits);
        }