diff --git a/Server/LocalServer/LocalSyncServer.cs b/Server/LocalServer/LocalSyncServer.cs index 3ddbb4b..dcb961a 100644 --- a/Server/LocalServer/LocalSyncServer.cs +++ b/Server/LocalServer/LocalSyncServer.cs @@ -7,7 +7,17 @@ public class LocalSyncServer #pragma warning disable CA2211 // Non-constant fields should not be visible public static string TempRootFile = "C:/TempPack"; #pragma warning restore CA2211 // Non-constant fields should not be visible - public StateHelpBase StateHelper; + private StateHelpBase StateHelper; + + public void SetStateHelper(StateHelpBase helper) + { + StateHelper = helper; + } + + public StateHelpBase GetStateHelper() + { + return StateHelper; + } public Config? SyncConfig; diff --git a/Server/LocalServer/StateHelper.cs b/Server/LocalServer/StateHelper.cs index d31e499..374143e 100644 --- a/Server/LocalServer/StateHelper.cs +++ b/Server/LocalServer/StateHelper.cs @@ -22,7 +22,7 @@ public abstract class StateHelpBase( { protected readonly LocalSyncServer Context = context; - protected readonly SyncProcessStep Step = step; + public readonly SyncProcessStep Step = step; public SyncMsg CreateErrMsg(string Body) { @@ -91,7 +91,7 @@ public class ConnectAuthorityHelper(LocalSyncServer context) Context.LocalPipe.SendMsg(msg); //下一步 var deployHelper = new DeployHelper(Context); - Context.StateHelper = deployHelper; + Context.SetStateHelper(deployHelper); deployHelper.DeployProcess(); } @@ -107,7 +107,8 @@ public class ConnectAuthorityHelper(LocalSyncServer context) var rs = Context.RemotePipe.Work( (byte[] b) => { - return Context.StateHelper.ReceiveRemoteMsg(b); + var x = Context.GetStateHelper().Step; + return Context.GetStateHelper().ReceiveRemoteMsg(b); }, Context.NotNullSyncConfig.RemoteUrl + "/websoc?Name=" + Context.Name ); @@ -142,7 +143,7 @@ public class DeployHelper(LocalSyncServer context) { Context.LocalPipe.SendMsg(CreateMsg("配置为不发布跳过此步骤")).Wait(); var h = new DiffFileAndPackHelper(Context); - Context.StateHelper = h; + Context.SetStateHelper(h); h.DiffProcess(); } else @@ -152,7 +153,7 @@ public class DeployHelper(LocalSyncServer context) ProcessStartInfo startInfo = new() { - FileName = "msdeploy", // The command to execute (can be any command line tool) + FileName = "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe", // The command to execute (can be any command line tool) Arguments = $" -verb:sync -source:contentPath={Context.NotNullSyncConfig.LocalProjectAbsolutePath} -dest:contentPath={Context.NotNullSyncConfig.LocalRootPath} -disablerule:BackupRule", // The arguments to pass to the command (e.g., list directory contents) @@ -172,9 +173,9 @@ public class DeployHelper(LocalSyncServer context) if (process.ExitCode == 0) { - Context.LocalPipe.SendMsg(CreateMsg("发布成功!")).Wait(); + Context.LocalPipe.SendMsg(CreateMsg("本地编译成功!")).Wait(); var h = new DiffFileAndPackHelper(Context); - Context.StateHelper = h; + Context.SetStateHelper(h); h.DiffProcess(); } else @@ -248,8 +249,8 @@ public class DiffFileAndPackHelper(LocalSyncServer context) } }); var n = new DeployMSSqlHelper(Context); + Context.SetStateHelper(n); n.PackSqlServerProcess(); - Context.StateHelper = n; } } @@ -263,7 +264,7 @@ public class DeployMSSqlHelper(LocalSyncServer context) Context.NotNullSyncConfig.Id.ToString() ); var h = new UploadPackedHelper(Context); - Context.StateHelper = h; + Context.SetStateHelper(h); h.UpLoadPackedFile(); } @@ -297,7 +298,7 @@ public class DeployMSSqlHelper(LocalSyncServer context) ProcessStartInfo startInfo = new() { - FileName = "SqlPackage", // The command to execute (can be any command line tool) + FileName = "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe", // The command to execute (can be any command line tool) Arguments = arguments, // The arguments to pass to the command (e.g., list directory contents) RedirectStandardOutput = true, // Redirect the standard output to a string @@ -359,6 +360,8 @@ public class UploadPackedHelper(LocalSyncServer context) ) .Wait(); Context.LocalPipe.SendMsg(CreateMsg("上传完成!")).Wait(); + + var x = Context.GetStateHelper().Step; } protected override void HandleLocalMsg(SyncMsg msg) @@ -370,7 +373,7 @@ public class UploadPackedHelper(LocalSyncServer context) { Context.LocalPipe.SendMsg(msg).Wait(); var h = new FinallyPublishHelper(Context); - Context.StateHelper = h; + Context.SetStateHelper(h); } } diff --git a/Server/RemoteServer/StateHelper.cs b/Server/RemoteServer/StateHelper.cs index 7f2ae32..a9e8327 100644 --- a/Server/RemoteServer/StateHelper.cs +++ b/Server/RemoteServer/StateHelper.cs @@ -126,7 +126,7 @@ public class UnPackAndReleaseHelper(RemoteSyncServer context) public void UnPack() { FileDirOpForUnpack.FirstUnComparess( - Path.Combine(RemoteSyncServer.TempRootFile, Context.NotNullSyncConfig.Id.ToString()), + Path.Combine(RemoteSyncServer.TempRootFile), Context.NotNullSyncConfig.Id.ToString() ); Context.Pipe.SendMsg(CreateMsg("解压完成!")).Wait(); @@ -149,14 +149,14 @@ public class FinallyPublishHelper(RemoteSyncServer context) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var arguments = - $" /Action:Publish /SourceFile: {RemoteSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}/{Context.NotNullSyncConfig.Id}.dacpac" + $" /Action:Publish /SourceFile:{RemoteSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}/{Context.NotNullSyncConfig.Id}.dacpac" + $" /TargetServerName:{Context.NotNullSyncConfig.DstDb.ServerName} /TargetDatabaseName:{Context.NotNullSyncConfig.DstDb.DatebaseName}" + $" /TargetUser:{Context.NotNullSyncConfig.DstDb.User} /TargetPassword:{Context.NotNullSyncConfig.DstDb.Password} /TargetTrustServerCertificate:True"; ProcessStartInfo startInfo = new() { - FileName = "SqlPackage", // The command to execute (can be any command line tool) + FileName = "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe", // The command to execute (can be any command line tool) Arguments = arguments, // The arguments to pass to the command (e.g., list directory contents) RedirectStandardOutput = true, // Redirect the standard output to a string @@ -193,11 +193,7 @@ public class FinallyPublishHelper(RemoteSyncServer context) Context.Pipe.SendMsg(CreateMsg("跳过数据库发布!")).Wait(); } var DirFileOp = new FileDirOpForUnpack( - Path.Combine( - RemoteSyncServer.TempRootFile, - Context.NotNullSyncConfig.Id.ToString(), - Context.NotNullSyncConfig.Id.ToString() - ), + Path.Combine(RemoteSyncServer.TempRootFile, Context.NotNullSyncConfig.Id.ToString()), Context.NotNullSyncConfig.RemoteRootPath ); Context.NotNullSyncConfig.DirFileConfigs.ForEach(e => diff --git a/Server/ServerTest/PipeTest.cs b/Server/ServerTest/PipeTest.cs index 3723af0..9ed63db 100644 --- a/Server/ServerTest/PipeTest.cs +++ b/Server/ServerTest/PipeTest.cs @@ -19,6 +19,11 @@ public class PipeTest var rs = p1.Work( (byte[] b) => { + var msg = JsonSerializer.Deserialize(b); + if (msg.Body == "ɣ") + { + p1.Close("˳"); + } Console.WriteLine(b); return true; } @@ -44,6 +49,7 @@ public class PipeTest lf.CreateLocalSyncServer(p2, "Test", p3); var rf = new RemoteSyncServerFactory(); rf.CreateRemoteSyncServer(p4, "Test"); + TestPipe.syncServerFactory = rf; var starter = new SyncMsg { Body = JsonSerializer.Serialize(new PipeSeed().TestConfig), @@ -52,7 +58,7 @@ public class PipeTest }; await p1.SendMsg(starter); await x; - if (p1.ErrResult != null) + if (p1.ErrResult != "˳") { Assert.Fail(p1.ErrResult); } diff --git a/Server/ServerTest/TestPipe.cs b/Server/ServerTest/TestPipe.cs index 45cb20a..c277780 100644 --- a/Server/ServerTest/TestPipe.cs +++ b/Server/ServerTest/TestPipe.cs @@ -2,6 +2,7 @@ using System.Text; using System.Text.Json; using Common; +using Microsoft.AspNetCore.Hosting.Server; using RemoteServer; namespace ServerTest @@ -14,6 +15,7 @@ namespace ServerTest public TestPipe? Other; public string? ErrResult; public string Id = id; + public static RemoteSyncServerFactory syncServerFactory; public override async IAsyncEnumerable Work( Func receiveCb, @@ -34,12 +36,19 @@ namespace ServerTest dst = Path.Combine(RemoteSyncServer.TempRootFile, Path.GetFileName(filePath)); await Task.Run(() => { + System.IO.File.Copy(filePath, dst, true); progressCb(100); //if (!Directory.Exists(dst)) //{ // Directory.CreateDirectory(dst); //} - System.IO.File.Copy(filePath, dst, true); + Task.Run(() => + { + var it = syncServerFactory.GetServerByName("Test"); + var h = new UnPackAndReleaseHelper(it); + it.StateHelper = h; + h.UnPack(); + }); }); } @@ -111,7 +120,14 @@ namespace ServerTest //var x = 1; var id = Id; //抛出异常 从 p3 传递到 p2 - throw new Exception(ErrResult); + if (ErrResult == "正常退出!") + { + return; + } + else + { + throw new Exception(ErrResult); + } } } }