forked from MarcosFelipeBC/contest-finder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.cs
101 lines (87 loc) · 2.86 KB
/
App.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ContestFinder.Models;
using ContestFinder.Communication;
using ContestFinder.Services;
namespace ContestFinder
{
public class App
{
private List<ContestDefinition> _contests;
private List<String> _users;
public App()
{
var responseContests = CodeforcesClient.GetContestsList(false);
_users = IO.GetUsers();
var responseCheckUsers = CheckUsers(_users);
responseCheckUsers.GetAwaiter().GetResult();
var able = responseCheckUsers.Result;
if(!able)
{
throw new Exception();
}
var response = responseContests.GetAwaiter().GetResult();
if(response.Status == "FAILED")
{
throw new Exception();
}
_contests = response.Result;
if(IO.OlderFirst())
{
_contests.Reverse();
}
}
public async Task<bool> CheckUsers(List<string> users)
{
bool able = true;
foreach (var username in users)
{
var responseUser = await CodeforcesClient.GetUser(username);
if(responseUser.Status == "FAILED"){
Console.WriteLine($"User {username} does not exist");
able = false;
}
}
return able;
}
public async Task<int> NextContest(string filter, int idx)
{
for (; idx < _contests.Count; idx++)
{
var contest = _contests[idx];
if(contest.Phase == "FINISHED" && contest.Name.Contains(filter))
{
bool able = true;
foreach (var user in _users)
{
var responseStatus = await CodeforcesClient.GetStatus(contest.Id, user);
if(responseStatus.Result.Count != 0){
able = false;
break;
}
}
if(able) return idx;
}
}
return -1;
}
public void FindContest()
{
var filter = IO.GetFilter();
var idx = 0;
var nextContestIndex = NextContest(filter, idx);
do
{
var contestIdx = nextContestIndex.GetAwaiter().GetResult();
if(contestIdx == -1) {
IO.NotFound();
Environment.Exit(1);
}
idx = contestIdx+1;
IO.DisplayContest(_contests[contestIdx]);
nextContestIndex = NextContest(filter, idx);
} while(IO.AnotherContest());
}
}
}