From b0a4c47dd74bc41c5df3bab6ddd8de7bcc6a52b0 Mon Sep 17 00:00:00 2001
From: patrick <patrick.xu@broconcentric.com>
Date: 星期五, 06 十二月 2019 18:35:42 +0800
Subject: [PATCH] 1. 重新整理项目,按照A034模式,将设备异步操作修改为类同步操作。使用任务队列来存储和分配任务。

---
 src/Bro.Common.Model/Helper/ListHelper.cs |   58 +++++++++++++++++++++++++++-------------------------------
 1 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/src/Bro.Common.Model/Helper/ListHelper.cs b/src/Bro.Common.Model/Helper/ListHelper.cs
index ad17def..1331583 100644
--- a/src/Bro.Common.Model/Helper/ListHelper.cs
+++ b/src/Bro.Common.Model/Helper/ListHelper.cs
@@ -1,18 +1,17 @@
 锘縰sing System;
 using System.Collections.Generic;
+using System.Collections.Specialized;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Bro.Common.Helper
 {
     public class NoticedList<T> : List<T> where T : class
     {
-        public Action OnItemChanged;
+        public Action<NotifyCollectionChangedAction> OnItemChanged;
 
-        public Action<List<T>> OnItemChangedWithItemInfo;
+        public Action<NotifyCollectionChangedAction, List<T>> OnItemChangedWithItemInfo;
 
-        public Action<NoticedList<T>> OnItemChangedWithSelf;
+        //public Action<NotifyCollectionChangedAction, NoticedList<T>> OnItemChangedWithSelf;
 
         public new T this[int index]
         {
@@ -33,9 +32,8 @@
                 if (base[index] != value)
                 {
                     base[index] = value;
-                    OnItemChanged?.Invoke();
-                    OnItemChangedWithItemInfo?.Invoke(new List<T>() { value });
-                    OnItemChangedWithSelf?.Invoke(this);
+                    OnItemChanged?.Invoke(NotifyCollectionChangedAction.Replace);
+                    OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Replace, new List<T>() { value });
                 }
             }
         }
@@ -43,40 +41,36 @@
         public new void Add(T item)
         {
             base.Add(item);
-            OnItemChanged?.Invoke();
-            OnItemChangedWithItemInfo?.Invoke(new List<T>() { item });
-            OnItemChangedWithSelf?.Invoke(this);
+            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Add);
+            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Add, new List<T>() { item });
         }
 
         public new void AddRange(IEnumerable<T> collection)
         {
             base.AddRange(collection);
-            OnItemChanged?.Invoke();
-            OnItemChangedWithItemInfo?.Invoke(collection.ToList());
-            OnItemChangedWithSelf?.Invoke(this);
+            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Add);
+            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Add, collection.ToList());
         }
 
         public new void Clear()
         {
             base.Clear();
-            OnItemChanged?.Invoke();
-            OnItemChangedWithSelf?.Invoke(this);
+            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Reset);
+            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Reset, this);
         }
 
         public new void Insert(int index, T item)
         {
             base.Insert(index, item);
-            OnItemChanged?.Invoke();
-            OnItemChangedWithItemInfo?.Invoke(new List<T>() { item });
-            OnItemChangedWithSelf?.Invoke(this);
+            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Add);
+            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Add, new List<T>() { item });
         }
 
         public new void InsertRange(int index, IEnumerable<T> collection)
         {
             base.InsertRange(index, collection);
-            OnItemChanged?.Invoke();
-            OnItemChangedWithItemInfo?.Invoke(collection.ToList());
-            OnItemChangedWithSelf?.Invoke(this);
+            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Add);
+            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Add, collection.ToList());
         }
 
         public new bool Remove(T item)
@@ -85,9 +79,8 @@
 
             if (flag)
             {
-                OnItemChanged?.Invoke();
-                OnItemChangedWithItemInfo?.Invoke(new List<T>() { item });
-                OnItemChangedWithSelf?.Invoke(this);
+                OnItemChanged?.Invoke(NotifyCollectionChangedAction.Remove);
+                OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Remove, new List<T>() { item });
             }
 
             return flag;
@@ -95,11 +88,12 @@
 
         public new int RemoveAll(Predicate<T> match)
         {
+            List<T> temp = this.Where(u => match.Invoke(u)).ToList();
             int i = base.RemoveAll(match);
             if (i > 0)
             {
-                OnItemChanged?.Invoke();
-                OnItemChangedWithSelf?.Invoke(this);
+                OnItemChanged?.Invoke(NotifyCollectionChangedAction.Remove);
+                OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Remove, temp);
             }
 
             return i;
@@ -107,16 +101,18 @@
 
         public new void RemoveAt(int index)
         {
+            var item = this[index];
             base.RemoveAt(index);
-            OnItemChanged?.Invoke();
-            OnItemChangedWithSelf?.Invoke(this);
+            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Remove);
+            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Remove, new List<T>() { item });
         }
 
         public new void RemoveRange(int index, int count)
         {
+            List<T> temp = this.Skip(index).Take(count).ToList();
             base.RemoveRange(index, count);
-            OnItemChanged?.Invoke();
-            OnItemChangedWithSelf?.Invoke(this);
+            OnItemChanged?.Invoke(NotifyCollectionChangedAction.Remove);
+            OnItemChangedWithItemInfo?.Invoke(NotifyCollectionChangedAction.Remove, temp);
         }
     }
 }

--
Gitblit v1.8.0