refactor: 改进了DirFileConfigs 的结构
This commit is contained in:
parent
002a99589b
commit
d7d39859d2
5 changed files with 31 additions and 38 deletions
|
@ -18,7 +18,9 @@ public class DirFileConfig
|
|||
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
|
||||
|
|
|
@ -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<List<DirFileConfig>>(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);
|
||||
|
|
|
@ -12,7 +12,6 @@ public class RemoteSyncServer
|
|||
public StateHelpBase StateHelper;
|
||||
|
||||
public Config? SyncConfig;
|
||||
public List<DirFileConfig> Diff = [];
|
||||
|
||||
public Config NotNullSyncConfig
|
||||
{
|
||||
|
|
|
@ -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<Config>(msg.Body);
|
||||
|
||||
var diffConfigs = new List<DirFileConfig>();
|
||||
//文件对比
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue