using ConnectionUtil;
|
using HMI.Core.Api;
|
using HMI.Core.Util;
|
using log4net;
|
using Panuon.WPF.UI;
|
using Plugin.DataBoard;
|
using Plugin.TestBuilder;
|
using Plugin.TestResult_WPF;
|
using Plugin.TsExecution;
|
using System;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using System.Windows;
|
|
namespace UnitTest
|
{
|
/// <summary>
|
/// MainWindow.xaml 的交互逻辑
|
/// </summary>
|
public partial class MainWindow : WindowX
|
{
|
private ILog log = LogManager.GetLogger("UnitTest");
|
public MainWindow()
|
{
|
LangUtil.Load();
|
InitializeComponent();
|
//page.Children.Add(new UserControl1());
|
}
|
|
TcpClientWrapper tcpClient;
|
|
PipeClient2 client;
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
{
|
Task.Run(() =>
|
{
|
for (int j = 0; j < 1000; j++)
|
{
|
string status = (j % 2 == 0) ? "Passed" : "Failed";
|
string d = (j % 2 == 0) ? "9" : "9999999999999999999999999999999999999999999999999999999999999999995";
|
tsExecution.AddTestData(0, $"ConnectivityCANRec,2,3,4,{d},6,{status}");
|
}
|
});
|
|
tsExecution.UpdatePositionStatus(0, "Passed");
|
tsExecution.UpdatePositionProcessValue(0, 12);
|
tsExecution.PausePosition(0);
|
tsExecution.SetPositionBarcode(0, "123456789");
|
tsExecution.SavePositionCSV(0);
|
|
|
//tsExecution.UpdatePositionStatus(1, "Failed");
|
//tsExecution.UpdatePositionStatus(2, "Ready");
|
//tsExecution.UpdatePositionStatus(3, "Testing");
|
//tsExecution.UpdatePositionProcessValue(1, 50);
|
//tsExecution.UpdatePositionProcessValue(2, 100);
|
//tsExecution.UpdatePositionProcessValue(3, 99);
|
|
|
//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("C:\\Workspace\\VisualStudio\\WPFProject\\WPFProject\\bin\\x64\\Debug\\Config\\TsExecution");
|
plugin.SetLogger(log);
|
plugin.InitFinish();
|
}
|
|
}
|
|
private ViewControl viewControl;
|
|
private TsExecution tsExecution;
|
|
private TestBuilder testBuilder;
|
private DataBoard dataBoard;
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
{
|
var plugin = new TsExecution();
|
HandlePlugin(plugin);
|
border.Child = plugin;
|
tsExecution = plugin;
|
this.Loaded -= Window_Loaded;
|
}
|
}
|
}
|