-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModels.vb
More file actions
540 lines (461 loc) · 19.8 KB
/
Copy pathModels.vb
File metadata and controls
540 lines (461 loc) · 19.8 KB
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
530
531
532
533
534
535
536
537
538
539
540
''' <summary>
''' Models.vb - Modelli dati dell'applicazione QueueMonitor
''' Contiene tutte le classi dati, enumerazioni e configurazioni.
''' </summary>
Imports System.ComponentModel
Imports System.Text.Json
Imports System.Text.Json.Serialization
Imports System.IO
'Namespace QueueMonitor
' ═══════════════════════════════════════════════════════════
' ENUMERAZIONI
' ═══════════════════════════════════════════════════════════
''' <summary>
''' Stile visivo del gauge
''' </summary>
Public Enum GaugeStyle
''' <summary>Arco semicircolare classico</summary>
Semicircle = 0
''' <summary>Arco completo 270 gradi</summary>
Arc270 = 1
''' <summary>Barra orizzontale</summary>
HorizontalBar = 2
''' <summary>Barra verticale</summary>
VerticalBar = 3
End Enum
''' <summary>
''' Schema colori del gauge
''' </summary>
Public Enum GaugeColorScheme
''' <summary>Verde → Giallo → Rosso (default)</summary>
TrafficLight = 0
''' <summary>Blu → Ciano → Verde</summary>
Ocean = 1
''' <summary>Viola → Rosa → Arancio</summary>
Sunset = 2
''' <summary>Toni grigi</summary>
Monochrome = 3
''' <summary>Personalizzato</summary>
Custom = 4
End Enum
''' <summary>
''' Stato corrente di una coda basato sul tempo di attesa
''' </summary>
Public Enum QueueStatus
''' <summary>Coda nella norma</summary>
Normal = 0
''' <summary>Coda in attenzione</summary>
Warning = 1
''' <summary>Coda critica</summary>
Critical = 2
''' <summary>Coda offline / non monitorata</summary>
Offline = 3
End Enum
' ═══════════════════════════════════════════════════════════
' MODELLO: CODA
' ═══════════════════════════════════════════════════════════
''' <summary>
''' Rappresenta una coda da monitorare con i suoi parametri
''' </summary>
Public Class QueueModel
Implements INotifyPropertyChanged
Private _id As String = Guid.NewGuid().ToString()
Private _name As String = "Nuova Coda"
Private _description As String = ""
Private _currentWaitTime As Double = 0 ' in minuti
Private _maxWaitTime As Double = 60 ' soglia massima (minuti)
Private _warningThreshold As Double = 30 ' soglia attenzione (minuti)
Private _criticalThreshold As Double = 45 ' soglia critica (minuti)
Private _isActive As Boolean = True
Private _lastUpdated As DateTime = DateTime.Now
Private _history As New List(Of WaitTimeEntry)()
''' <summary>ID univoco della coda</summary>
Public Property Id As String
Get
Return _id
End Get
Set(value As String)
_id = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(Id)))
End Set
End Property
''' <summary>Nome visualizzato della coda</summary>
Public Property Name As String
Get
Return _name
End Get
Set(value As String)
_name = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(Name)))
End Set
End Property
''' <summary>Descrizione opzionale della coda</summary>
Public Property Description As String
Get
Return _description
End Get
Set(value As String)
_description = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(Description)))
End Set
End Property
''' <summary>Tempo di attesa corrente in minuti</summary>
Public Property CurrentWaitTime As Double
Get
Return _currentWaitTime
End Get
Set(value As Double)
_currentWaitTime = Math.Max(0, value)
_lastUpdated = DateTime.Now
' Aggiunge alla storia
_history.Add(New WaitTimeEntry(_currentWaitTime))
' Mantieni solo le ultime 100 misurazioni
If _history.Count > 100 Then _history.RemoveAt(0)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(CurrentWaitTime)))
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(Status)))
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(PercentageFull)))
End Set
End Property
''' <summary>Tempo di attesa massimo configurato (minuti)</summary>
Public Property MaxWaitTime As Double
Get
Return _maxWaitTime
End Get
Set(value As Double)
_maxWaitTime = Math.Max(1, value)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(MaxWaitTime)))
End Set
End Property
''' <summary>Soglia attenzione in minuti</summary>
Public Property WarningThreshold As Double
Get
Return _warningThreshold
End Get
Set(value As Double)
_warningThreshold = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(WarningThreshold)))
End Set
End Property
''' <summary>Soglia critica in minuti</summary>
Public Property CriticalThreshold As Double
Get
Return _criticalThreshold
End Get
Set(value As Double)
_criticalThreshold = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(CriticalThreshold)))
End Set
End Property
''' <summary>Se la coda è attiva e monitorata</summary>
Public Property IsActive As Boolean
Get
Return _isActive
End Get
Set(value As Boolean)
_isActive = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(IsActive)))
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(Status)))
End Set
End Property
''' <summary>Data/ora dell'ultimo aggiornamento</summary>
Public Property LastUpdated As DateTime
Get
Return _lastUpdated
End Get
Set(value As DateTime)
_lastUpdated = value
End Set
End Property
''' <summary>Storico delle misurazioni</summary>
Public ReadOnly Property History As List(Of WaitTimeEntry)
Get
Return _history
End Get
End Property
''' <summary>Calcola lo stato corrente della coda</summary>
<JsonIgnore>
Public ReadOnly Property Status As QueueStatus
Get
If Not _isActive Then Return QueueStatus.Offline
If _currentWaitTime >= _criticalThreshold Then Return QueueStatus.Critical
If _currentWaitTime >= _warningThreshold Then Return QueueStatus.Warning
Return QueueStatus.Normal
End Get
End Property
''' <summary>Percentuale di riempimento (0-100) per il gauge</summary>
<JsonIgnore>
Public ReadOnly Property PercentageFull As Double
Get
If _maxWaitTime = 0 Then Return 0
Return Math.Min(100, (_currentWaitTime / _maxWaitTime) * 100)
End Get
End Property
''' <summary>Testo formattato del tempo di attesa</summary>
<JsonIgnore>
Public ReadOnly Property WaitTimeFormatted As String
Get
If _currentWaitTime < 1 Then Return "< 1 min"
If _currentWaitTime >= 60 Then
Dim ore = CInt(Math.Floor(_currentWaitTime / 60))
Dim min = CInt(_currentWaitTime Mod 60)
Return $"{ore}h {min:D2}m"
End If
Return $"{CInt(_currentWaitTime)} min"
End Get
End Property
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
End Class
' ═══════════════════════════════════════════════════════════
' MODELLO: ENTRY STORICO
' ═══════════════════════════════════════════════════════════
''' <summary>
''' Un'istanza di misurazione del tempo di attesa con timestamp
''' </summary>
Public Class WaitTimeEntry
Public Property Timestamp As DateTime
Public Property WaitTime As Double
Public Sub New(waitTime As Double)
Me.Timestamp = DateTime.Now
Me.WaitTime = waitTime
End Sub
Public Sub New()
End Sub
End Class
' ═══════════════════════════════════════════════════════════
' MODELLO: CONFIGURAZIONE GAUGE
' ═══════════════════════════════════════════════════════════
''' <summary>
''' Configurazione visiva di un singolo gauge
''' </summary>
Public Class GaugeConfig
''' <summary>ID della coda associata</summary>
Public Property QueueId As String = ""
''' <summary>Stile del gauge</summary>
Public Property Style As GaugeStyle = GaugeStyle.Arc270
''' <summary>Schema colori</summary>
Public Property ColorScheme As GaugeColorScheme = GaugeColorScheme.TrafficLight
''' <summary>Mostra etichette sul gauge</summary>
Public Property ShowLabels As Boolean = True
''' <summary>Mostra il valore numerico nel centro</summary>
Public Property ShowValue As Boolean = True
''' <summary>Mostra il nome della coda</summary>
Public Property ShowName As Boolean = True
''' <summary>Mostra animazione di transizione</summary>
Public Property AnimateTransitions As Boolean = True
''' <summary>Colore personalizzato normale (hex es. #00FF00)</summary>
Public Property CustomColorNormal As String = "#00C851"
''' <summary>Colore personalizzato attenzione</summary>
Public Property CustomColorWarning As String = "#FF8800"
''' <summary>Colore personalizzato critico</summary>
Public Property CustomColorCritical As String = "#FF4444"
''' <summary>Larghezza dell'arco in pixel</summary>
Public Property ArcWidth As Integer = 18
''' <summary>Mostra griglia di sfondo nel gauge bar</summary>
Public Property ShowGrid As Boolean = True
''' <summary>Posizione nella griglia dashboard (riga, colonna)</summary>
Public Property GridRow As Integer = 0
Public Property GridColumn As Integer = 0
End Class
' ═══════════════════════════════════════════════════════════
' MODELLO: CONFIGURAZIONE APPLICAZIONE
' ═══════════════════════════════════════════════════════════
''' <summary>
''' Configurazione globale dell'applicazione, persistita su file JSON
''' </summary>
Public Class AppConfig
''' <summary>Numero di colonne nella griglia dashboard</summary>
Public Property DashboardColumns As Integer = 3
''' <summary>Intervallo aggiornamento automatico in secondi (0 = disabilitato)</summary>
Public Property AutoRefreshSeconds As Integer = 30
''' <summary>Mostra la barra di stato</summary>
Public Property ShowStatusBar As Boolean = True
''' <summary>Tema scuro abilitato</summary>
Public Property DarkTheme As Boolean = True
''' <summary>Dimensione font del valore gauge</summary>
Public Property GaugeValueFontSize As Single = 18
''' <summary>Riproduce suono su allarme critico</summary>
Public Property SoundOnCritical As Boolean = False
''' <summary>Lista di tutte le code configurate</summary>
Public Property Queues As List(Of QueueModel) = New List(Of QueueModel)()
''' <summary>Configurazioni gauge per ogni coda</summary>
Public Property GaugeConfigs As Dictionary(Of String, GaugeConfig) = New Dictionary(Of String, GaugeConfig)()
''' <summary>Ottieni o crea la config gauge per una coda</summary>
Public Function GetGaugeConfig(queueId As String) As GaugeConfig
If Not GaugeConfigs.ContainsKey(queueId) Then
GaugeConfigs(queueId) = New GaugeConfig With {.QueueId = queueId}
End If
Return GaugeConfigs(queueId)
End Function
End Class
' ═══════════════════════════════════════════════════════════
' SERVIZIO: PERSISTENZA CONFIGURAZIONE
' ═══════════════════════════════════════════════════════════
''' <summary>
''' Gestisce il salvataggio e caricamento della configurazione su file JSON locale.
''' Nessuna connessione internet richiesta.
''' </summary>
Public Class ConfigService
Private Shared ReadOnly _configPath As String =
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"QueueMonitor",
"config.json")
Private Shared ReadOnly _jsonOptions As New JsonSerializerOptions With {
.WriteIndented = True,
.PropertyNamingPolicy = JsonNamingPolicy.CamelCase
}
''' <summary>
''' Carica la configurazione dal file. Se non esiste, restituisce una config di default con dati demo.
''' </summary>
Public Shared Function Load() As AppConfig
Try
If File.Exists(_configPath) Then
Dim json = File.ReadAllText(_configPath)
Dim config = JsonSerializer.Deserialize(Of AppConfig)(json, _jsonOptions)
Return If(config, CreateDefault())
End If
Catch ex As Exception
' In caso di file corrotto, usa default
End Try
Return CreateDefault()
End Function
''' <summary>
''' Salva la configurazione su file JSON
''' </summary>
Public Shared Sub Save(config As AppConfig)
Try
Dim dir = Path.GetDirectoryName(_configPath)
If Not Directory.Exists(dir) Then Directory.CreateDirectory(dir)
Dim json = JsonSerializer.Serialize(config, _jsonOptions)
File.WriteAllText(_configPath, json)
Catch ex As Exception
System.Windows.Forms.MessageBox.Show($"Errore salvataggio configurazione:{Environment.NewLine}{ex.Message}",
"Avviso", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning)
End Try
End Sub
''' <summary>
''' Crea una configurazione di default con code dimostrative
''' </summary>
Public Shared Function CreateDefault() As AppConfig
Dim config As New AppConfig()
' Code di esempio pre-caricate
Dim queues As New List(Of QueueModel) From {
New QueueModel With {
.Name = "Cassa Principale",
.Description = "Coda principale cassiere",
.CurrentWaitTime = 12,
.MaxWaitTime = 60,
.WarningThreshold = 20,
.CriticalThreshold = 40,
.IsActive = True
},
New QueueModel With {
.Name = "Sportello 1",
.Description = "Sportello informazioni",
.CurrentWaitTime = 35,
.MaxWaitTime = 60,
.WarningThreshold = 20,
.CriticalThreshold = 40,
.IsActive = True
},
New QueueModel With {
.Name = "Sportello 2",
.Description = "Sportello pagamenti",
.CurrentWaitTime = 5,
.MaxWaitTime = 60,
.WarningThreshold = 20,
.CriticalThreshold = 40,
.IsActive = True
},
New QueueModel With {
.Name = "Assistenza Tecnica",
.Description = "Help desk IT",
.CurrentWaitTime = 48,
.MaxWaitTime = 90,
.WarningThreshold = 30,
.CriticalThreshold = 60,
.IsActive = True
},
New QueueModel With {
.Name = "Prenotazioni",
.Description = "Coda prenotazioni online",
.CurrentWaitTime = 0,
.MaxWaitTime = 45,
.WarningThreshold = 15,
.CriticalThreshold = 30,
.IsActive = False
}
}
config.Queues = queues
' Gauge config di default per ogni coda
For i = 0 To queues.Count - 1
Dim q = queues(i)
config.GaugeConfigs(q.Id) = New GaugeConfig With {
.QueueId = q.Id,
.Style = If(i Mod 4 = 2, GaugeStyle.HorizontalBar,
If(i Mod 4 = 3, GaugeStyle.Semicircle, GaugeStyle.Arc270)),
.ColorScheme = CType(i Mod 4, GaugeColorScheme),
.ShowLabels = True,
.ShowValue = True,
.ShowName = True,
.AnimateTransitions = True,
.ArcWidth = 18,
.GridRow = i \ 3,
.GridColumn = i Mod 3
}
Next
Return config
End Function
''' <summary>Percorso file di configurazione</summary>
Public Shared ReadOnly Property ConfigFilePath As String
Get
Return _configPath
End Get
End Property
End Class
' ═══════════════════════════════════════════════════════════
' STATO GLOBALE APPLICAZIONE (Singleton)
' ═══════════════════════════════════════════════════════════
''' <summary>
''' Stato globale condiviso tra tutte le form dell'applicazione.
''' Pattern Singleton per accesso semplificato.
''' </summary>
Public Class AppState
Private Shared _instance As AppState
Public Shared ReadOnly Property Instance As AppState
Get
If _instance Is Nothing Then _instance = New AppState()
Return _instance
End Get
End Property
Public Property Config As AppConfig
Public Event DataChanged As EventHandler
Private Sub New()
' Assicurati che Config sia inizializzato anche se il servizio fallisce
Try
Config = ConfigService.Load()
Catch
Config = New AppConfig()
End Try
If Config Is Nothing Then Config = New AppConfig()
End Sub
Public Sub SaveAndNotify()
' ConfigService deve esistere ed essere un modulo o classe shared
ConfigService.Save(Config)
RaiseEvent DataChanged(Me, EventArgs.Empty)
End Sub
''' <summary>Otteniamo la lista senza LINQ per evitare errori di compilazione</summary>
Public ReadOnly Property ActiveQueues As IEnumerable(Of QueueModel)
Get
Dim activeList As New List(Of QueueModel)
If Config Is Nothing OrElse Config.Queues Is Nothing Then Return activeList
For Each q In Config.Queues
If q.IsActive Then
activeList.Add(q)
End If
Next
Return activeList
End Get
End Property
End Class
'End Namespace