-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataHandler.cs
163 lines (128 loc) · 5.63 KB
/
DataHandler.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SportInfoUI
{
public static class DataHandler
{
public static async Task<List<SportInfo>> processSportInput(string sport, string week, string day, string exAge, string exWord, string sportType)
{
//General variables
bool controlFlag = true;
List<SportInfo> infoTable = new List<SportInfo>();
string[] exAges = exAge.Split(';');
string[] exWords = exWord.Split(";");
//Define Sport Type boolean control
bool isIce = false;
if (sportType.Equals("Ice"))
isIce = true;
string generalResponse;
if(isIce)
generalResponse = await HTTPHandler.GETIceSportGeneralResponse();
else
generalResponse = await HTTPHandler.GETNonIceSportGeneralResponse();
RootObj rootObj;
//Convert response to JSON format
try
{
rootObj = JsonConvert.DeserializeObject<RootObj>(generalResponse);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return infoTable;
}
foreach (var venue in rootObj.features)
{
List<string?> sportCat = new List<string?>();
string? venueName;
int id = venue.attributes.locationid == null? 0 : (int)venue.attributes.locationid;
if (isIce)
{
sportCat.Add(venue.attributes.activity_type);
venueName = venue.attributes.location;
}
else
{
sportCat.Add(venue.attributes.sports_activities_a_d);
sportCat.Add(venue.attributes.sports_activities_e_p);
sportCat.Add(venue.attributes.sports_activities_s_z);
venueName = venue.attributes.complexname;
}
foreach(string? sportlist in sportCat)
{
if (!string.IsNullOrEmpty(sportlist) ? sportlist.Contains(sport) : false)
{
string info;
if (isIce)
info = await HTTPHandler.GETIceSportInfo(id, week);
else
info = await HTTPHandler.GETNonIceSportInfo(id, week);
RootPrograms? infoObj;
//Convert response to JSON format
try
{
infoObj = JsonConvert.DeserializeObject<RootPrograms>(info);
if (infoObj == null)
{
continue;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return infoTable;
}
try
{
List<Day>? programs = infoObj.programs[0].days;
foreach (Day program in programs)
{
//Set up controlFlag
controlFlag = program.title.Contains(sport);
if (!exAge.Equals(""))
foreach (string age in exAges)
{
controlFlag &= !program.age.Contains(age);
}
if (!exWord.Equals(""))
foreach (string word in exWords)
{
controlFlag &= !program.title.Contains(word);
}
if (controlFlag)
{
foreach (Time time in program.times)
{
if (time.day.Contains(day))
{
//commCentre, sportName, weekday, time
infoTable.Add(new SportInfo()
{
venue = venueName,
sport = program.title + " " + program.age,
day = time.day,
time = time.title
});
//Console.WriteLine(program.title);
//Console.WriteLine(time.day + "\t" + time.title);
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return new List<SportInfo>();
}
}
}
}
return infoTable;
}
}
}