コード例 #1
0
        private static void Process(InputFormat inputFormat, OutputFormat outputFormat, string fromCode,
                                    string fromList,
                                    VjudgeOverflowBehavior overflowBehavior, int penaltyTime)
        {
            if (!string.IsNullOrEmpty(fromCode) && !string.IsNullOrEmpty(fromList))
            {
                Console.WriteLine("'--fromCode' and '--fromList' can not be simultaneously set!");
                return;
            }

            if (string.IsNullOrEmpty(fromCode) && string.IsNullOrEmpty(fromList))
            {
                Console.WriteLine("At least one of '--fromCode' and '--fromList' must be set!");
                return;
            }

            if (!string.IsNullOrEmpty(fromCode))
            {
                Process(inputFormat, outputFormat, fromCode, overflowBehavior, penaltyTime);
            }
            else
            {
                var lines = File.ReadAllLines(fromList);
                foreach (var line in lines)
                {
                    Process(inputFormat, outputFormat, line, overflowBehavior, penaltyTime);
                }
            }
        }
コード例 #2
0
        private static void Process(InputFormat inputFormat, OutputFormat outputFormat, string fromCode,
                                    VjudgeOverflowBehavior overflowBehavior, int penaltyTime)
        {
            RanklistResponse response;

            switch (inputFormat)
            {
            case InputFormat.Fetch:
                var requester = new RanklistRequester();
                response = requester.GetRanklistAsync(fromCode).GetAwaiter().GetResult();
                break;

            case InputFormat.Json:
                var jsonText = File.ReadAllText(fromCode);
                response = JsonSerializer.Deserialize <RanklistResponse>(jsonText);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(inputFormat));
            }

            var dirPath = response.Contest.ContestCode;

            Directory.CreateDirectory(dirPath); // doesn't do anything if they already exist!

            if ((outputFormat & OutputFormat.Json) > 0)
            {
                var outputJson = JsonSerializer.Serialize(response);
                File.WriteAllText(Path.Combine(dirPath, "raw.json"), outputJson);
            }

            if ((outputFormat & OutputFormat.Vjudge) > 0)
            {
                var exporter = new VjudgeExporter(overflowBehavior, TimeSpan.FromMinutes(penaltyTime));
                exporter.Export(response, dirPath);
            }
        }
コード例 #3
0
 public VjudgeExporter(VjudgeOverflowBehavior overflowBehavior, TimeSpan penaltyTime)
 {
     _overflowBehavior = overflowBehavior;
     _penaltyTime      = penaltyTime;
 }