Bladeren bron

added dbo in notifications filters; made hub connection tracker thread safe

tags/v0.1.0
Robin Thoni 7 jaren geleden
bovenliggende
commit
5057956940
2 gewijzigde bestanden met toevoegingen van 24 en 4 verwijderingen
  1. 12
    3
      Luticate2.Utils/Business/LuCrudBusiness.cs
  2. 12
    1
      Luticate2.Utils/Hubs/LuHubConnectionTracker.cs

+ 12
- 3
Luticate2.Utils/Business/LuCrudBusiness.cs Bestand weergeven

@@ -23,6 +23,12 @@ namespace Luticate2.Utils.Business
23 23
 
24 24
         protected virtual string EntityType { get; set; }
25 25
 
26
+        protected virtual Func<string, TDboRead, bool> NotifyCreateFilter { get; set; }
27
+
28
+        protected virtual Func<string, TDboRead, TDboRead, bool> NotifyUpdateFilter { get; set; }
29
+
30
+        protected virtual Func<string, TDboRead, bool> NotifyDeleteFilter { get; set; }
31
+
26 32
         protected LuCrudBusiness(TDataAccess dataAccess, LuNotificationsBusiness notificationsBusiness)
27 33
         {
28 34
             DataAccess = dataAccess;
@@ -87,7 +93,8 @@ namespace Luticate2.Utils.Business
87 93
             var newEntity = DataAccess.AddDbo(res.Data);
88 94
             if (newEntity)
89 95
             {
90
-                _notificationsBusiness.NotifyCreate(EntityType, newEntity.Data);
96
+                _notificationsBusiness.NotifyCreate(EntityType, newEntity.Data,
97
+                    s => NotifyCreateFilter(s, newEntity.Data));
91 98
                 return LuResult<T>.Ok(returnFunc(newEntity.Data));
92 99
             }
93 100
             return newEntity.To<T>();
@@ -153,7 +160,8 @@ namespace Luticate2.Utils.Business
153 160
             var editedEntity = DataAccess.EditSingleByIdDbo(id, obj.Data);
154 161
             if (editedEntity)
155 162
             {
156
-                _notificationsBusiness.NotifyUpdate(EntityType, originalEntity.Data, editedEntity.Data);
163
+                _notificationsBusiness.NotifyUpdate(EntityType, originalEntity.Data, editedEntity.Data,
164
+                    s => NotifyUpdateFilter(s, originalEntity.Data, editedEntity.Data));
157 165
                 return LuResult<T>.Ok(returnFunc(editedEntity.Data));
158 166
             }
159 167
             return editedEntity.To<T>();
@@ -182,7 +190,8 @@ namespace Luticate2.Utils.Business
182 190
             var res = DataAccess.DeleteSingleById(id, returnFunc);
183 191
             if (res)
184 192
             {
185
-                _notificationsBusiness.NotifyDelete(EntityType, originalEntity.Data);
193
+                _notificationsBusiness.NotifyDelete(EntityType, originalEntity.Data,
194
+                    s => NotifyDeleteFilter(s, originalEntity.Data));
186 195
             }
187 196
             return res;
188 197
         }

+ 12
- 1
Luticate2.Utils/Hubs/LuHubConnectionTracker.cs Bestand weergeven

@@ -1,5 +1,6 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3
+using System.Threading;
3 4
 
4 5
 namespace Luticate2.Utils.Hubs
5 6
 {
@@ -7,8 +8,11 @@ namespace Luticate2.Utils.Hubs
7 8
     {
8 9
         protected IDictionary<string, IList<string>> ConnectionIds { get; set; }
9 10
 
11
+        protected Mutex Mutex;
12
+
10 13
         public LuHubConnectionTracker()
11 14
         {
15
+            Mutex = new Mutex();
12 16
             ConnectionIds = new Dictionary<string, IList<string>>();
13 17
         }
14 18
 
@@ -21,7 +25,9 @@ namespace Luticate2.Utils.Hubs
21 25
 
22 26
         public void Add(string name, string id)
23 27
         {
28
+            Mutex.WaitOne();
24 29
             GetReal(name).Add(id);
30
+            Mutex.ReleaseMutex();
25 31
         }
26 32
 
27 33
         public void Add(Type type, string id)
@@ -43,7 +49,9 @@ namespace Luticate2.Utils.Hubs
43 49
 
44 50
         public void Remove(string name, string id)
45 51
         {
52
+            Mutex.WaitOne();
46 53
             GetReal(name).Remove(id);
54
+            Mutex.ReleaseMutex();
47 55
         }
48 56
 
49 57
         public void Remove(Type type, string id)
@@ -74,7 +82,10 @@ namespace Luticate2.Utils.Hubs
74 82
 
75 83
         public IList<string> Get(string name)
76 84
         {
77
-            return new List<string>(GetReal(name));
85
+            Mutex.WaitOne();
86
+            var copy = new List<string>(GetReal(name));
87
+            Mutex.ReleaseMutex();
88
+            return copy;
78 89
         }
79 90
 
80 91
         public IList<string> Get(Type type)

Laden…
Annuleren
Opslaan