diff --git a/BPASmartClient.MessageName/MessageName.cs b/BPASmartClient.MessageName/MessageName.cs index 6e79e11b..eddffd36 100644 --- a/BPASmartClient.MessageName/MessageName.cs +++ b/BPASmartClient.MessageName/MessageName.cs @@ -73,6 +73,14 @@ namespace BPASmartClient.MessageName /// ConveyorBeltRunStatus, + /// + /// 发送消息 + /// + SendMessageName, + /// + /// 接收消息 + /// + ReceiveMessageName, } /// diff --git a/BPASmartClient.MessageName/发送消息Model/EventSendMessage.cs b/BPASmartClient.MessageName/发送消息Model/EventSendMessage.cs index 1c2804cb..c8c79222 100644 --- a/BPASmartClient.MessageName/发送消息Model/EventSendMessage.cs +++ b/BPASmartClient.MessageName/发送消息Model/EventSendMessage.cs @@ -18,7 +18,7 @@ namespace BPASmartClient.MessageName.发送消息Model /// /// 控件名称 /// - public object ControlName { get; set; } + public string ControlName { get; set; } /// /// 控件标题 /// diff --git a/BPASmartClient.MessageName/接收消息Model/EventReceiveMessage.cs b/BPASmartClient.MessageName/接收消息Model/EventReceiveMessage.cs index 498a2d39..162ded4f 100644 --- a/BPASmartClient.MessageName/接收消息Model/EventReceiveMessage.cs +++ b/BPASmartClient.MessageName/接收消息Model/EventReceiveMessage.cs @@ -9,8 +9,16 @@ namespace BPASmartClient.MessageName.接收消息Model /// /// 事件消息[接收端]Model:配置 /// - public class EventReceiveMessage: MessageBase + public class EventReceiveMessage:MessageBase { + ///// + ///// 消息号 + ///// + //public string MeaageID { get; set; } + //// + ///// 消息名称:枚举 + ///// + //public MessageNameEnum MeaageName { get; set; } /// /// 空:保留 /// @@ -19,5 +27,9 @@ namespace BPASmartClient.MessageName.接收消息Model /// 消息标题:标志控件说明 /// public string Title { get; set; } + //public EventReceiveMessage() + //{ + // MeaageID = GetMessageID.GetID(); + //} } } diff --git a/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs b/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs index 137f84d0..70370f48 100644 --- a/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs +++ b/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs @@ -3,6 +3,7 @@ using BPASmartClient.MessageCommunication; using BPASmartClient.MessageCommunication.MsgControl; using BPASmartClient.MessageName; using BPASmartClient.MessageName.EnumHelp; +using BPASmartClient.MessageName.发送消息Model; using BPASmartClient.MessageName.接收消息Model; using BPASmartClient.MessageName.接收消息Model.滚动线; using Newtonsoft.Json; @@ -57,6 +58,8 @@ namespace BPASmartClient.SCADAControl private void NewConveyorBelt_Loaded(object sender, RoutedEventArgs e) { + EventReceiveNameList.CollectionChanged += EventNameList_CollectionChanged; + EventSendNameList.CollectionChanged += EventSendNameList_CollectionChanged; foreach (TextBlock tb in FindVisualChildren(this)) { // do something with tb here @@ -68,16 +71,28 @@ namespace BPASmartClient.SCADAControl } } } - EventNameList.CollectionChanged += EventNameList_CollectionChanged; } + private void EventSendNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + if (EventSendNameList.Count > 0) + { + try + { + EventSendNameListStr = JsonConvert.SerializeObject(EventSendNameList); + } + catch (Exception ex) + { + } + } + } private void EventNameList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { - if (EventNameList.Count > 0) + if (EventReceiveNameList.Count > 0) { try { - EventNameListStr = JsonConvert.SerializeObject(EventNameList); + EventReceiveNameListStr = JsonConvert.SerializeObject(EventReceiveNameList); } catch (Exception ex) @@ -310,44 +325,72 @@ namespace BPASmartClient.SCADAControl } public static readonly DependencyProperty ConveyorBeltStopProperty = DependencyProperty.Register("ConveyorBeltStop", typeof(string), typeof(NewConveyorBelt), new PropertyMetadata(string.Empty)); - [Category("消息名称")] - public string EventNameListStr + [Category("名称[自动生成]")] + public string EventReceiveNameListStr { - get { return (string)GetValue(EventNameListStrProperty); } - set { SetValue(EventNameListStrProperty, value); } + get { return (string)GetValue(EventReceiveNameListStrProperty); } + set { SetValue(EventReceiveNameListStrProperty, value); } } - public static readonly DependencyProperty EventNameListStrProperty = - DependencyProperty.Register("EventNameListStr", typeof(string), typeof(NewConveyorBelt), new PropertyMetadata(string.Empty)); - [Category("消息名称集合")] - public ObservableCollection EventNameList + public static readonly DependencyProperty EventReceiveNameListStrProperty = + DependencyProperty.Register("EventReceiveNameListStr", typeof(string), typeof(NewConveyorBelt), new PropertyMetadata(string.Empty)); + [Category("消息接收名称集合")] + public ObservableCollection EventReceiveNameList { - get { return (ObservableCollection)GetValue(EventNameListProperty); } - set { SetValue(EventNameListProperty, value); } + get { return (ObservableCollection)GetValue(EventReceiveNameListProperty); } + set { SetValue(EventReceiveNameListProperty, value); } } - public static readonly DependencyProperty EventNameListProperty = - DependencyProperty.Register("EventNameList", typeof(ObservableCollection), typeof(NewConveyorBelt), new PropertyMetadata(new ObservableCollection(), onEventNameListChanged)); + public static readonly DependencyProperty EventReceiveNameListProperty = + DependencyProperty.Register("EventReceiveNameList", typeof(ObservableCollection), typeof(NewConveyorBelt), new PropertyMetadata(new ObservableCollection(), onEventNameListChanged)); private static void onEventNameListChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as NewConveyorBelt)?.RunNameRefresh(); + [Category("名称[自动生成]")] + public string EventSendNameListStr + { + get { return (string)GetValue(EventSendNameListStrProperty); } + set { SetValue(EventSendNameListStrProperty,value); } + } + public static readonly DependencyProperty EventSendNameListStrProperty = + DependencyProperty.Register("EventSendNameListStr",typeof(string),typeof(NewConveyorBelt),new PropertyMetadata(string.Empty)); + [Category("消息发送名称集合")] + public ObservableCollection EventSendNameList + { + get { return (ObservableCollection)GetValue(EventSendNameListProperty); } + set { SetValue(EventSendNameListProperty,value); } + } + public static readonly DependencyProperty EventSendNameListProperty = + DependencyProperty.Register("EventSendNameList",typeof(ObservableCollection),typeof(NewConveyorBelt),new PropertyMetadata(new ObservableCollection(),new PropertyChangedCallback(onEventNameListChanged))); + #endregion #region 属性变更事件 public void Register() { - if (!string.IsNullOrEmpty(EventNameListStr)) + if (!string.IsNullOrEmpty(EventReceiveNameListStr)) + { + try + { + EventReceiveNameList = JsonConvert.DeserializeObject>(EventReceiveNameListStr); + } + catch (Exception ex) + { + + } + } + if (!string.IsNullOrEmpty(EventSendNameListStr)) { try { - EventNameList = JsonConvert.DeserializeObject>(EventNameListStr); + EventSendNameList = JsonConvert.DeserializeObject>(EventSendNameListStr); } catch (Exception ex) { } } - if (EventNameList != null) + if (EventReceiveNameList != null) { - EventNameList?.ToList().ForEach(x => + EventReceiveNameList?.ToList().ForEach(x => { - Class_InnerMessageBus.GetInstance().ListenMessage(this, x.MeaageName.ToString(), "EventHandler"); + Class_InnerMessageBus.GetInstance().ListenMessage(this,x.MeaageName.ToString(),"EventHandler"); }); } } @@ -361,7 +404,7 @@ namespace BPASmartClient.SCADAControl if (e.obj_MessageObj is RunEnumModel)//接收到运行消息 { RunEnumModel mode = (RunEnumModel)e.obj_MessageObj; - var msg = EventNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID); + var msg = EventReceiveNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID); //必对消息号: if (msg != null) { @@ -371,7 +414,7 @@ namespace BPASmartClient.SCADAControl else if (e.obj_MessageObj is ConveyorBeltMessageModel)//接收到数据模型 { ConveyorBeltMessageModel mode = (ConveyorBeltMessageModel)e.obj_MessageObj; - var msg = EventNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID); + var msg = EventReceiveNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID); //必对消息号: if (msg != null) { diff --git a/BPASmartClient.SCADAControl/Silos.xaml.cs b/BPASmartClient.SCADAControl/Silos.xaml.cs index 216463e2..9c511d99 100644 --- a/BPASmartClient.SCADAControl/Silos.xaml.cs +++ b/BPASmartClient.SCADAControl/Silos.xaml.cs @@ -60,9 +60,9 @@ namespace BPASmartClient.SCADAControl private void Silos_Loaded(object sender, RoutedEventArgs e) { - Loading(); - EventNameList.CollectionChanged += EventNameList_CollectionChanged; + EventReceiveNameList.CollectionChanged += EventNameList_CollectionChanged; EventSendNameList.CollectionChanged += EventSendNameList_CollectionChanged; + Loading(); } private void EventSendNameList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) @@ -79,14 +79,13 @@ namespace BPASmartClient.SCADAControl } } } - private void EventNameList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { - if (EventNameList.Count > 0) + if (EventReceiveNameList.Count > 0) { try { - EventNameListStr = JsonConvert.SerializeObject(EventNameList); + EventReceiveNameListStr = JsonConvert.SerializeObject(EventReceiveNameList); } catch (Exception ex) @@ -114,10 +113,8 @@ namespace BPASmartClient.SCADAControl #region 动画 /// - /// 字节改变 + /// 加载内部变量 /// - /// - /// public void Loading() { //查找 @@ -201,7 +198,6 @@ namespace BPASmartClient.SCADAControl storyboard.Children.Add(animation); } - public static IEnumerable FindVisualChildren(DependencyObject depObj) where T : DependencyObject { if (depObj != null) @@ -253,33 +249,29 @@ namespace BPASmartClient.SCADAControl DependencyProperty.Register("Title", typeof(string), typeof(Silos), new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); [Category("名称[自动生成]")] - private string EventNameListStr + public string EventReceiveNameListStr { - get { return (string)GetValue(EventNameListStrProperty); } - set { SetValue(EventNameListStrProperty, value); } + get { return (string)GetValue(EventReceiveNameListStrProperty); } + set { SetValue(EventReceiveNameListStrProperty, value); } } - private static readonly DependencyProperty EventNameListStrProperty = - DependencyProperty.Register("EventNameListStr", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty)); - + public static readonly DependencyProperty EventReceiveNameListStrProperty = + DependencyProperty.Register("EventReceiveNameListStr", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty)); [Category("消息接收名称集合")] - public ObservableCollection EventNameList + public ObservableCollection EventReceiveNameList { - get { return (ObservableCollection)GetValue(EventNameListProperty); } - set { SetValue(EventNameListProperty, value); } + get { return (ObservableCollection)GetValue(EventReceiveNameListProperty); } + set { SetValue(EventReceiveNameListProperty, value); } } - public static readonly DependencyProperty EventNameListProperty = - DependencyProperty.Register("EventNameList", typeof(ObservableCollection), typeof(Silos), new PropertyMetadata(new ObservableCollection(), new PropertyChangedCallback(onEventNameListChanged))); - private static void onEventNameListChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as Silos)?.DataNameRefresh(); - + public static readonly DependencyProperty EventReceiveNameListProperty = + DependencyProperty.Register("EventReceiveNameList", typeof(ObservableCollection), typeof(Silos), new PropertyMetadata(new ObservableCollection(), new PropertyChangedCallback(onEventNameListChanged))); [Category("名称[自动生成]")] - private string EventSendNameListStr + public string EventSendNameListStr { get { return (string)GetValue(EventSendNameListStrProperty); } set { SetValue(EventSendNameListStrProperty, value); } } - private static readonly DependencyProperty EventSendNameListStrProperty = + public static readonly DependencyProperty EventSendNameListStrProperty = DependencyProperty.Register("EventSendNameListStr", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty)); - [Category("消息发送名称集合")] public ObservableCollection EventSendNameList { @@ -288,6 +280,7 @@ namespace BPASmartClient.SCADAControl } public static readonly DependencyProperty EventSendNameListProperty = DependencyProperty.Register("EventSendNameList", typeof(ObservableCollection), typeof(Silos), new PropertyMetadata(new ObservableCollection(), new PropertyChangedCallback(onEventNameListChanged))); + private static void onEventNameListChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.DataNameRefresh(); [Category("值设定")] public int Direction @@ -302,6 +295,7 @@ namespace BPASmartClient.SCADAControl { (d as Silos)?.Refresh(); } + #endregion #region 函数 @@ -367,25 +361,17 @@ namespace BPASmartClient.SCADAControl #region 运行事件 public void Register() { - if (!string.IsNullOrEmpty(EventNameListStr)) + if (!string.IsNullOrEmpty(EventReceiveNameListStr)) { try { - EventNameList = JsonConvert.DeserializeObject>(EventNameListStr); + EventReceiveNameList = JsonConvert.DeserializeObject>(EventReceiveNameListStr); } catch (Exception ex) { } } - if (EventNameList != null) - { - EventNameList?.ToList().ForEach(x => - { - Class_InnerMessageBus.GetInstance().ListenMessage(this, x.MeaageName.ToString(), "EventHandler"); - }); - } - if (!string.IsNullOrEmpty(EventSendNameListStr)) { try @@ -397,6 +383,10 @@ namespace BPASmartClient.SCADAControl } } + EventReceiveNameList?.ToList().ForEach(x => + { + Class_InnerMessageBus.GetInstance().ListenMessage(this,x.MeaageName.ToString(),"EventHandler"); + }); } /// /// 统一事件消息处理中心 @@ -412,7 +402,7 @@ namespace BPASmartClient.SCADAControl if (e.obj_MessageObj is RunEnumModel)//接收到运行消息 { RunEnumModel mode = (RunEnumModel)e.obj_MessageObj; - var msg = EventNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID); + var msg = EventReceiveNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID); //必对消息号: if (msg!=null) { @@ -421,7 +411,7 @@ namespace BPASmartClient.SCADAControl }else if (e.obj_MessageObj is SilosMessageModel)//接收到数据模型 { SilosMessageModel mode = (SilosMessageModel)e.obj_MessageObj; - var msg = EventNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID); + var msg = EventReceiveNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID); //必对消息号: if (msg != null) { diff --git a/SCADA.Test/RunCanvas.xaml.cs b/SCADA.Test/RunCanvas.xaml.cs index f3501b62..13cfa5cb 100644 --- a/SCADA.Test/RunCanvas.xaml.cs +++ b/SCADA.Test/RunCanvas.xaml.cs @@ -48,10 +48,10 @@ namespace SCADA.Test RootCanvas.Children.Clear(); foreach (FrameworkElement element in canvas) { - if (element.GetType().GetInterface("IExecutable") != null) - { - element.GetType().GetProperty("IsExecuteState").SetValue(element, true); - } + //if (element.GetType().GetInterface("IExecutable") != null) + //{ + // element.GetType().GetProperty("IsExecuteState").SetValue(element, true); + //} if (element is IExecutable executable) {