using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Windows.Forms; //using DQ.Construction.NewLook.Utility; using WorkData; using WorkData.Entity; #region 文件说明 /*----------------------------------------------------- * 版权所有 (c) 2024 jdfcd * CLR版本 4.0.30319.42000 * 命名空间 DQ.Construction.NewLook.DataManager * * 创建者:pnpe * 电子邮件:pnpe@qq.com * 创建时间:2024/6/19 12:01:26 */ #endregion 文件说明 namespace WellWorkDataUI { /// /// The k e p data manager. /// public static class KEPDataManager { // 使用字典来存储不同类型的事件 private static Dictionary> subscriptions = new Dictionary>(); /// /// 基础 /// /// /// /// /// private static void Subscribe(string name, Action callback, bool loadCallBack = false) where T : class { string pageUniqueValue = name; var type = typeof(T); if (!subscriptions.ContainsKey(type)) { subscriptions[type] = new Dictionary(); } if (!subscriptions[type].ContainsKey(pageUniqueValue)) { subscriptions[type].Add(pageUniqueValue, callback); } else { subscriptions[type][pageUniqueValue] = callback; } if (loadCallBack) { NotifyChange(); } } public static void Subscribe(this Form form, Action callback, bool loadCallBack = false) where T : class { Subscribe(form.Name, callback, loadCallBack); } /// /// 订阅方法 /// /// The page unique value. /// The callback. /// If true, load call back. //public static void Subscribe(this CustomUserControl customUserControl, Action callback, bool loadCallBack = false) // where T : class //{ // Subscribe(customUserControl.Name, callback, loadCallBack); //} ///// ///// 订阅方法 ///// ///// The page unique value. //public static void UnSubscribe(this CustomUserControl customUserControl) // where T : class //{ // string pageUniqueValue = customUserControl.Name; // var type = typeof(T); // if (!subscriptions.ContainsKey(type)) // { // subscriptions[type] = new Dictionary(); // } // if (subscriptions[type].ContainsKey(pageUniqueValue)) // { // subscriptions[type].Remove(pageUniqueValue); // } //} // 触发事件的方法 /// /// Ons the data changed. /// /// The t. public static void NotifyChange() where T : class { Task.Run(() => { var type = typeof(T); if (subscriptions.ContainsKey(type)) { foreach (var subscription in subscriptions[type].Values) { try { subscription?.Invoke(); } catch (Exception ex) { //Log Reporter.WriteMsg($"数据管理推送数据:" + ex.Message); } } } if (type == typeof(WellDeflection)) { //清理井斜相关缓存 CalcDataHelp.Reset(); } }); } } }