2024-10-12 06:30:56 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2024-09-23 05:55:17 +00:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using Common;
|
|
|
|
|
using LocalServer;
|
|
|
|
|
using RemoteServer;
|
|
|
|
|
using XUnit.Project.Attributes;
|
2024-09-23 09:46:46 +00:00
|
|
|
|
|
2024-09-23 05:55:17 +00:00
|
|
|
|
/*using Newtonsoft.Json;*/
|
|
|
|
|
|
|
|
|
|
namespace ServerTest;
|
|
|
|
|
|
|
|
|
|
public class PipeTest
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public async void TestCase()
|
|
|
|
|
{
|
2024-10-29 04:46:13 +00:00
|
|
|
|
//if (System.IO.File.Exists("Pipe.txt"))
|
|
|
|
|
//{
|
|
|
|
|
// System.IO.File.Delete("Pipe.txt");
|
|
|
|
|
//}
|
|
|
|
|
//System.IO.File.Create("Pipe.txt");
|
|
|
|
|
//msbuild ֻ<><D6BB><EFBFBD><EFBFBD>windows<77><73><EFBFBD><EFBFBD>
|
2024-10-12 06:30:56 +00:00
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
2024-09-24 09:46:52 +00:00
|
|
|
|
{
|
2024-10-12 06:30:56 +00:00
|
|
|
|
var p1 = new TestPipe(false, "1");
|
|
|
|
|
var x = Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
var rs = p1.Work(
|
|
|
|
|
(byte[] b) =>
|
2024-09-26 09:49:40 +00:00
|
|
|
|
{
|
2024-10-12 06:30:56 +00:00
|
|
|
|
var msg = JsonSerializer.Deserialize<SyncMsg>(b);
|
|
|
|
|
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
|
|
|
|
if (msg.Body == "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>")
|
|
|
|
|
{
|
2024-10-29 04:46:13 +00:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Task.Delay(1000).Wait();
|
|
|
|
|
_ = p1.Close("<22><><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD>");
|
|
|
|
|
});
|
2024-10-12 06:30:56 +00:00
|
|
|
|
}
|
|
|
|
|
#pragma warning restore CS8602 // Dereference of a possibly null reference.
|
2024-10-29 04:46:13 +00:00
|
|
|
|
System.IO.File.AppendAllText(
|
|
|
|
|
"Pipe.txt",
|
|
|
|
|
$"{msg.Step}-{msg.Type}:{msg.Body}\n"
|
|
|
|
|
);
|
|
|
|
|
|
2024-10-12 06:30:56 +00:00
|
|
|
|
Console.WriteLine(b);
|
|
|
|
|
return true;
|
2024-09-26 09:49:40 +00:00
|
|
|
|
}
|
2024-10-12 06:30:56 +00:00
|
|
|
|
);
|
|
|
|
|
await foreach (var r in rs)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(r);
|
2024-09-24 09:46:52 +00:00
|
|
|
|
}
|
2024-10-12 06:30:56 +00:00
|
|
|
|
});
|
|
|
|
|
//await p1.Close("sdf");
|
|
|
|
|
//await x;
|
|
|
|
|
var p2 = new TestPipe(false, "2");
|
|
|
|
|
p1.Other = p2;
|
|
|
|
|
p2.Other = p1;
|
|
|
|
|
var p3 = new TestPipe(true, "3");
|
|
|
|
|
var p4 = new TestPipe(true, "4");
|
|
|
|
|
p3.Other = p4;
|
|
|
|
|
p4.Other = p3;
|
|
|
|
|
LocalSyncServer.TempRootFile = "D:/FileSyncTest/stemp";
|
|
|
|
|
RemoteSyncServer.SqlPackageAbPath =
|
|
|
|
|
"C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe";
|
|
|
|
|
//LocalSyncServer.MsdeployAbPath =
|
|
|
|
|
// "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe";
|
|
|
|
|
LocalSyncServer.SqlPackageAbPath = "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe";
|
|
|
|
|
LocalSyncServer.MSBuildAbPath =
|
|
|
|
|
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\amd64\\MSBuild.exe";
|
|
|
|
|
RemoteSyncServer.TempRootFile = "D:/FileSyncTest/dtemp";
|
|
|
|
|
RemoteSyncServerFactory.NamePwd = [new Tuple<string, string>("Test", "t123")];
|
|
|
|
|
var lf = new LocalSyncServerFactory();
|
|
|
|
|
var task1 = Task.Run(async () =>
|
2024-09-24 09:46:52 +00:00
|
|
|
|
{
|
2024-10-12 06:30:56 +00:00
|
|
|
|
await lf.CreateLocalSyncServer(p2, "Test", p3);
|
|
|
|
|
});
|
2024-10-10 05:15:14 +00:00
|
|
|
|
|
2024-10-12 06:30:56 +00:00
|
|
|
|
var rf = new RemoteSyncServerFactory();
|
2024-10-10 05:15:14 +00:00
|
|
|
|
|
2024-10-12 06:30:56 +00:00
|
|
|
|
var task2 = Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
await rf.CreateRemoteSyncServer(p4, "Test");
|
|
|
|
|
});
|
|
|
|
|
TestPipe.syncServerFactory = rf;
|
|
|
|
|
var starter = new SyncMsg
|
|
|
|
|
{
|
|
|
|
|
Body = JsonSerializer.Serialize(new PipeSeed().TestConfig),
|
|
|
|
|
Type = SyncMsgType.General,
|
|
|
|
|
Step = SyncProcessStep.Connect
|
|
|
|
|
};
|
|
|
|
|
await p1.SendMsg(starter);
|
|
|
|
|
await x;
|
|
|
|
|
if (p1.ErrResult != "<22><><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD>")
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail(p1.ErrResult);
|
|
|
|
|
}
|
2024-09-24 09:46:52 +00:00
|
|
|
|
}
|
2024-09-23 05:55:17 +00:00
|
|
|
|
}
|
2024-09-23 09:46:46 +00:00
|
|
|
|
}
|