/
Data.vb
529 lines (425 loc) · 22.3 KB
/
Data.vb
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
Imports System
Imports System.Collections.ObjectModel
Imports System.Globalization
Imports System.Linq
Imports System.Windows.Media
Imports DevExpress.Mvvm
Imports DevExpress.XtraScheduler
Namespace DXSample.Data
'#Region "Data classes"
Public Class SportEvent
Inherits BindableBase
Public Property Id As Integer
Get
Return GetValue(Of Integer)()
End Get
Set(ByVal value As Integer)
SetValue(value)
End Set
End Property
Public Property StartTime As Date
Get
Return GetValue(Of Date)()
End Get
Set(ByVal value As Date)
SetValue(value)
End Set
End Property
Public Property EndTime As Date
Get
Return GetValue(Of Date)()
End Get
Set(ByVal value As Date)
SetValue(value)
End Set
End Property
Public Property Caption As String
Get
Return GetValue(Of String)()
End Get
Set(ByVal value As String)
SetValue(value)
RaisePropertyChanged(Function() CustomText)
End Set
End Property
Public Property ChannelId As Integer
Get
Return GetValue(Of Integer)()
End Get
Set(ByVal value As Integer)
SetValue(value)
End Set
End Property
Public Property SportId As Integer
Get
Return GetValue(Of Integer)()
End Get
Set(ByVal value As Integer)
SetValue(value)
End Set
End Property
Public Property Type As Integer?
Get
Return GetValue(Of Integer?)()
End Get
Set(ByVal value As Integer?)
SetValue(value)
End Set
End Property
Public Property AllDay As Boolean
Get
Return GetValue(Of Boolean)()
End Get
Set(ByVal value As Boolean)
SetValue(value)
End Set
End Property
Public Property Location As String
Get
Return GetValue(Of String)()
End Get
Set(ByVal value As String)
SetValue(value)
RaisePropertyChanged(Function() CustomText)
End Set
End Property
Public Property Description As String
Get
Return GetValue(Of String)()
End Get
Set(ByVal value As String)
SetValue(value)
End Set
End Property
Public Property RecurrenceInfo As String
Get
Return GetValue(Of String)()
End Get
Set(ByVal value As String)
SetValue(value)
End Set
End Property
Public Property ReminderInfo As String
Get
Return GetValue(Of String)()
End Get
Set(ByVal value As String)
SetValue(value)
End Set
End Property
Public ReadOnly Property CustomText As String
Get
Return $"{Location} - {Caption}"
End Get
End Property
End Class
Public Class SportChannel
Inherits BindableBase
Public Property Id As Integer
Get
Return GetValue(Of Integer)()
End Get
Set(ByVal value As Integer)
SetValue(value)
End Set
End Property
Public Property Caption As String
Get
Return GetValue(Of String)()
End Get
Set(ByVal value As String)
SetValue(value)
End Set
End Property
Public ReadOnly Property HasNews As Boolean
Get
Return Not NewsTimeRange.IsZero
End Get
End Property
Public Property IsVisible As Boolean
Get
Return GetValue(Of Boolean)()
End Get
Set(ByVal value As Boolean)
SetValue(value)
End Set
End Property
Public Property NewsTimeRange As TimeSpanRange
Get
Return GetValue(Of TimeSpanRange)()
End Get
Set(ByVal value As TimeSpanRange)
SetValue(value)
RaisePropertyChanged(Function() HasNews)
End Set
End Property
End Class
Public Class SportGroup
Inherits BindableBase
Public Property Id As Integer
Get
Return GetValue(Of Integer)()
End Get
Set(ByVal value As Integer)
SetValue(value)
End Set
End Property
Public Property Caption As String
Get
Return GetValue(Of String)()
End Get
Set(ByVal value As String)
SetValue(value)
End Set
End Property
Public Property Color As Color
Get
Return GetValue(Of Color)()
End Get
Set(ByVal value As Color)
SetValue(value)
End Set
End Property
Public Property Image As ImageSource
Get
Return GetValue(Of ImageSource)()
End Get
Set(ByVal value As ImageSource)
SetValue(value)
End Set
End Property
End Class
'#End Region
'#Region "Data generator"
Public Class SportChannelsDataHelper
Private _Groups As ObservableCollection(Of DXSample.Data.SportGroup), _Channels As ObservableCollection(Of DXSample.Data.SportChannel), _Events As ObservableCollection(Of DXSample.Data.SportEvent)
Public Shared ReadOnly SportGroups As SportGroup() = {New SportGroup() With {.Id = 0, .Caption = "SportNews", .Color = Color.FromRgb(255, 255, 255)}, New SportGroup() With {.Id = 1, .Caption = "Basketball", .Color = Color.FromRgb(&HFF, &HC2, &HBE)}, New SportGroup() With {.Id = 2, .Caption = "Boxing", .Color = Color.FromRgb(&HA8, &HD5, &HFF)}, New SportGroup() With {.Id = 3, .Caption = "Tennis", .Color = Color.FromRgb(&HC1, &HF4, &H9C)}, New SportGroup() With {.Id = 4, .Caption = "Soccer", .Color = Color.FromRgb(&HF3, &HE4, &HC7)}, New SportGroup() With {.Id = 5, .Caption = "Artistic Gymnastics", .Color = Color.FromRgb(&HF4, &HCE, &H93)}, New SportGroup() With {.Id = 6, .Caption = "Canoe", .Color = Color.FromRgb(&HC7, &HF4, &HFF)}, New SportGroup() With {.Id = 7, .Caption = "Kayak", .Color = Color.FromRgb(&HCF, &HDB, &H98)}, New SportGroup() With {.Id = 8, .Caption = "Sailing", .Color = Color.FromRgb(&HE0, &HCF, &HE9)}, New SportGroup() With {.Id = 9, .Caption = "Swimming", .Color = Color.FromRgb(&H8D, &HE9, &HDF)}, New SportGroup() With {.Id = 10, .Caption = "Shooting", .Color = Color.FromRgb(&HFF, &HF7, &HA5)}}
Private Shared Function GenerateEvents(ByVal dayCount As Integer) As ObservableCollection(Of SportEvent)
Dim result As ObservableCollection(Of SportEvent) = New ObservableCollection(Of SportEvent)()
Dim aptId As Integer = 0
For Each ch As SportChannel In sportChannels
Dim start As Date = Date.Today - TimeSpan.FromDays(dayCount)
Dim [end] As Date = Date.Today + TimeSpan.FromDays(dayCount)
If ch.HasNews Then result.Add(GetRandomRecurrenceSportEvent(Math.Min(Threading.Interlocked.Increment(aptId), aptId - 1), start, ch, dayCount * 2 - 1))
Dim i As Date = start
While i < [end]
If i.DayOfWeek = DayOfWeek.Saturday OrElse i.DayOfWeek = DayOfWeek.Sunday Then
result.Add(GetRandomSportEvent(Math.Min(Threading.Interlocked.Increment(aptId), aptId - 1), i, i + TimeSpan.FromDays(1), ch.Id))
Continue While
End If
Dim airtimeStart As Date = New DateTime(i.Year, i.Month, i.Day, 6, 0, 0)
Dim airtimeEnd As Date = New DateTime(i.Year, i.Month, i.Day, 21, 0, 0)
Dim aptStartTime As Date = airtimeStart
While aptStartTime < airtimeEnd
Dim aptEndTime As Date
Dim duration As TimeSpan = TimeSpan.FromMinutes(rnd.Next(20, 180))
Dim newsTimeRange As TimeSpanRange = ch.NewsTimeRange
If ch.HasNews Then
Dim timeBeforeNews As Long =(newsTimeRange.Start - aptStartTime.TimeOfDay).Ticks
If timeBeforeNews > 0 AndAlso (timeBeforeNews < TimeSpan.FromMinutes(30).Ticks OrElse timeBeforeNews <= duration.Ticks) Then
aptEndTime = aptStartTime.Date + newsTimeRange.Start
result.Add(GetRandomSportEvent(Math.Min(Threading.Interlocked.Increment(aptId), aptId - 1), aptStartTime, aptEndTime, ch.Id))
aptStartTime = aptEndTime.Date + newsTimeRange.End
Continue While
End If
End If
aptEndTime = aptStartTime + duration
result.Add(GetRandomSportEvent(Math.Min(Threading.Interlocked.Increment(aptId), aptId - 1), aptStartTime, aptEndTime, ch.Id))
aptStartTime = aptEndTime
End While
i += TimeSpan.FromDays(1)
End While
Next
Return result
End Function
Private Shared recurrenceInfoFormat As String = "<RecurrenceInfo Start=""{0}"" End=""{1}"" WeekDays=""{2}"" OccurrenceCount=""{3}"" Range=""{4}"" Type=""{5}"" Id=""{6}""/>"
Private Shared Function GetRandomRecurrenceSportEvent(ByVal id As Integer, ByVal startDate As Date, ByVal channel As SportChannel, ByVal dayCount As Integer) As SportEvent
Dim pattern As SportEvent = New SportEvent()
pattern.Id = id
Dim newsTimeRange As TimeSpanRange = 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 = CInt(AppointmentType.Pattern)
Dim recInfo As RecurrenceInfo = 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, CInt(recInfo.WeekDays), recInfo.OccurrenceCount, CInt(recInfo.Range), CInt(recInfo.Type), recInfo.Id.ToString())
Return pattern
End Function
Private Shared Function GetRandomSportEvent(ByVal id As Integer, ByVal start As Date, ByVal [end] As Date, ByVal channelId As Integer) As SportEvent
Dim 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
End Function
Private Shared Function GetRandomString(ByVal events As String()) As String
Return events(rnd.Next(0, events.Count()))
End Function
Private Shared Function GetEvents(ByVal sportId As Integer) As String()
Select Case 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
End Select
Return Nothing
End Function
Private Shared Function GetLocations(ByVal sportId As Integer) As String()
Select Case 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
End Select
Return Nothing
End Function
Private Shared Function GetDescriptions(ByVal sportId As Integer) As String()
Select Case 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
End Select
Return Nothing
End Function
Private Shared rnd As Random = New Random()
Private Shared Function GetRandomNewsTimeRange(ByVal start As TimeSpan) As TimeSpanRange
Return New TimeSpanRange(start, start + TimeSpan.FromMinutes(rnd.Next(30, 60)))
End Function
'#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" },
'};
Private Shared ReadOnly sportChannels As SportChannel() = {New SportChannel() With {.Id = 0, .Caption = "SPORT TV 1", .NewsTimeRange = GetRandomNewsTimeRange(TimeSpan.FromHours(11))}, New SportChannel() With {.Id = 1, .Caption = "SPORT TV 2", .NewsTimeRange = GetRandomNewsTimeRange(TimeSpan.FromHours(19))}, New SportChannel() With {.Id = 2, .Caption = "SPORT TV 3"}, New SportChannel() With {.Id = 3, .Caption = "SPORT TV 4"}}
Private Shared ReadOnly basketballEvents As String() = {"Basketball First Group Phase - Men", "Basketball First Group Phase - Women"}
Private Shared ReadOnly boxingEvents As String() = {"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)"}
Private Shared ReadOnly tennisEvents As String() = {"Tennis - BNP Paribas Masters", "Tennis - Tennis Masters Hamburg", "Tennis - Tennis Masters Monte Carlo", "Tennis - Australian Open"}
Private Shared ReadOnly soccerEvents As String() = {"Soccer Quarter final - *Women's Quarterfinal - Women", "Soccer 1st Round - *Men's Preliminaries - Men", "Soccer places 3/4 - *Women's Bronze Medal Match - Women"}
Private Shared ReadOnly artisticGymnasticsEvents As String() = {"Artistic Gymnastics - Vault - Women - Final", "Artistic Gymnastics - Floor Exercise - Men - Final"}
Private Shared ReadOnly canoeEvents As String() = {"Canoe - Slalom C2 - Men - Heats", "Canoe - Slalom C1 - Men - Heats"}
Private Shared ReadOnly kayakEvents As String() = {"Kayak - Slalom K2 - Men - Heats", "Kayak - Slalom K1 - Women - Semi-finals"}
Private Shared ReadOnly sailingEvents As String() = {"Sailing - Finn - Race 1", "Sailing - Women's Mistral - Race 01"}
Private Shared ReadOnly swimmingEvents As String() = {"Swimming - Men's 100m Breaststroke - Heat 2", "Swimming - Women's 400m Individual Medley - Heat 2", "Swimming - Women's 100m Butterfly - Heat 1"}
Private Shared ReadOnly shootingEvents As String() = {"Shooting - Men's 50m Pistol Qualification", "Shooting - Women's 25m Pistol Final", "Shooting - Men's 10m Air Pistol Qualification"}
Private Shared ReadOnly basketballLocations As String() = {"Brooklyn, NY, USA", "Charlottesville, VA, USA"}
Private Shared ReadOnly basketballDescriptions As String() = {"Baseline Leaners vs Rimshots", "Lady Mustangs vs Houston Rockettes"}
Private Shared ReadOnly boxingLocations As String() = {"Hamburg, Germany", "Chattanooga, Tennessee, USA", "Salt Lake City, Utah, USA", "Albuquerque, New Mexico, USA"}
Private Shared ReadOnly boxingDescriptions As String() = {"IBF, IBO and WBO super middleweight belts", "WBC and WBO lightweight belts", "WBC super middleweight belt", "IBO light heavyweight belt"}
Private Shared ReadOnly tennisLocations As String() = {"Paris, France", "Hamburg, Germany", "Monte Carlo, Monaco", "Melbourne, Victoria, Australia"}
Private Shared ReadOnly tennisDescriptions As String() = {"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"}
Private Shared ReadOnly soccerLocations As String() = {"Philadelphia, PA, USA", "San Francisco, CA, USA", "New York City, USA"}
Private Shared ReadOnly soccerDescriptions As String() = {"Cheetahs vs Lady Eagles", "Amigos vs Terminators", "Spitting Cobras vs Red Dragons"}
Private Shared ReadOnly artisticGymnasticsLocations As String() = {"Hong Kong Open Championships", "World Artistic Gymnastics Championships Glasgo, UK"}
Private Shared ReadOnly artisticGymnasticsDescriptions As String() = {"Complicated vaults in different body positions, such as tucked, piked or stretched.", "Express the personalities through their music choice and choreography."}
Private Shared ReadOnly canoeLocations As String() = {"Račice, Czech republic", "Milan, Italy"}
Private Shared ReadOnly canoeDescriptions As String() = {"Row hard or row home.", "Recovery is not an option."}
Private Shared ReadOnly kayakLocations As String() = {"Puerto Deportivo el Puntal, Spain", "Danson Lake, Bexleyheath, UK"}
Private Shared ReadOnly kayakDescriptions As String() = {"After the Gold Rush vs Humpbacks", "Drag-On vs Shark Week"}
Private Shared ReadOnly sailingLocations As String() = {"Marseille, France", "Savannah, Georgia, United States"}
Private Shared ReadOnly sailingDescriptions As String() = {"Grab life by the tail, set sail", "Do or do not. There is no try."}
Private Shared ReadOnly swimmingLocations As String() = {"Budapest, Hungary", "Kazan, Russia", "Barcelona, Spain"}
Private Shared ReadOnly swimmingDescriptions As String() = {"Dashing Dolphins and Krazy Krakens", "Golden Gators and Stingrays", "Wave Makers and Murray Marlins"}
Private Shared ReadOnly shootingLocations As String() = {"Munich, Germany", "Zagreb, Croatia", "Lahti, Finland"}
Private Shared ReadOnly shootingDescriptions As String() = {"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."}
'#End Region
Public Sub New(ByVal dayCount As Integer)
Groups = New ObservableCollection(Of SportGroup)(SportGroups)
Channels = New ObservableCollection(Of SportChannel)(sportChannels)
Events = GenerateEvents(dayCount)
End Sub
Public Property Groups As ObservableCollection(Of SportGroup)
Get
Return _Groups
End Get
Private Set(ByVal value As ObservableCollection(Of SportGroup))
_Groups = value
End Set
End Property
Public Property Channels As ObservableCollection(Of SportChannel)
Get
Return _Channels
End Get
Private Set(ByVal value As ObservableCollection(Of SportChannel))
_Channels = value
End Set
End Property
Public Property Events As ObservableCollection(Of SportEvent)
Get
Return _Events
End Get
Private Set(ByVal value As ObservableCollection(Of SportEvent))
_Events = value
End Set
End Property
End Class
'#End Region
End Namespace