Browse Source

Merge remote-tracking branch 'origin/frank' into kenric

Kenric Nugteren 1 năm trước cách đây
mục cha
commit
27345c0d3a

+ 21 - 0
InABox.Database/Stores/Store.cs

@@ -3,6 +3,7 @@ using System.Reflection;
 using System.Text.RegularExpressions;
 using InABox.Configuration;
 using InABox.Core;
+using NPOI.OpenXmlFormats.Dml;
 using NPOI.POIFS.FileSystem;
 
 namespace InABox.Database
@@ -466,6 +467,7 @@ namespace InABox.Database
             AfterSave(entity);
 
             entity = RunScript(ScriptType.AfterSave, new[] { entity }).First();
+            NotifyListeners([entity]);
         }
 
         protected void AuditTrail(IEnumerable<Entity> entities, IEnumerable<string> notes)
@@ -594,6 +596,8 @@ namespace InABox.Database
             }
 
             entities = RunScript(ScriptType.AfterSave, entities);
+            
+            NotifyListeners(entities);
 
             //}
             //catch (Exception e)
@@ -602,6 +606,19 @@ namespace InABox.Database
             //}
         }
 
+        private static List<Tuple<Type, Action<Guid[]>>> _listeners = new List<Tuple<Type, Action<Guid[]>>>();
+
+        public static void RegisterListener<TType>(Action<Guid[]> listener)
+            => _listeners.Add(new Tuple<Type, Action<Guid[]>>(typeof(TType), listener));
+
+        private void NotifyListeners(IEnumerable<T> items)
+        {
+            var ids = items.Select(x => x.ID).ToArray();
+            foreach (var listener in _listeners.Where(x => x.Item1 == typeof(T)))
+                listener.Item2(ids);
+            
+        }
+        
         #endregion
 
         #region Delete Functions
@@ -641,6 +658,8 @@ namespace InABox.Database
                 AfterDelete(entity);
 
                 entity = RunScript(ScriptType.AfterDelete, new[] { entity }).First();
+                
+                NotifyListeners([entity]);
             }
             catch (Exception e)
             {
@@ -671,6 +690,8 @@ namespace InABox.Database
                 foreach (var entity in entities) AfterDelete(entity);
 
                 entities = RunScript(ScriptType.AfterDelete, entities);
+                
+                NotifyListeners(entities);
             }
             catch (Exception e)
             {

+ 5 - 0
inabox.wpf/Converters/BooleanToGridLengthConverter.cs

@@ -0,0 +1,5 @@
+using System.Windows;
+
+namespace InABox.WPF;
+
+public class BooleanToGridLengthConverter : BooleanConverter<GridLength> { }