123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Configuration;
- 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.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Xml.Linq;
- namespace EapClientSimulator
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- lp1.OnSendMessage += Lp1_OnSendMessage;
- lp2.OnSendMessage += Lp2_OnSendMessage;
- lp3.OnSendMessage += Lp3_OnSendMessage;
- ureport.OnSendMessage += Ureport_OnSendMessage;
- ueventReport.OnSendMessage += UeventReport_OnSendMessage;
- uevent.OnSendMessage += Uevent_OnSendMessage;
- ualarm.OnSendMessage += Ualarm_OnSendMessage;
- ustatus.OnSendMessage += Ustatus_OnSendMessage;
- }
- private void Ustatus_OnSendMessage(object sender, string e)
- {
- ShowMessage(e);
- }
- private void Ualarm_OnSendMessage(object sender, string e)
- {
- ShowMessage(e);
- }
- private void Uevent_OnSendMessage(object sender, string e)
- {
- ShowMessage(e);
- }
- private void UeventReport_OnSendMessage(object sender, string e)
- {
- ShowMessage(e);
- }
- private void Ureport_OnSendMessage(object sender, string e)
- {
- ShowMessage(e);
- }
- private void Lp3_OnSendMessage(object sender, string e)
- {
- ShowMessage(e);
- }
- private void Lp2_OnSendMessage(object sender, string e)
- {
- ShowMessage(e);
- }
- private void Lp1_OnSendMessage(object sender, string e)
- {
- ShowMessage(e);
- }
- private void btnConnect_Click(object sender, RoutedEventArgs e)
- {
- if(GlobalData.Client==null)
- {
- GlobalData.Client = new EapClient();
- GlobalData.Client.OnDisConnected += Client_OnDisConnected;
- GlobalData.Client.OnReceiveData += Client_OnReceiveData;
- }
- if(GlobalData.Client.Connect(txtIp.Text,int.Parse(txtPort.Text)))
- {
- btnConnect.IsEnabled = false;
- btnDisConnect.IsEnabled = true;
- gp1.IsEnabled = true;
- gp2.IsEnabled = true;
- gp3.IsEnabled = true;
- gp4.IsEnabled = true;
- gp5.IsEnabled = true;
- gp6.IsEnabled = true;
- gp7.IsEnabled = true;
- gp8.IsEnabled = true;
- gp10.IsEnabled = true;
- lstReceivedData.Items.Clear();
- }
- else
- {
- MessageBox.Show($"connect failed {txtIp.Text}:{txtPort.Text}");
- }
- }
- private void Client_OnReceiveData(object sender, string e)
- {
- ShowMessage(e);
- }
- private object locker = new object();
- private void ShowMessage(string msg)
- {
- string content = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff ") + msg;
- lock (locker)
- {
- try
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- if (lstReceivedData.Items.Count >= 1000)
- {
- lstReceivedData.Items.Clear();
- }
- lstReceivedData.Items.Insert(0,content);
- lstReceivedData.SelectedIndex = 0;
- //if (lstReceivedData.Items.Count >= 2)
- //{
- //lstReceivedData.ScrollIntoView(lstReceivedData.Items[lstReceivedData.Items.Count - 2]);
- //}
- }));
- }
- catch
- {
- }
- }
- }
- private void Client_OnDisConnected(object sender, string e)
- {
- try
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- btnDisConnect.IsEnabled = false;
- btnConnect.IsEnabled = true;
- gp1.IsEnabled = false;
- gp2.IsEnabled = false;
- gp3.IsEnabled = false;
- gp4.IsEnabled = false;
- gp5.IsEnabled = false;
- gp6.IsEnabled = false;
- gp7.IsEnabled = false;
- gp8.IsEnabled= false;
- gp10.IsEnabled = false;
- }));
- }
- catch
- {
- }
- }
- private void btnDisConnect_Click(object sender, RoutedEventArgs e)
- {
- GlobalData.Client.Close();
- btnDisConnect.IsEnabled = false;
- btnConnect.IsEnabled = true;
- }
- }
- }
|