From 4467c929ce3b51fd68060e3ac2281a18073f1997 Mon Sep 17 00:00:00 2001 From: woni <320753691@qq.com> Date: Tue, 24 Oct 2023 09:03:38 +0800 Subject: [PATCH] sync code --- BotBridge.csproj | 6 ++++++ BotExtPipe.cs | 5 +++++ Program.cs | 49 ++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/BotBridge.csproj b/BotBridge.csproj index fbb4a9b..71db53a 100644 --- a/BotBridge.csproj +++ b/BotBridge.csproj @@ -9,4 +9,10 @@ true + + + + + + diff --git a/BotExtPipe.cs b/BotExtPipe.cs index c2a6113..8275050 100644 --- a/BotExtPipe.cs +++ b/BotExtPipe.cs @@ -48,4 +48,9 @@ internal class BotExtPipe return buffer; } + public void Close() + { + _pipeServerStream.Close(); + } + } diff --git a/Program.cs b/Program.cs index 203086b..e39f0a6 100644 --- a/Program.cs +++ b/Program.cs @@ -1,28 +1,61 @@ using System.Text; +using Microsoft.Extensions.Logging; +using System.Diagnostics.CodeAnalysis; namespace BotBridge; internal class Program { + [RequiresDynamicCode("Calls Microsoft.Extensions.Logging.LoggerFactory.Create(Action)")] static void Main(string[] args) { BotExtHost botExtHost = new BotExtHost(); - while (true) - { - BotExtPipe botExtPipe = new BotExtPipe("BotExtPipe"); - botExtPipe.WaitForConnection(); + using ILoggerFactory loggerFactory = LoggerFactory.Create(builder => + { + builder.AddSimpleConsole(options => + { + options.IncludeScopes = true; + options.SingleLine = true; + options.TimestampFormat = "HH:mm:ss "; + } + ); + } + + ); + ILogger logger = loggerFactory.CreateLogger(); + using (logger.BeginScope("[scope is enabled]")) + { while (true) { + //BotExtPipe botExtPipe = new BotExtPipe("BotExtPipe"); + //botExtPipe.WaitForConnection(); + + //byte[] clientData = botExtPipe.ReadData(); + //logger.LogInformation("Recived: " + Encoding.UTF8.GetString(clientData)); + //botExtPipe.WriteData(Encoding.UTF8.GetBytes("Hello from BotExtHost")); + //logger.LogInformation("Send: Hello from BotExtHost"); + //botExtPipe.Close(); + + //while (true) + //{ + + // byte[] clientData = botExtPipe.ReadData(); + // //Console.WriteLine(Encoding.UTF8.GetString(clientData)); + // botExtPipe.Close(); + // //botExtHost.WriteData(clientData); + // //byte[] serverData = botExtHost.ReadData(); + // //botExtPipe.WriteData(serverData); + + //} - byte[] clientData = botExtPipe.ReadData(); - botExtHost.WriteData(clientData); byte[] serverData = botExtHost.ReadData(); - botExtPipe.WriteData(serverData); - + logger.LogInformation("Recived from chrom:" + Encoding.UTF8.GetString(serverData)); } } + + } } \ No newline at end of file