示例#1
0
        /// <summary>
        /// Apply a <see cref="CompareTarget"/> to a checker for some entities.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="checker"></param>
        /// <param name="expected"></param>
        /// <param name="candidate"></param>
        /// <param name="objectName"></param>
        protected void Check(CompareTarget target, IChecker checker, object expected, object candidate, string objectName)
        {
            switch (target)
            {
            case CompareTarget.Ignore:
                break;

            case CompareTarget.Id:
                CheckId(expected, candidate, objectName + ".Id");
                break;

            case CompareTarget.Entity:
                checker.Check(expected, candidate, objectName);
                break;

            case CompareTarget.Dictionary:
                Check(checker, expected as IDictionary, candidate as IDictionary, objectName);
                break;

            case CompareTarget.Count:
            case CompareTarget.Collection:
                Check(checker, expected as IEnumerable, candidate as IEnumerable, objectName);
                break;

            case CompareTarget.Value:
                Check(expected, candidate, objectName);
                break;

            default:
                throw new NotSupportedException("Cannot perform comparison: " + target);
            }
        }
示例#2
0
文件: Lint.cs 项目: jmrnilsson/Cslint
        public void Check(DirectoryInfo workingDirectory)
        {
            lf.Information   += OnInformation;
            lf.Error         += OnError;
            lf.Verbose       += OnVerbose;
            utf8.Information += OnInformation;
            utf8.Error       += OnError;
            utf8.Verbose     += OnVerbose;

            var csFiles = new List <string>();

            GetCsFiles(workingDirectory.FullName, ref csFiles);

            foreach (string file in csFiles)
            {
                if (Regex.Match(file, @"(AssemblyInfo.cs$|\\bin\\|\\obj\\)").Success)
                {
                    OnInformation($"||\tSkipping: {file}");
                    continue;
                }

                lf.Check(file);
                utf8.Check(file);
            }
        }
示例#3
0
        protected void Check(CompareTarget target, IChecker checker, object expected, object candidate, string objectName)
        {
            switch (target)
            {
            case CompareTarget.Id:
                CheckId(expected, candidate, objectName + ".Id");
                break;

            case CompareTarget.Entity:
                checker.Check(expected, candidate, objectName);
                break;

            case CompareTarget.Count:
            case CompareTarget.Collection:
                this.Check(checker, expected as IEnumerable, candidate as IEnumerable, objectName);
                break;

            default:
                if (CheckNullNotNull(expected, candidate, objectName))
                {
                    return;
                }

                if (!expected.Equals(candidate))
                {
                    throw new PropertyCheckException(objectName, expected, candidate);
                }
                break;
            }
        }
示例#4
0
        private static async Task Do(IChecker checker, CheckerArgs args)
        {
            switch (args.Command)
            {
            case Command.Debug:
                await Debug(checker, args.Host).ConfigureAwait(false);

                break;

            case Command.Info:
                await Console.Out.WriteLineAsync(await checker.Info().ConfigureAwait(false)).ConfigureAwait(false);

                break;

            case Command.Check:
                await checker.Check(args.Host).ConfigureAwait(false);

                break;

            case Command.Put:
                await Console.Out.WriteLineAsync(await checker.Put(args.Host, args.Id, args.Flag, args.Vuln).ConfigureAwait(false)).ConfigureAwait(false);

                break;

            case Command.Get:
                await checker.Get(args.Host, args.Id, args.Flag, args.Vuln).ConfigureAwait(false);

                break;

            default:
                throw new CheckerException(ExitCode.CHECKER_ERROR, "Unknown command");
            }
        }
示例#5
0
        private static async Task Debug(IChecker checker, string host)
        {
            for (int i = 0; i < int.MaxValue; i++)
            {
                try
                {
                    var vulns = (await checker.Info().ConfigureAwait(false)).Split(':').Skip(1).Select(v => int.Parse(v.Trim())).ToArray();
                    await checker.Check(host).ConfigureAwait(false);

                    var vuln = RndDbg.RandomVuln(vulns);
                    var flag = RndDbg.RandomFlag();

                    var flagid = await checker.Put(host, "", flag, vuln).ConfigureAwait(false);

                    await checker.Get(host, flagid, flag, vuln).ConfigureAwait(false);

                    Console.ForegroundColor = ConsoleColor.Green;
                    await Console.Error.WriteLineAsync(ExitCode.OK.ToString()).ConfigureAwait(false);

                    Console.ResetColor();
                }
                catch (CheckerException e)
                {
                    await Console.Error.WriteLineAsync(e.ExitCode.ToString()).ConfigureAwait(false);

                    return;
                }
            }
        }
示例#6
0
 private static bool CheckSingleWatcher(IChecker watcher)
 {
     try
     {
         _log.Info($"Checking {watcher.Name}");
         return(watcher.Check());
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         return(false);
     }
 }
示例#7
0
        protected TestResult CheckAndGetTestResult(
            TestContext test,
            ProcessExecutionResult processExecutionResult,
            IChecker checker,
            string receivedOutput)
        {
            var testResult = new TestResult
            {
                Id          = test.Id,
                TimeUsed    = (int)processExecutionResult.TimeWorked.TotalMilliseconds,
                MemoryUsed  = (int)processExecutionResult.MemoryUsed,
                IsTrialTest = test.IsTrialTest,
            };

            if (processExecutionResult.Type == ProcessExecutionResultType.RunTimeError)
            {
                testResult.ResultType       = TestRunResultType.RunTimeError;
                testResult.ExecutionComment = processExecutionResult.ErrorOutput.MaxLength(2048); // Trimming long error texts
            }
            else if (processExecutionResult.Type == ProcessExecutionResultType.TimeLimit)
            {
                testResult.ResultType = TestRunResultType.TimeLimit;
            }
            else if (processExecutionResult.Type == ProcessExecutionResultType.MemoryLimit)
            {
                testResult.ResultType = TestRunResultType.MemoryLimit;
            }
            else if (processExecutionResult.Type == ProcessExecutionResultType.Success)
            {
                var checkerResult = checker.Check(test.Input, receivedOutput, test.Output, test.IsTrialTest);

                testResult.ResultType = checkerResult.IsCorrect
                    ? TestRunResultType.CorrectAnswer
                    : TestRunResultType.WrongAnswer;

                // TODO: Do something with checkerResult.ResultType
                testResult.CheckerDetails = checkerResult.CheckerDetails;
            }
            else
            {
                throw new ArgumentOutOfRangeException(
                          nameof(processExecutionResult),
                          "Invalid ProcessExecutionResultType value.");
            }

            testResult.Input = test.Input;

            return(testResult);
        }
    private static void TestChecker(IChecker checker, string expectedOutput, string userOutput)
    {
        var input = "";
        var result = checker.Check(input, userOutput, expectedOutput, false);

        Console.WriteLine("Correct: " + result.IsCorrect);
        if (!result.IsCorrect)
        {
            Console.WriteLine(result.CheckerDetails.Comment);
            Console.WriteLine("User output:");
            Console.WriteLine(result.CheckerDetails.UserOutputFragment);
            Console.WriteLine("Expected output:");
            Console.WriteLine(result.CheckerDetails.ExpectedOutputFragment);
        }
    }
示例#9
0
        static void Main(string[] args)
        {
            int type;

            Console.WriteLine("Select logger:\n1.Console logger\n2.File logger\n3.Combo logger");

            Int32.TryParse(Console.ReadLine(), out type);
            IocInit(type);

            IChecker checker = Ioc.Get <IChecker>();
            ILogger  logger  = Ioc.Get <ILogger>();

            logger.Log(checker.Check());

            Console.ReadKey();
        }
示例#10
0
    public static void Main(string[] args)
    {
        Source sc = new Source();

        sc.TestA("テストデータ");

        Console.WriteLine("return : {0}", sc.Check(100, "a"));

        sc.PrintLog();

        IChecker checker = sc as IChecker;

        if (checker != null)
        {
            Console.WriteLine("Interface Imple : {0}", checker.Check(100, "a"));
        }
    }
示例#11
0
        public (bool, string) VerifyPassword(string password)
        {
            if (password == null)
            {
                throw new ArgumentException($"{password} is null arg");
            }


            bool suitable = checker.Check(password);

            if (suitable)
            {
                repository.Create(password);
                return(true, "Password is Ok. User was created");
            }

            return(suitable, "Password isn't suitable");
        }
示例#12
0
        public new void Tick()
        {
            if (ActiveChecker == null || Pet.ActiveGear == null || Pet.GetOwner() == null || Pet.Spacemap != Pet.GetOwner().Spacemap)
            {
                Exit();
                return;
            }

            if (Pet.Hangar.Configurations == null || Pet.Hangar.Configurations.Length != 2)
            {
                Packet.Builder.LegacyModule(Pet.GetOwner().GetGameSession(), "0|A|STD|Failed launching PET, error in configurations. Please PM an admin on Discord.");
                Exit();
                return;
            }

            Pet.ActiveGear.Tick();
            ActiveChecker.Check();
        }
 public List <Driver> GetFreeDrivers(DateRange range)
 {
     return(GetSchedule()
            .Drivers
            .Where(d =>
     {
         var schedule = GetSchedule().DeepClone();
         var driver = schedule
                      .Drivers
                      .Where(dd => dd.Name == d.Name)
                      .FirstOrDefault();
         if (driver == null)
         {
             return false;                     // ???
         }
         if (driver.Assignments.Any(a => a.Range.Intersects(range)))
         {
             return false;
         }
         driver.Assignments.Add(new Assignment
         {
             Range = range,
             TrainId = "temp",
             TrainType = TrainType.Electric
         });
         driver.Assignments = driver.Assignments.OrderBy(a => a.Range.ExactFrom).ToList();
         try
         {
             checker.Check(schedule);
             return true;
         }
         catch (ValidationException)
         {
             return false;
         }
     })
            .ToList());
 }
示例#14
0
文件: Judger.cs 项目: YuroKy/Judge
        public void Assessment(string pathToSolve, Problem problem, ExecuteConfiguration configuration)
        {
            foreach (var solve in problem.Tests)
            {
                Executor exe           = new Executor();
                var      executeOutput = exe.Execute(pathToSolve, solve.Test, _options, configuration.StartArgument);

                var testVerdict = _limitChecker.CheckTime(executeOutput, _options);
                testVerdict = _limitChecker.CheckMemory(executeOutput, _options);
                if (testVerdict.Verdict == TypeVerdicts.OK)
                {
                    if (_checker.Check(solve.Answer, executeOutput.Result))
                    {
                        testVerdict.UpdateVerdict(TypeVerdicts.OK);
                    }
                    else
                    {
                        testVerdict.UpdateVerdict(TypeVerdicts.WrongAnswer);
                    }
                }
                _protocol.Results.Add(solve, testVerdict);
            }
        }
示例#15
0
        public virtual void Begin()
        {
            result = checker.Check();

            if (notifyResultFilters != null)
            {
                foreach (INotifyResultFilter filter in notifyResultFilters)
                {
                    if (filter.Evaluate(result))
                    {
                        passedFilters.Add(filter);
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (notifier != null)
            {
                notifier.Notify(result, identifier);
            }
        }
示例#16
0
        /// <summary>
        /// Apply a <see cref="CompareTarget"/> to a checker for some entities.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="checker"></param>
        /// <param name="expected"></param>
        /// <param name="candidate"></param>
        /// <param name="objectName"></param>
        protected void Check(CompareTarget target, IChecker checker, object expected, object candidate, string objectName)
        {
            switch (target)
            {
                case CompareTarget.Ignore:
                    break;

                case CompareTarget.Id:
                    CheckId(expected, candidate, objectName + ".Id");
                    break;

                case CompareTarget.Entity:
                    checker.Check(expected, candidate, objectName);
                    break;

                case CompareTarget.Count:
                case CompareTarget.Collection:
                    Check(checker, expected as IEnumerable, candidate as IEnumerable, objectName);
                    break;

                case CompareTarget.Value:
                    Check(expected, candidate, objectName);
                    break;

                default:
                    throw new NotSupportedException("Cannot perform comparison: " + target);
            }
        }
        protected TestResult ExecuteAndCheckTest(TestContext test, ProcessExecutionResult processExecutionResult, IChecker checker, string receivedOutput)
        {
            var testResult = new TestResult
            {
                Id = test.Id,
                TimeUsed = (int)processExecutionResult.TimeWorked.TotalMilliseconds,
                MemoryUsed = (int)processExecutionResult.MemoryUsed,
            };

            if (processExecutionResult.Type == ProcessExecutionResultType.RunTimeError)
            {
                testResult.ResultType = TestRunResultType.RunTimeError;
                testResult.ExecutionComment = processExecutionResult.ErrorOutput.MaxLength(2048); // Trimming long error texts
            }
            else if (processExecutionResult.Type == ProcessExecutionResultType.TimeLimit)
            {
                testResult.ResultType = TestRunResultType.TimeLimit;
            }
            else if (processExecutionResult.Type == ProcessExecutionResultType.MemoryLimit)
            {
                testResult.ResultType = TestRunResultType.MemoryLimit;
            }
            else if (processExecutionResult.Type == ProcessExecutionResultType.Success)
            {
                var checkerResult = checker.Check(test.Input, receivedOutput, test.Output, test.IsTrialTest);
                if (checkerResult.IsCorrect)
                {
                    testResult.ResultType = TestRunResultType.CorrectAnswer;
                }
                else
                {
                    testResult.ResultType = TestRunResultType.WrongAnswer;
                }

                // TODO: Do something with checkerResult.ResultType
                testResult.CheckerComment = checkerResult.CheckerDetails;
            }
            else
            {
                throw new ArgumentOutOfRangeException("processExecutionResult", "Invalid ProcessExecutionResultType value.");
            }

            return testResult;
        }
        protected void Check(CompareTarget target, IChecker checker, object expected, object candidate, string objectName)
        {
            switch (target)
            {
                case CompareTarget.Id:
                    CheckId(expected, candidate, objectName + ".Id");
                    break;

                case CompareTarget.Entity:
                    checker.Check(expected, candidate, objectName);
                    break;

                case CompareTarget.Count:
                case CompareTarget.Collection:
                    this.Check(checker, expected as IEnumerable, candidate as IEnumerable, objectName);
                    break;

                default:
                    if (CheckNullNotNull(expected, candidate, objectName))
                    {
                        return;
                    }

                    if (!expected.Equals(candidate))
                    {
                        throw new PropertyCheckException(objectName, expected, candidate);
                    }
                    break;
            }
        }