using BPASmartClient.Compiler; 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 Microsoft.Win32; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace SCADA.Test { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow :Window { /// /// 控件集合 /// List Children = new List(); /// /// 接收消息集合 /// List eventReceiveMessages = new List(); FRedisClient fRedisClient = new FRedisClient(); public MainWindow() { InitializeComponent(); fRedisClient.Connect("124.222.238.75:16000,password=123456,defaultDatabase=1"); Dictionary sdsd= fRedisClient.GetKeys(); string _code = " public string main(string message) \n { \n //请在此填写你的代码\n\n return message; \n }\n"; string GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(_code,new object[] { "ERERERERE" }); xxnc.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList(); mlname.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList(); xx.ItemsSource = System.Enum.GetNames(typeof(RunEnum))?.ToList(); Class_InnerMessageBus.GetInstance().ListenMessage(this,MessageNameEnum.SendMessageName.ToString(),"MainWindowHandler"); } public void MainWindowHandler(object sender,InnerMessageEventArgs e) { try { if (e.obj_MessageObj is EventSendMessage)//接收到运行消息 { EventSendMessage mode = (EventSendMessage)e.obj_MessageObj; LogShowText(JsonConvert.SerializeObject(mode)); } } catch (Exception ex) { } } #region 加载数据 public void LogShowText(string str) { LogShow.Text += str + "\n"; } /// /// 加载数据 /// public void LoadingData(string path) { //加载控件 Children.Clear(); FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.ReadWrite); using (StreamReader sr = new StreamReader(fs,System.Text.Encoding.Unicode)) { while (sr.Peek() > -1) { string str = sr.ReadLine(); //if (!str.Contains("NewConveyorBelt")) { var ele = XamlReader.Parse(str) as FrameworkElement; Children.Add(ele); } } } if (Children.Count > 0) { eventReceiveMessages = runCanvas.Run(Children); } } #endregion private void Button_Click(object sender,RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "布局文件|*.lay"; if (ofd.ShowDialog() == true) { LoadingData(ofd.FileName); } } private void Button_Click_1(object sender,RoutedEventArgs e) { if (string.IsNullOrEmpty(mlname.Text)) { MessageBox.Show("消息名称不能为空!"); return; } if (string.IsNullOrEmpty(xx.Text)) { MessageBox.Show("命令不能为空!"); return; } RunEnumModel runEnumModel = new RunEnumModel(); runEnumModel.Run = ToEnumValue(xx.Text); runEnumModel.MessageID = hm.Text; Class_InnerMessageBus.GetInstance().PostMessage(this,mlname.Text,runEnumModel); } /// /// 根据枚举名称获取枚举值 /// public T ToEnumValue(string name) { return (T)Enum.Parse(typeof(T),name); } private void Button_Click_2(object sender,RoutedEventArgs e) { if (string.IsNullOrEmpty(xxnc.Text)) { MessageBox.Show("消息名称不能为空!"); return; } if (string.IsNullOrEmpty(ch.Text)) { MessageBox.Show("仓号不能为空!"); return; } if (string.IsNullOrEmpty(bt.Text)) { MessageBox.Show("标题不能为空!"); return; } if (string.IsNullOrEmpty(zl.Text)) { MessageBox.Show("重量不能为空!"); return; } SilosMessageModel silosMessage = new SilosMessageModel(); silosMessage.MessageID = ch.Text; silosMessage.Value = zl.Text; silosMessage.Title = bt.Text; silosMessage.Text = cgs.Text; Class_InnerMessageBus.GetInstance().PostMessage(this,xxnc.Text,silosMessage); } } }