diff --git a/Server/Common/Config.cs b/Server/Common/Config.cs index e828d56..294c67a 100644 --- a/Server/Common/Config.cs +++ b/Server/Common/Config.cs @@ -18,7 +18,9 @@ public class DirFileConfig public List? CherryPicks { get; set; } /// - public Dir? DirInfo { get; set; } + public Dir? LocalDirInfo { get; set; } + public Dir? DiffDirInfo{ get; set; } + public Dir? RemoteDirInfo{ get; set; } } public class MSSqlConfig diff --git a/Server/LocalServer/StateHelper.cs b/Server/LocalServer/StateHelper.cs index 5eb20d1..a2aa18e 100644 --- a/Server/LocalServer/StateHelper.cs +++ b/Server/LocalServer/StateHelper.cs @@ -185,8 +185,8 @@ public class DiffFileAndPackHelper(LocalSyncServer context) //提取本地文件的信息 Context.NotNullSyncConfig.DirFileConfigs.ForEach(e => { - e.DirInfo = new Dir(Context.NotNullSyncConfig.LocalRootPath + e.DirPath); - e.DirInfo.ExtractInfo(e.CherryPicks, e.Excludes); + e.LocalDirInfo = new Dir(Context.NotNullSyncConfig.LocalRootPath + e.DirPath); + e.LocalDirInfo.ExtractInfo(e.CherryPicks, e.Excludes); }); //将配置信息发送到remoteServer Context @@ -198,24 +198,28 @@ public class DiffFileAndPackHelper(LocalSyncServer context) protected override void HandleRemoteMsg(SyncMsg msg) { - Context.NotNullSyncConfig.DirFileConfigs = + var diffConfig = JsonSerializer.Deserialize>(msg.Body) ?? throw new Exception("LocalServer: DirFile为空!"); + for (var i = 0; i < diffConfig.Count; ++i) + { + Context.NotNullSyncConfig.DirFileConfigs[i].DiffDirInfo = diffConfig[i].DiffDirInfo; + } + var PackOp = new FileDirOpForPack( Context.NotNullSyncConfig.LocalRootPath, - LocalSyncServer.TempRootFile + "/" + Context.NotNullSyncConfig.Id.ToString(), - Context.NotNullSyncConfig.Id.ToString() + LocalSyncServer.TempRootFile + "/" + Context.NotNullSyncConfig.Id.ToString() ); Context.NotNullSyncConfig.DirFileConfigs.ForEach(e => { - if (e.DirInfo != null) + if (e.DiffDirInfo!= null) { - e.DirInfo.ResetRootPath( + e.DiffDirInfo.ResetRootPath( Context.NotNullSyncConfig.RemoteRootPath, Context.NotNullSyncConfig.LocalRootPath ); - e.DirInfo.WriteByThisInfo(PackOp); + e.DiffDirInfo.WriteByThisInfo(PackOp); } }); var n = new DeployMSSqlHelper(Context); diff --git a/Server/RemoteServer/RemoteSyncServer.cs b/Server/RemoteServer/RemoteSyncServer.cs index 598dc9d..4beb2f6 100644 --- a/Server/RemoteServer/RemoteSyncServer.cs +++ b/Server/RemoteServer/RemoteSyncServer.cs @@ -12,7 +12,6 @@ public class RemoteSyncServer public StateHelpBase StateHelper; public Config? SyncConfig; - public List Diff = []; public Config NotNullSyncConfig { diff --git a/Server/RemoteServer/StateHelper.cs b/Server/RemoteServer/StateHelper.cs index 418d6ea..5d3fe2b 100644 --- a/Server/RemoteServer/StateHelper.cs +++ b/Server/RemoteServer/StateHelper.cs @@ -21,6 +21,7 @@ public abstract class StateHelpBase( protected readonly RemoteSyncServer Context = context; protected readonly SyncProcessStep Step = step; + public SyncMsg CreateErrMsg(string Body) { return new SyncMsg(SyncMsgType.Error, Step, Body); @@ -76,36 +77,31 @@ public class DiffFileHelper(RemoteSyncServer context) { Context.SyncConfig = JsonSerializer.Deserialize(msg.Body); + var diffConfigs = new List(); //文件对比 Context.NotNullSyncConfig.DirFileConfigs.ForEach(e => { - if (e.DirInfo == null) + if (e.LocalDirInfo == null) { throw new NullReferenceException("RemoteServer: 发布的文件为空!--这个异常应该永远不会发生~"); } else { - var nd = e.DirInfo.Clone(); + var nd = e.LocalDirInfo.Clone(); nd.ResetRootPath( Context.NotNullSyncConfig.LocalRootPath, Context.NotNullSyncConfig.RemoteRootPath ); nd.ExtractInfo(e.CherryPicks, e.Excludes); - var diff = e.DirInfo.Diff(nd); - e.DirInfo = nd; - Context.Diff.Add( - new DirFileConfig() - { - DirPath = e.DirPath, - Excludes = e.Excludes, - CherryPicks = e.CherryPicks, - DirInfo = diff - } + e.DiffDirInfo = nd.Diff(nd); + e.RemoteDirInfo = nd; + diffConfigs.Add( + new DirFileConfig { DiffDirInfo = e.DiffDirInfo, DirPath = e.DirPath } ); } }); //将对比结果发送到Local - Context.Pipe.SendMsg(CreateMsg(JsonSerializer.Serialize(Context.Diff))); + Context.Pipe.SendMsg(CreateMsg(JsonSerializer.Serialize(diffConfigs))); } } @@ -189,16 +185,13 @@ public class FinallyPublishHelper(RemoteSyncServer context) ), Context.NotNullSyncConfig.RemoteRootPath ); - for (int i = 0; i < Context.NotNullSyncConfig.DirFileConfigs.Count; ++i) + Context.NotNullSyncConfig.DirFileConfigs.ForEach(e => { -#pragma warning disable CS8602 // Dereference of a possibly null reference. -#pragma warning disable CS8604 // Possible null reference argument. - Context - .NotNullSyncConfig.DirFileConfigs[i] - .DirInfo.CombineJustDirFile(DirFileOp, Context.Diff[i].DirInfo); -#pragma warning restore CS8604 // Possible null reference argument. -#pragma warning restore CS8602 // Dereference of a possibly null reference. - } + if (e.RemoteDirInfo != null && e.DiffDirInfo != null) + { + e.RemoteDirInfo.CombineJustDirFile(DirFileOp, e.DiffDirInfo); + } + }); Context.Pipe.SendMsg(CreateMsg("发布完成!")).Wait(); } diff --git a/Server/ServerTest/TestPipe.cs b/Server/ServerTest/TestPipe.cs index c520c78..9e1521c 100644 --- a/Server/ServerTest/TestPipe.cs +++ b/Server/ServerTest/TestPipe.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Text; +using System.Collections.Concurrent; using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; using Common; namespace ServerTest