Browse Source

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

tags/v0.1.0
Robin Thoni 7 years ago
parent
commit
5057956940

+ 12
- 3
Luticate2.Utils/Business/LuCrudBusiness.cs View File

23
 
23
 
24
         protected virtual string EntityType { get; set; }
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
         protected LuCrudBusiness(TDataAccess dataAccess, LuNotificationsBusiness notificationsBusiness)
32
         protected LuCrudBusiness(TDataAccess dataAccess, LuNotificationsBusiness notificationsBusiness)
27
         {
33
         {
28
             DataAccess = dataAccess;
34
             DataAccess = dataAccess;
87
             var newEntity = DataAccess.AddDbo(res.Data);
93
             var newEntity = DataAccess.AddDbo(res.Data);
88
             if (newEntity)
94
             if (newEntity)
89
             {
95
             {
90
-                _notificationsBusiness.NotifyCreate(EntityType, newEntity.Data);
96
+                _notificationsBusiness.NotifyCreate(EntityType, newEntity.Data,
97
+                    s => NotifyCreateFilter(s, newEntity.Data));
91
                 return LuResult<T>.Ok(returnFunc(newEntity.Data));
98
                 return LuResult<T>.Ok(returnFunc(newEntity.Data));
92
             }
99
             }
93
             return newEntity.To<T>();
100
             return newEntity.To<T>();
153
             var editedEntity = DataAccess.EditSingleByIdDbo(id, obj.Data);
160
             var editedEntity = DataAccess.EditSingleByIdDbo(id, obj.Data);
154
             if (editedEntity)
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
                 return LuResult<T>.Ok(returnFunc(editedEntity.Data));
165
                 return LuResult<T>.Ok(returnFunc(editedEntity.Data));
158
             }
166
             }
159
             return editedEntity.To<T>();
167
             return editedEntity.To<T>();
182
             var res = DataAccess.DeleteSingleById(id, returnFunc);
190
             var res = DataAccess.DeleteSingleById(id, returnFunc);
183
             if (res)
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
             return res;
196
             return res;
188
         }
197
         }

+ 12
- 1
Luticate2.Utils/Hubs/LuHubConnectionTracker.cs View File

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

Loading…
Cancel
Save