/
SportChannels.cs
346 lines (338 loc) · 16.5 KB
/
SportChannels.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
using DevExpress.Mvvm;
using DevExpress.XtraScheduler;
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Windows.Media;
namespace DXScheduler_PopUpMenuCustomization {
public class SportEvent {
public int Id { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string Caption { get; set; }
public int ChannelId { get; set; }
public int SportId { get; set; }
public int? Type { get; set; }
public bool AllDay { get; set; }
public string Location { get; set; }
public string Description { get; set; }
public string RecurrenceInfo { get; set; }
public string ReminderInfo { get; set; }
public string CustomText { get { return String.Format("[{0}] - {1}", Location, Caption); } set { } }
}
public class SportChannel {
public int Id { get; set; }
public string Caption { get; set; }
public bool HasNews { get { return !NewsTimeRange.IsZero; } }
public bool IsVisible { get; set; }
public TimeSpanRange NewsTimeRange { get; set; }
}
public class SportGroup {
public int Id { get; set; }
public string Caption { get; set; }
public Color Color { get; set; }
public ImageSource Image { get; set; }
}
public class SportChannelsData {
public static readonly SportGroup[] SportGroups = {
new SportGroup() { Id = 0, Caption = "SportNews", Color = Color.FromRgb(255, 255, 255)},
new SportGroup() { Id = 1, Caption = "Basketball", Color = Color.FromRgb(0xFF, 0xC2, 0xBE)},
new SportGroup() { Id = 2, Caption = "Boxing", Color = Color.FromRgb(0xA8, 0xD5, 0xFF)},
new SportGroup() { Id = 3, Caption = "Tennis", Color = Color.FromRgb(0xC1, 0xF4, 0x9C)},
new SportGroup() { Id = 4, Caption = "Soccer", Color = Color.FromRgb(0xF3, 0xE4, 0xC7)},
new SportGroup() { Id = 5, Caption = "Artistic Gymnastics", Color = Color.FromRgb(0xF4, 0xCE, 0x93)},
new SportGroup() { Id = 6, Caption = "Canoe", Color = Color.FromRgb(0xC7, 0xF4, 0xFF)},
new SportGroup() { Id = 7, Caption = "Kayak", Color = Color.FromRgb(0xCF, 0xDB, 0x98)},
new SportGroup() { Id = 8, Caption = "Sailing", Color = Color.FromRgb(0xE0, 0xCF, 0xE9)},
new SportGroup() { Id = 9, Caption = "Swimming", Color = Color.FromRgb(0x8D, 0xE9, 0xDF)},
new SportGroup() { Id = 10, Caption = "Shooting", Color = Color.FromRgb(0xFF, 0xF7, 0xA5)},
};
static ObservableCollection<SportEvent> GenerateEvents(int dayCount) {
ObservableCollection<SportEvent> result = new ObservableCollection<SportEvent>();
int aptId = 0;
foreach (SportChannel ch in sportChannels) {
DateTime start = DateTime.Today - TimeSpan.FromDays(dayCount);
DateTime end = DateTime.Today + TimeSpan.FromDays(dayCount);
if (ch.HasNews)
result.Add(GetRandomRecurrenceSportEvent(aptId++, start, ch, (dayCount * 2) - 1));
for (DateTime i = start; i < end; i += TimeSpan.FromDays(1)) {
if (i.DayOfWeek == DayOfWeek.Saturday || i.DayOfWeek == DayOfWeek.Sunday) {
result.Add(GetRandomSportEvent(aptId++, i, i + TimeSpan.FromDays(1), ch.Id));
continue;
}
DateTime airtimeStart = new DateTime(i.Year, i.Month, i.Day, 6, 0, 0);
DateTime airtimeEnd = new DateTime(i.Year, i.Month, i.Day, 21, 0, 0);
DateTime aptStartTime = airtimeStart;
while (aptStartTime < airtimeEnd) {
DateTime aptEndTime;
TimeSpan duration = TimeSpan.FromMinutes(rnd.Next(20, 180));
TimeSpanRange newsTimeRange = ch.NewsTimeRange;
if (ch.HasNews) {
long timeBeforeNews = (newsTimeRange.Start - aptStartTime.TimeOfDay).Ticks;
if (timeBeforeNews > 0 && (timeBeforeNews < TimeSpan.FromMinutes(30).Ticks || timeBeforeNews <= duration.Ticks)) {
aptEndTime = aptStartTime.Date + newsTimeRange.Start;
result.Add(GetRandomSportEvent(aptId++, aptStartTime, aptEndTime, ch.Id));
aptStartTime = aptEndTime.Date + newsTimeRange.End;
continue;
}
}
aptEndTime = aptStartTime + duration;
result.Add(GetRandomSportEvent(aptId++, aptStartTime, aptEndTime, ch.Id));
aptStartTime = aptEndTime;
}
}
}
return result;
}
static string recurrenceInfoFormat = @"<RecurrenceInfo Start=""{0}"" End=""{1}"" WeekDays=""{2}"" OccurrenceCount=""{3}"" Range=""{4}"" Type=""{5}"" Id=""{6}""/>";
static SportEvent GetRandomRecurrenceSportEvent(int id, DateTime startDate, SportChannel channel, int dayCount) {
SportEvent pattern = new SportEvent();
pattern.Id = id;
TimeSpanRange newsTimeRange = channel.NewsTimeRange;
pattern.StartTime = startDate + newsTimeRange.Start;
pattern.EndTime = startDate + newsTimeRange.End;
pattern.SportId = 0;
pattern.ChannelId = channel.Id;
pattern.Caption = "Sport News";
pattern.Location = "New York City, USA";
pattern.Type = (int)AppointmentType.Pattern;
RecurrenceInfo recInfo = new RecurrenceInfo();
recInfo.Start = pattern.StartTime;
recInfo.End = pattern.EndTime.AddDays(dayCount);
recInfo.WeekDays = WeekDays.WorkDays;
recInfo.Range = RecurrenceRange.EndByDate;
recInfo.Type = RecurrenceType.Daily;
pattern.RecurrenceInfo = String.Format(CultureInfo.InvariantCulture, recurrenceInfoFormat,
recInfo.Start, recInfo.End, (int)recInfo.WeekDays, recInfo.OccurrenceCount, (int)recInfo.Range, (int)recInfo.Type, recInfo.Id.ToString());
return pattern;
}
static SportEvent GetRandomSportEvent(int id, DateTime start, DateTime end, int channelId) {
var res = new SportEvent();
res.Id = id;
res.StartTime = start;
res.EndTime = end;
res.SportId = rnd.Next(1, 10);
res.ChannelId = channelId;
res.Caption = GetRandomString(GetEvents(res.SportId));
res.Location = GetRandomString(GetLocations(res.SportId));
res.Description = GetRandomString(GetDescriptions(res.SportId));
res.Type = 0;
return res;
}
static string GetRandomString(string[] events) {
return events[rnd.Next(0, events.Count())];
}
static string[] GetEvents(int sportId) {
switch (sportId) {
case 1: return basketballEvents;
case 2: return boxingEvents;
case 3: return tennisEvents;
case 4: return soccerEvents;
case 5: return artisticGymnasticsEvents;
case 6: return canoeEvents;
case 7: return kayakEvents;
case 8: return sailingEvents;
case 9: return swimmingEvents;
case 10: return shootingEvents;
}
return null;
}
static string[] GetLocations(int sportId) {
switch (sportId) {
case 1: return basketballLocations;
case 2: return boxingLocations;
case 3: return tennisLocations;
case 4: return soccerLocations;
case 5: return artisticGymnasticsLocations;
case 6: return canoeLocations;
case 7: return kayakLocations;
case 8: return sailingLocations;
case 9: return swimmingLocations;
case 10: return shootingLocations;
}
return null;
}
static string[] GetDescriptions(int sportId) {
switch (sportId) {
case 1: return basketballDescriptions;
case 2: return boxingDescriptions;
case 3: return tennisDescriptions;
case 4: return soccerDescriptions;
case 5: return artisticGymnasticsDescriptions;
case 6: return canoeDescriptions;
case 7: return kayakDescriptions;
case 8: return sailingDescriptions;
case 9: return swimmingDescriptions;
case 10: return shootingDescriptions;
}
return null;
}
static Random rnd = new Random();
static TimeSpanRange GetRandomNewsTimeRange(TimeSpan start) {
return new TimeSpanRange(start, start + TimeSpan.FromMinutes(rnd.Next(30, 60)));
}
#region Sample Data
static readonly SportChannel[] sportChannels = {
new SportChannel() { Id = 0, Caption = "SPORT TV 1", NewsTimeRange = GetRandomNewsTimeRange(TimeSpan.FromHours(11)) },
new SportChannel() { Id = 1, Caption = "SPORT TV 2", NewsTimeRange = GetRandomNewsTimeRange(TimeSpan.FromHours(19)) },
new SportChannel() { Id = 2, Caption = "SPORT TV 3" },
new SportChannel() { Id = 3, Caption = "SPORT TV 4" },
new SportChannel() { Id = 4, Caption = "TV 5" },
new SportChannel() { Id = 5, Caption = "TV 6" },
new SportChannel() { Id = 6, Caption = "TV 7" },
new SportChannel() { Id = 7, Caption = "TV 8" },
};
static readonly string[] basketballEvents = {
"Basketball First Group Phase - Men",
"Basketball First Group Phase - Women"
};
static readonly string[] boxingEvents = {
"Boxing - ((Showtime) Jeff Lacy (20-0) vs. Joe Calzaghe (39-0) (IBF, IBO and WBO super middleweight belts)",
"Boxing - ((WBC and WBO lightweight belts) (PPV) Carlos Hernandez vs. Bobby Pacquiao",
"Boxing - (Danilo Haussler (25-3) vs. TBA",
"Boxing - (PPV) Antonio Tarver (23-3) vs. Roy Jones (49-3) (IBO light heavyweight belt)"
};
static readonly string[] tennisEvents = {
"Tennis - BNP Paribas Masters",
"Tennis - Tennis Masters Hamburg",
"Tennis - Tennis Masters Monte Carlo",
"Tennis - Australian Open"
};
static readonly string[] soccerEvents = {
"Soccer Quarter final - *Women's Quarterfinal - Women",
"Soccer 1st Round - *Men's Preliminaries - Men",
"Soccer places 3/4 - *Women's Bronze Medal Match - Women",
};
static readonly string[] artisticGymnasticsEvents = {
"Artistic Gymnastics - Vault - Women - Final",
"Artistic Gymnastics - Floor Exercise - Men - Final",
};
static readonly string[] canoeEvents = {
"Canoe - Slalom C2 - Men - Heats",
"Canoe - Slalom C1 - Men - Heats",
};
static readonly string[] kayakEvents = {
"Kayak - Slalom K2 - Men - Heats",
"Kayak - Slalom K1 - Women - Semi-finals",
};
static readonly string[] sailingEvents = {
"Sailing - Finn - Race 1",
"Sailing - Women's Mistral - Race 01",
};
static readonly string[] swimmingEvents = {
"Swimming - Men's 100m Breaststroke - Heat 2",
"Swimming - Women's 400m Individual Medley - Heat 2",
"Swimming - Women's 100m Butterfly - Heat 1",
};
static readonly string[] shootingEvents = {
"Shooting - Men's 50m Pistol Qualification",
"Shooting - Women's 25m Pistol Final",
"Shooting - Men's 10m Air Pistol Qualification",
};
static readonly string[] basketballLocations = {
"Brooklyn, NY, USA",
"Charlottesville, VA, USA"
};
static readonly string[] basketballDescriptions = {
"Baseline Leaners vs Rimshots",
"Lady Mustangs vs Houston Rockettes"
};
static readonly string[] boxingLocations = {
"Hamburg, Germany",
"Chattanooga, Tennessee, USA",
"Salt Lake City, Utah, USA",
"Albuquerque, New Mexico, USA",
};
static readonly string[] boxingDescriptions = {
"IBF, IBO and WBO super middleweight belts",
"WBC and WBO lightweight belts",
"WBC super middleweight belt",
"IBO light heavyweight belt",
};
static readonly string[] tennisLocations = {
"Paris, France",
"Hamburg, Germany",
"Monte Carlo, Monaco",
"Melbourne, Victoria, Australia"
};
static readonly string[] tennisDescriptions = {
"One Hit Wonders vs Big Hitters",
"Love Hurts vs Queens of the Court",
"Alley Gators vs String Nation",
"Tennis the Menace vs Heavy Duty Felt"
};
static readonly string[] soccerLocations = {
"Philadelphia, PA, USA",
"San Francisco, CA, USA",
"New York City, USA",
};
static readonly string[] soccerDescriptions = {
"Cheetahs vs Lady Eagles",
"Amigos vs Terminators",
"Spitting Cobras vs Red Dragons",
};
static readonly string[] artisticGymnasticsLocations = {
"Hong Kong Open Championships",
"World Artistic Gymnastics Championships Glasgo, UK",
};
static readonly string[] artisticGymnasticsDescriptions = {
"Complicated vaults in different body positions, such as tucked, piked or stretched.",
"Express the personalities through their music choice and choreography.",
};
static readonly string[] canoeLocations = {
"Račice, Czech republic",
"Milan, Italy",
};
static readonly string[] canoeDescriptions = {
"Row hard or row home.",
"Recovery is not an option.",
};
static readonly string[] kayakLocations = {
"Puerto Deportivo el Puntal, Spain",
"Danson Lake, Bexleyheath, UK",
};
static readonly string[] kayakDescriptions = {
"After the Gold Rush vs Humpbacks",
"Drag-On vs Shark Week",
};
static readonly string[] sailingLocations = {
"Marseille, France",
"Savannah, Georgia, United States",
};
static readonly string[] sailingDescriptions = {
"Grab life by the tail, set sail",
"Do or do not. There is no try.",
};
static readonly string[] swimmingLocations = {
"Budapest, Hungary",
"Kazan, Russia",
"Barcelona, Spain",
};
static readonly string[] swimmingDescriptions = {
"Dashing Dolphins and Krazy Krakens",
"Golden Gators and Stingrays",
"Wave Makers and Murray Marlins",
};
static readonly string[] shootingLocations = {
"Munich, Germany",
"Zagreb, Croatia",
"Lahti, Finland",
};
static readonly string[] shootingDescriptions = {
"Shoot over a distance of 50 meters / 54.68 yards in standing position, using a 5.6 millimeters / 0.22 inches caliber pistol with no weight restriction.",
"Shoot over a distance of 25 meters / 27.34 yards in standing position, using a 5.6 millimeters / 0.22 inches caliber pistol with a maximum weight of 1.4 kilograms / 3.09 libbers.",
"Shoot over a distance of 10 meters / 10.94 yards in standing position, using a 4.5 millimeters / 0.177 inches caliber air pistol with a maximum weight of 1.5 kilograms / 3,31 libbers.",
};
#endregion
public SportChannelsData(int dayCount) {
Groups = new ObservableCollection<SportGroup>(SportGroups);
Channels = new ObservableCollection<SportChannel>(sportChannels);
Events = GenerateEvents(dayCount);
}
public ObservableCollection<SportGroup> Groups { get; private set; }
public ObservableCollection<SportChannel> Channels { get; private set; }
public ObservableCollection<SportEvent> Events { get; private set; }
public ObservableCollection<SportEvent> CancelledEvents { get; private set; }
}
}