You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.0 KiB

using Autofac;
using Autofac.Core;
using DotNetty.Handlers.Logging;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Utils;
using log4net;
using Newtonsoft.Json;
using Service.TBox;
using Service.TBox.Codec;
using Service.TBox.Server;
namespace WinFormStarter;
public partial class Form2 : Form
{
private static readonly ILog Log = LogManager.GetLogger(typeof(Form2));
private TBoxServer? server = null;
7 months ago
public Form2()
{
InitializeComponent();
this.txtPort.Text = "9000";
Task.Run(() =>
{
while (true)
{
if (Decoder.Msgs.TryDequeue(out var msg))
{
AppendText(rTxtParsed, JsonConvert.SerializeObject(msg) + "\r\n");
}
if (Decoder.BytesQueue.TryDequeue(out var bytes))
{
AppendText(rTxtOriginal, BitUtls.BytesToHexStr(bytes) + "\r\n");
}
Thread.Sleep(50);
}
});
}
private void AppendText(RichTextBox r, string msg)
{
if (r.InvokeRequired)
{
r.Invoke(() =>
{
r.AppendText(msg);
});
}
else
{
r.AppendText(msg);
}
}
private void btnConn_Click(object sender, EventArgs e)
{
string portTxt = txtPort.Text;
if (!int.TryParse(portTxt, out var port))
{
MessageBox.Show("请输入端口号");
return;
}
if (server == null)
{
foreach (var reg in AppInfo.Container.ComponentRegistry.Registrations)
foreach (var service in reg.Services)
if (service is TypedService ts)
Log.Info(ts.ServiceType);
server = AppInfo.Container.Resolve<TBoxServer>();
server.LogLevel = LogLevel.TRACE;
server.Start(port);
}
MessageBox.Show($"启动成功, 监听{port}");
}
}