11using cAlgo . API . Alert . Models ;
22using cAlgo . API . Alert . UI . Models ;
33using LiteDB ;
4+ using System ;
45using System . Collections . Generic ;
56using System . IO ;
67using System . Linq ;
@@ -21,16 +22,17 @@ public static IEnumerable<AlertModel> GetAlerts()
2122
2223 using ( var eventWaitHandle = GetWaitHandle ( ) )
2324 {
24- eventWaitHandle . WaitOne ( ) ;
25-
26- using ( LiteDatabase database = new LiteDatabase ( GetConnectionString ( ) ) )
25+ if ( eventWaitHandle . WaitOne ( TimeSpan . FromMinutes ( 1 ) ) )
2726 {
28- var collection = database . GetCollection < AlertModel > ( ) ;
27+ using ( LiteDatabase database = new LiteDatabase ( GetConnectionString ( ) ) )
28+ {
29+ var collection = database . GetCollection < AlertModel > ( ) ;
2930
30- result = collection . FindAll ( ) . ToList ( ) ;
31- }
31+ result = collection . FindAll ( ) . ToList ( ) ;
32+ }
3233
33- eventWaitHandle . Set ( ) ;
34+ eventWaitHandle . Set ( ) ;
35+ }
3436 }
3537
3638 return result ;
@@ -40,33 +42,35 @@ public static void AddAlerts(params AlertModel[] alerts)
4042 {
4143 using ( var eventWaitHandle = GetWaitHandle ( ) )
4244 {
43- eventWaitHandle . WaitOne ( ) ;
44-
45- using ( LiteDatabase database = new LiteDatabase ( GetConnectionString ( ) ) )
45+ if ( eventWaitHandle . WaitOne ( TimeSpan . FromMinutes ( 1 ) ) )
4646 {
47- var collection = database . GetCollection < AlertModel > ( ) ;
47+ using ( LiteDatabase database = new LiteDatabase ( GetConnectionString ( ) ) )
48+ {
49+ var collection = database . GetCollection < AlertModel > ( ) ;
4850
49- collection . InsertBulk ( alerts ) ;
50- }
51+ collection . InsertBulk ( alerts ) ;
52+ }
5153
52- eventWaitHandle . Set ( ) ;
54+ eventWaitHandle . Set ( ) ;
55+ }
5356 }
5457 }
5558
5659 public static void RemoveAlerts ( params AlertModel [ ] alerts )
5760 {
5861 using ( var eventWaitHandle = GetWaitHandle ( ) )
5962 {
60- eventWaitHandle . WaitOne ( ) ;
61-
62- using ( LiteDatabase database = new LiteDatabase ( GetConnectionString ( ) ) )
63+ if ( eventWaitHandle . WaitOne ( TimeSpan . FromMinutes ( 1 ) ) )
6364 {
64- var collection = database . GetCollection < AlertModel > ( ) ;
65+ using ( LiteDatabase database = new LiteDatabase ( GetConnectionString ( ) ) )
66+ {
67+ var collection = database . GetCollection < AlertModel > ( ) ;
6568
66- collection . DeleteMany ( iAlert => alerts . Contains ( iAlert ) ) ;
67- }
69+ collection . DeleteMany ( iAlert => alerts . Contains ( iAlert ) ) ;
70+ }
6871
69- eventWaitHandle . Set ( ) ;
72+ eventWaitHandle . Set ( ) ;
73+ }
7074 }
7175 }
7276
0 commit comments