diff --git a/Server/Common/ConnectPipeline.cs b/Server/Common/ConnectPipeline.cs index 2d5315a..09bd98c 100644 --- a/Server/Common/ConnectPipeline.cs +++ b/Server/Common/ConnectPipeline.cs @@ -55,7 +55,7 @@ public class WebSocPipeLine(TSocket socket, bool isAES) : AbsPipeLine(i ); var fileContent = new ProgressStreamContent(fileStream, progress); content.Add(fileContent, "file", Path.GetFileName(filePath)); - var it = await client.PostAsync(url, content); + var it = await client.PostAsync(url + "/UploadPacked", content); if (it.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception(it.Content.ReadAsStringAsync().Result); diff --git a/Server/Common/Message.cs b/Server/Common/Message.cs index 62047eb..8827efe 100644 --- a/Server/Common/Message.cs +++ b/Server/Common/Message.cs @@ -5,7 +5,7 @@ public enum SyncMsgType Error = 0, General = 1, Process = 2, - DirFilePack = 3 + // DirFilePack = 3 } public enum SyncProcessStep { diff --git a/Server/LocalServer/Controllers/LocalServerController.cs b/Server/LocalServer/Controllers/LocalServerController.cs index 1e9be38..56fb6e4 100644 --- a/Server/LocalServer/Controllers/LocalServerController.cs +++ b/Server/LocalServer/Controllers/LocalServerController.cs @@ -20,8 +20,12 @@ namespace LocalServer.Controllers if (Factory.GetServerByName(Name) == null) { var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync(); - var pipeLine = new WebSocPipeLine(webSocket,false); - Factory.CreateLocalSyncServer(pipeLine, Name); + var pipeLine = new WebSocPipeLine(webSocket, false); + Factory.CreateLocalSyncServer( + pipeLine, + Name, + new WebSocPipeLine(new ClientWebSocket(), false) + ); } else { diff --git a/Server/LocalServer/LocalSyncServer.cs b/Server/LocalServer/LocalSyncServer.cs index cc967ba..b0a4892 100644 --- a/Server/LocalServer/LocalSyncServer.cs +++ b/Server/LocalServer/LocalSyncServer.cs @@ -1,4 +1,3 @@ -using System.Net.WebSockets; using Common; namespace LocalServer; @@ -31,20 +30,19 @@ public class LocalSyncServer /// public readonly AbsPipeLine LocalPipe; - public readonly AbsPipeLine RemotePipe = new WebSocPipeLine( - new ClientWebSocket(),false - ); + public readonly AbsPipeLine RemotePipe; /// /// 父工程,用于释放资源 /// public readonly LocalSyncServerFactory Factory; - public LocalSyncServer(AbsPipeLine pipe, LocalSyncServerFactory factory,string name) + public LocalSyncServer(AbsPipeLine pipe, LocalSyncServerFactory factory,string name,AbsPipeLine remotePipe ) { LocalPipe = pipe; Factory = factory; StateHelper = new ConnectAuthorityHelper(this); Name = name; + RemotePipe = remotePipe; Task.Run(async () => { diff --git a/Server/LocalServer/LocalSyncServerFactory.cs b/Server/LocalServer/LocalSyncServerFactory.cs index 9fd81e9..1f6ff41 100644 --- a/Server/LocalServer/LocalSyncServerFactory.cs +++ b/Server/LocalServer/LocalSyncServerFactory.cs @@ -1,13 +1,20 @@ using Common; +using System.Net.WebSockets; + namespace LocalServer; public class LocalSyncServerFactory { private readonly object Lock = new(); - public void CreateLocalSyncServer(AbsPipeLine pipeLine,string name) + public void CreateLocalSyncServer(AbsPipeLine pipeLine, string name,AbsPipeLine absPipeLine) { - var server = new LocalSyncServer(pipeLine, this,name); + var server = new LocalSyncServer( + pipeLine, + this, + name, + absPipeLine + ); lock (Lock) { Servers.Add(server); @@ -26,7 +33,7 @@ public class LocalSyncServerFactory public LocalSyncServer? GetServerByName(string name) { - var it = Servers.Where(x=>x.Name== name).FirstOrDefault(); + var it = Servers.Where(x => x.Name == name).FirstOrDefault(); return it; } } diff --git a/Server/LocalServer/StateHelper.cs b/Server/LocalServer/StateHelper.cs index a2aa18e..ccc6d14 100644 --- a/Server/LocalServer/StateHelper.cs +++ b/Server/LocalServer/StateHelper.cs @@ -2,7 +2,6 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Text.Json; using Common; -using Microsoft.AspNetCore.Mvc; namespace LocalServer; @@ -321,7 +320,7 @@ public class UploadPackedHelper(LocalSyncServer context) { Context .LocalPipe.UploadFile( - Context.NotNullSyncConfig.RemoteUrl + "/UploadPacked", + Context.NotNullSyncConfig.RemoteUrl , $"{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}/{Context.NotNullSyncConfig.Id}.zip", (double current) => { diff --git a/Server/ServerTest/FileDirOpForTest.cs b/Server/ServerTest/FileDirSimpleOp.cs similarity index 100% rename from Server/ServerTest/FileDirOpForTest.cs rename to Server/ServerTest/FileDirSimpleOp.cs diff --git a/Server/ServerTest/PipeSeed.cs b/Server/ServerTest/PipeSeed.cs new file mode 100644 index 0000000..8752f17 --- /dev/null +++ b/Server/ServerTest/PipeSeed.cs @@ -0,0 +1,61 @@ +using Common; +using LocalServer; +using RemoteServer; + +namespace ServerTest; + +public class PipeSeed : IDisposable +{ + public PipeSeed() + { + TestConfig = new Config + { + Name = "Test", + RemoteUrl = "D:/FileSyncTest", + RemotePwd = "", + IsDeployDb = true, + IsDeployProject = true, + LocalProjectAbsolutePath = "D:/git/HMES-H7-HNFY/HMES-H7-HNFYMF/HMES-H7-HNFYMF.WEB", + LocalRootPath = "D:/FileSyncTest/src", + + RemoteRootPath = "D:/FileSyncTest/dst", + SrcDb = new MSSqlConfig + { + ServerName = "172.16.12.2", + DatebaseName = "HMES_H7_HNFYMF", + User = "hmes-h7", + Password = "Hmes-h7666", + TrustServerCertificate = "True", + SyncTablesData = new List + { + "dbo.sys_Button", + "dbo.sys_Menu", + "dbo.sys_Module", + "dbo.sys_Page", + } + }, + DstDb = new MSSqlConfig + { + ServerName = "127.0.0.1", + DatebaseName = "HMES_H7_HNFYMF", + User = "sa", + Password = "0", + TrustServerCertificate = "True" + }, + DirFileConfigs = new List{ + new DirFileConfig{ + DirPath = "/bin", + Excludes = ["/roslyn","/Views"] + + } + } + }; + } + + public Config TestConfig; + + public void Dispose() + { + GC.SuppressFinalize(this); + } +} diff --git a/Server/ServerTest/PipeTest.cs b/Server/ServerTest/PipeTest.cs new file mode 100644 index 0000000..ab3e62b --- /dev/null +++ b/Server/ServerTest/PipeTest.cs @@ -0,0 +1,36 @@ +using System.Text.Json; +using Common; +using LocalServer; +using RemoteServer; +using XUnit.Project.Attributes; +/*using Newtonsoft.Json;*/ + +namespace ServerTest; + +public class PipeTest +{ + [Fact] + public async void TestCase() + { + var p1 = new TestPipe(false); + var p2 = new TestPipe(false); + p1.Other = p2; + p2.Other = p1; + var p3 = new TestPipe(true); + var p4 = new TestPipe(true); + p3.Other = p4; + p4.Other = p3; + + var lf = new LocalSyncServerFactory(); + lf.CreateLocalSyncServer(p2,"Test",p3); + var rf = new RemoteSyncServerFactory(); + rf.CreateRemoteSyncServer(p4,"Test"); + var starter = new SyncMsg( + SyncMsgType.General, + SyncProcessStep.Connect, + JsonSerializer.Serialize(new PipeSeed().TestConfig) + ); + await p1.SendMsg(starter); + + } +} \ No newline at end of file