alielie
2025-04-10 6bcafc823e836ecd5790f87178a906333699f868
HMI.UnitTest/MainWindow.xaml.cs
@@ -1,18 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConnectionUtil;
using HMI.Core.Api;
using HMI.Core.Util;
using Plugin.TestResult_WPF;
using System;
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 HMI.SettingControl;
namespace UnitTest
{
@@ -23,9 +14,121 @@
    {
        public MainWindow()
        {
            LangUtil.Load();
            InitializeComponent();
            page.Children.Clear();
            page.Children.Add(new SettingControl());
            //page.Children.Add(new UserControl1());
        }
        TcpClientWrapper tcpClient;
        PipeClient2 client;
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //client = new PipeClient2("DAService");
            ////client.OnData += Client_OnData1;
            //client.Connect();
            //tcpClient = new TcpClientWrapper("127.0.0.1", 5555);
            //tcpClient.Connect();
            viewControl.View.GetDataTable(0).GetSingleCell(0).SetStatus("testing");
            //new Thread(new ThreadStart(PipeServerMessage)).Start();
            //new Thread(new ThreadStart(PipeClientMessage)).Start();
        }
        private void Client_OnData1(object sender, PipeDataEventArgs e)
        {
            Console.WriteLine($"{e.Data}");
        }
        private void Client_OnData(object sender, PipeDataEventArgs e)
        {
            Dispatcher.Invoke(() =>
            {
                console.Text += e.Data;
            });
        }
        private void Button_Click2(object sender, RoutedEventArgs e)
        {
            var allStart = DateTime.Now;
            for (int i = 0; i < 100; i++)
            {
                var start = DateTime.Now;
                if (client.SendMessage("ping", out string res))
                {
                    var interval = (DateTime.Now - start).TotalMilliseconds;
                    Console.WriteLine($"{interval}: {res}");
                }
            }
            Console.WriteLine($"Total: {(DateTime.Now - allStart).TotalMilliseconds}");
        }
        private void Button_Click3(object sender, RoutedEventArgs e)
        {
            try
            {
                var allStart = DateTime.Now;
                for (int i = 0; i < 500; i++)
                {
                    var start = DateTime.Now;
                    string data = input.Text;
                    string str = $"{{\"command\":5,\"value\":{data},\"id\":\"DITag0\"}}\r\n";
                    string res = tcpClient.SendMessage(str);
                    var interval = (DateTime.Now - start).TotalMilliseconds;
                    Console.WriteLine($"{interval}: {res}");
                }
                Console.WriteLine($"Total: {(DateTime.Now - allStart).TotalMilliseconds}");
            }
            catch (Exception ex)
            {
            }
        }
        private void Button_Click4(object sender, RoutedEventArgs e)
        {
            try
            {
                var allStart = DateTime.Now;
                for (int i = 0; i < 500; i++)
                {
                    var start = DateTime.Now;
                    string data = input.Text;
                    string str = $"{{\"command\":5,\"value\":{data},\"id\":\"DITag0\"}}";
                    client.SendMessage(str, out string res);
                    var interval = (DateTime.Now - start).TotalMilliseconds;
                    Console.WriteLine($"{interval}: {res}");
                }
                Console.WriteLine($"Total: {(DateTime.Now - allStart).TotalMilliseconds}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
        private void HandlePlugin(object obj)
        {
            if (obj is IPlugin plugin)
            {
                plugin.SetBaseFolder(PathHelper.AppFolder);
                plugin.InitFinish();
            }
        }
        private ViewControl viewControl;
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            viewControl = new ViewControl();
            HandlePlugin(viewControl);
            border.Child = viewControl;
            this.Loaded -= Window_Loaded;
        }
    }
}