refactor: 改进了DirFileConfigs 的结构

This commit is contained in:
zerlei 2024-09-23 09:13:24 +08:00
parent 002a99589b
commit d7d39859d2
5 changed files with 31 additions and 38 deletions

View file

@ -18,7 +18,9 @@ public class DirFileConfig
public List<string>? CherryPicks { get; set; } public List<string>? 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 public class MSSqlConfig

View file

@ -185,8 +185,8 @@ public class DiffFileAndPackHelper(LocalSyncServer context)
//提取本地文件的信息 //提取本地文件的信息
Context.NotNullSyncConfig.DirFileConfigs.ForEach(e => Context.NotNullSyncConfig.DirFileConfigs.ForEach(e =>
{ {
e.DirInfo = new Dir(Context.NotNullSyncConfig.LocalRootPath + e.DirPath); e.LocalDirInfo = new Dir(Context.NotNullSyncConfig.LocalRootPath + e.DirPath);
e.DirInfo.ExtractInfo(e.CherryPicks, e.Excludes); e.LocalDirInfo.ExtractInfo(e.CherryPicks, e.Excludes);
}); });
//将配置信息发送到remoteServer //将配置信息发送到remoteServer
Context Context
@ -198,24 +198,28 @@ public class DiffFileAndPackHelper(LocalSyncServer context)
protected override void HandleRemoteMsg(SyncMsg msg) protected override void HandleRemoteMsg(SyncMsg msg)
{ {
Context.NotNullSyncConfig.DirFileConfigs = var diffConfig =
JsonSerializer.Deserialize<List<DirFileConfig>>(msg.Body) JsonSerializer.Deserialize<List<DirFileConfig>>(msg.Body)
?? throw new Exception("LocalServer: DirFile为空"); ?? 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( var PackOp = new FileDirOpForPack(
Context.NotNullSyncConfig.LocalRootPath, Context.NotNullSyncConfig.LocalRootPath,
LocalSyncServer.TempRootFile + "/" + Context.NotNullSyncConfig.Id.ToString(), LocalSyncServer.TempRootFile + "/" + Context.NotNullSyncConfig.Id.ToString()
Context.NotNullSyncConfig.Id.ToString()
); );
Context.NotNullSyncConfig.DirFileConfigs.ForEach(e => Context.NotNullSyncConfig.DirFileConfigs.ForEach(e =>
{ {
if (e.DirInfo != null) if (e.DiffDirInfo!= null)
{ {
e.DirInfo.ResetRootPath( e.DiffDirInfo.ResetRootPath(
Context.NotNullSyncConfig.RemoteRootPath, Context.NotNullSyncConfig.RemoteRootPath,
Context.NotNullSyncConfig.LocalRootPath Context.NotNullSyncConfig.LocalRootPath
); );
e.DirInfo.WriteByThisInfo(PackOp); e.DiffDirInfo.WriteByThisInfo(PackOp);
} }
}); });
var n = new DeployMSSqlHelper(Context); var n = new DeployMSSqlHelper(Context);

View file

@ -12,7 +12,6 @@ public class RemoteSyncServer
public StateHelpBase StateHelper; public StateHelpBase StateHelper;
public Config? SyncConfig; public Config? SyncConfig;
public List<DirFileConfig> Diff = [];
public Config NotNullSyncConfig public Config NotNullSyncConfig
{ {

View file

@ -21,6 +21,7 @@ public abstract class StateHelpBase(
protected readonly RemoteSyncServer Context = context; protected readonly RemoteSyncServer Context = context;
protected readonly SyncProcessStep Step = step; protected readonly SyncProcessStep Step = step;
public SyncMsg CreateErrMsg(string Body) public SyncMsg CreateErrMsg(string Body)
{ {
return new SyncMsg(SyncMsgType.Error, Step, Body); return new SyncMsg(SyncMsgType.Error, Step, Body);
@ -76,36 +77,31 @@ public class DiffFileHelper(RemoteSyncServer context)
{ {
Context.SyncConfig = JsonSerializer.Deserialize<Config>(msg.Body); Context.SyncConfig = JsonSerializer.Deserialize<Config>(msg.Body);
var diffConfigs = new List<DirFileConfig>();
//文件对比 //文件对比
Context.NotNullSyncConfig.DirFileConfigs.ForEach(e => Context.NotNullSyncConfig.DirFileConfigs.ForEach(e =>
{ {
if (e.DirInfo == null) if (e.LocalDirInfo == null)
{ {
throw new NullReferenceException("RemoteServer: 发布的文件为空!--这个异常应该永远不会发生~"); throw new NullReferenceException("RemoteServer: 发布的文件为空!--这个异常应该永远不会发生~");
} }
else else
{ {
var nd = e.DirInfo.Clone(); var nd = e.LocalDirInfo.Clone();
nd.ResetRootPath( nd.ResetRootPath(
Context.NotNullSyncConfig.LocalRootPath, Context.NotNullSyncConfig.LocalRootPath,
Context.NotNullSyncConfig.RemoteRootPath Context.NotNullSyncConfig.RemoteRootPath
); );
nd.ExtractInfo(e.CherryPicks, e.Excludes); nd.ExtractInfo(e.CherryPicks, e.Excludes);
var diff = e.DirInfo.Diff(nd); e.DiffDirInfo = nd.Diff(nd);
e.DirInfo = nd; e.RemoteDirInfo = nd;
Context.Diff.Add( diffConfigs.Add(
new DirFileConfig() new DirFileConfig { DiffDirInfo = e.DiffDirInfo, DirPath = e.DirPath }
{
DirPath = e.DirPath,
Excludes = e.Excludes,
CherryPicks = e.CherryPicks,
DirInfo = diff
}
); );
} }
}); });
//将对比结果发送到Local //将对比结果发送到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 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. if (e.RemoteDirInfo != null && e.DiffDirInfo != null)
#pragma warning disable CS8604 // Possible null reference argument. {
Context e.RemoteDirInfo.CombineJustDirFile(DirFileOp, e.DiffDirInfo);
.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.
}
Context.Pipe.SendMsg(CreateMsg("发布完成!")).Wait(); Context.Pipe.SendMsg(CreateMsg("发布完成!")).Wait();
} }

View file

@ -1,10 +1,5 @@
using System; using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Common; using Common;
namespace ServerTest namespace ServerTest