Add project files.
This commit is contained in:
1 parent
69125777be
commit
082c25b252
5 files changed
+161
No files matched your search
@@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<PublishAot>true</PublishAot>
|
||||||
|
<InvariantGlobalization>true</InvariantGlobalization>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.7.34024.191
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotBridge", "BotBridge.csproj", "{81206CA0-73E6-48B0-B061-97131963EA7D}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{81206CA0-73E6-48B0-B061-97131963EA7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{81206CA0-73E6-48B0-B061-97131963EA7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{81206CA0-73E6-48B0-B061-97131963EA7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{81206CA0-73E6-48B0-B061-97131963EA7D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {FC656DCA-2289-41AA-91ED-49EFF75A916A}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BotBridge;
|
||||||
|
|
||||||
|
internal class BotExtHost
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly Stream _stdIn = Console.OpenStandardInput();
|
||||||
|
private readonly Stream _stdOut = Console.OpenStandardOutput();
|
||||||
|
|
||||||
|
|
||||||
|
public void WriteData(byte[] data)
|
||||||
|
{
|
||||||
|
byte[] dataLength = BitConverter.GetBytes(data.Length);
|
||||||
|
if (BitConverter.IsLittleEndian)
|
||||||
|
{
|
||||||
|
Array.Reverse(dataLength);
|
||||||
|
}
|
||||||
|
_stdOut.Write(dataLength, 0, dataLength.Length);
|
||||||
|
|
||||||
|
_stdOut.Write(data, 0, data.Length);
|
||||||
|
_stdIn.Flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] ReadData()
|
||||||
|
{
|
||||||
|
byte[] dataLengthBytes = new byte[4];
|
||||||
|
_stdIn.Read(dataLengthBytes, 0, 4);
|
||||||
|
if (BitConverter.IsLittleEndian)
|
||||||
|
{
|
||||||
|
Array.Reverse(dataLengthBytes);
|
||||||
|
}
|
||||||
|
int dataLength = BitConverter.ToInt32(dataLengthBytes, 0);
|
||||||
|
|
||||||
|
byte[] data = new byte[dataLength];
|
||||||
|
_stdIn.Read(data, 0, dataLength);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.IO.Pipes;
|
||||||
|
|
||||||
|
namespace BotBridge;
|
||||||
|
|
||||||
|
internal class BotExtPipe
|
||||||
|
{
|
||||||
|
private readonly NamedPipeServerStream _pipeServerStream;
|
||||||
|
|
||||||
|
public BotExtPipe(string pipeName)
|
||||||
|
{
|
||||||
|
_pipeServerStream = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WaitForConnection()
|
||||||
|
{
|
||||||
|
_pipeServerStream.WaitForConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] ReadData()
|
||||||
|
{
|
||||||
|
int messageLength = BitConverter.ToInt32(ReadBytes(_pipeServerStream, 4), 0);
|
||||||
|
return ReadBytes(_pipeServerStream, messageLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteData(byte[] data)
|
||||||
|
{
|
||||||
|
byte[] dateLength = BitConverter.GetBytes(data.Length);
|
||||||
|
_pipeServerStream.Write(dateLength, 0, dateLength.Length);
|
||||||
|
_pipeServerStream.Write(data, 0, data.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static byte[] ReadBytes(NamedPipeServerStream pipeServerStream, int bytesToRead)
|
||||||
|
{
|
||||||
|
byte[] buffer = new byte[bytesToRead];
|
||||||
|
int bytesRead = 0;
|
||||||
|
int totalBytesRead = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
bytesRead = pipeServerStream.Read(buffer, totalBytesRead, bytesToRead - totalBytesRead);
|
||||||
|
totalBytesRead += bytesRead;
|
||||||
|
} while (bytesRead > 0 && totalBytesRead < bytesToRead);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BotBridge;
|
||||||
|
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
BotExtHost botExtHost = new BotExtHost();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
BotExtPipe botExtPipe = new BotExtPipe("BotExtPipe");
|
||||||
|
botExtPipe.WaitForConnection();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
|
||||||
|
byte[] clientData = botExtPipe.ReadData();
|
||||||
|
botExtHost.WriteData(clientData);
|
||||||
|
byte[] serverData = botExtHost.ReadData();
|
||||||
|
botExtPipe.WriteData(serverData);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user