fix: 测试改了一堆bug
This commit is contained in:
parent
a70a302134
commit
ffda80aa01
7 changed files with 113 additions and 86 deletions
|
@ -2,7 +2,6 @@ namespace Common;
|
|||
|
||||
public static class DirExtension
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 比较两个目录文件树是否相同,不相同返回差异部分,左侧是右侧的下一个版本,任何一个节点的nextop != null,即所有
|
||||
/// 节点都会打上标记
|
||||
|
@ -286,14 +285,15 @@ public static class DirExtension
|
|||
{
|
||||
bool filter(string path)
|
||||
{
|
||||
var relativePath = path.Replace('\\', '/').Replace(thisDir.FormatedPath, "");
|
||||
if (cherryPicks != null)
|
||||
{
|
||||
return cherryPicks.Contains(path);
|
||||
return cherryPicks.Contains(relativePath);
|
||||
}
|
||||
|
||||
if (exculdes != null)
|
||||
{
|
||||
return !exculdes.Contains(path);
|
||||
return !exculdes.Contains(relativePath);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -302,6 +302,8 @@ public static class DirExtension
|
|||
{
|
||||
throw new NotSupportedException("this dir is not empty.");
|
||||
}
|
||||
if (Directory.Exists(thisDir.FormatedPath))
|
||||
{
|
||||
string[] files = Directory.GetFiles(thisDir.FormatedPath);
|
||||
string[] dirs = Directory.GetDirectories(thisDir.FormatedPath);
|
||||
foreach (var file in files)
|
||||
|
@ -318,11 +320,12 @@ public static class DirExtension
|
|||
if (filter(dir))
|
||||
{
|
||||
var ndir = new Dir { Path = dir, Children = [] };
|
||||
ndir.ExtractInfo();
|
||||
ndir.ExtractInfo(cherryPicks, exculdes);
|
||||
thisDir.Children.Add(ndir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddChild(this Dir thisDir, AFileOrDir child)
|
||||
{
|
|
@ -1,4 +1,6 @@
|
|||
namespace Common;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Common;
|
||||
|
||||
public enum DirOrFile
|
||||
{
|
||||
|
@ -13,7 +15,10 @@ public enum NextOpType
|
|||
Del = 2
|
||||
}
|
||||
|
||||
public abstract class AFileOrDir
|
||||
[JsonDerivedType(typeof(AFileOrDir), typeDiscriminator: 1)]
|
||||
[JsonDerivedType(typeof(File), typeDiscriminator: 2)]
|
||||
[JsonDerivedType(typeof(Dir), typeDiscriminator: 3)]
|
||||
public class AFileOrDir
|
||||
{
|
||||
public DirOrFile Type { get; set; }
|
||||
public NextOpType? NextOp { get; set; }
|
||||
|
@ -33,7 +38,11 @@ public abstract class AFileOrDir
|
|||
get { return Path.Replace("\\", "/"); }
|
||||
set { Path = value; }
|
||||
}
|
||||
public abstract bool IsEqual(AFileOrDir other);
|
||||
|
||||
public bool IsEqual(AFileOrDir other)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int Compare(AFileOrDir l, AFileOrDir r)
|
||||
{
|
||||
|
@ -57,9 +66,10 @@ public class File : AFileOrDir
|
|||
{
|
||||
Type = DirOrFile.File;
|
||||
}
|
||||
|
||||
public required DateTime MTime { get; set; }
|
||||
|
||||
public override bool IsEqual(AFileOrDir other)
|
||||
public new bool IsEqual(AFileOrDir other)
|
||||
{
|
||||
if (other is not File otherFile)
|
||||
{
|
||||
|
@ -83,9 +93,10 @@ public class Dir : AFileOrDir
|
|||
{
|
||||
Type = DirOrFile.Dir;
|
||||
}
|
||||
|
||||
public required List<AFileOrDir> Children { get; set; }
|
||||
|
||||
public override bool IsEqual(AFileOrDir other)
|
||||
public new bool IsEqual(AFileOrDir other)
|
||||
{
|
||||
if (other is not Dir otherDir)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@ using System.Diagnostics;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Common;
|
||||
|
||||
namespace LocalServer;
|
||||
|
@ -210,8 +211,11 @@ public class DiffFileAndPackHelper(LocalSyncServer context)
|
|||
e.LocalDirInfo.ExtractInfo(e.CherryPicks, e.Excludes);
|
||||
});
|
||||
//将配置信息发送到remoteServer
|
||||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||
Context
|
||||
.RemotePipe.SendMsg(CreateMsg(JsonSerializer.Serialize(Context.NotNullSyncConfig)))
|
||||
.RemotePipe.SendMsg(
|
||||
CreateMsg(JsonSerializer.Serialize(Context.NotNullSyncConfig, options))
|
||||
)
|
||||
.Wait();
|
||||
}
|
||||
|
||||
|
@ -276,7 +280,8 @@ public class DeployMSSqlHelper(LocalSyncServer context)
|
|||
{
|
||||
var arguments =
|
||||
$" /Action:Extract /TargetFile:{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id.ToString()}/{Context.NotNullSyncConfig.Id.ToString()}.dacpac"
|
||||
+ $"/DiagnosticsFile:{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id.ToString()}/{Context.NotNullSyncConfig.Id.ToString()}.log "
|
||||
// 不要log file 了
|
||||
//+ $" /DiagnosticsFile:{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id.ToString()}/{Context.NotNullSyncConfig.Id.ToString()}.log"
|
||||
+ $" /p:ExtractAllTableData=false /p:VerifyExtraction=true /SourceServerName:{Context.NotNullSyncConfig.SrcDb.ServerName}"
|
||||
+ $" /SourceDatabaseName:{Context.NotNullSyncConfig.SrcDb.DatebaseName} /SourceUser:{Context.NotNullSyncConfig.SrcDb.User}"
|
||||
+ $" /SourcePassword:{Context.NotNullSyncConfig.SrcDb.Password} /SourceTrustServerCertificate:{Context.NotNullSyncConfig.SrcDb.TrustServerCertificate}"
|
||||
|
@ -343,7 +348,7 @@ public class UploadPackedHelper(LocalSyncServer context)
|
|||
Context
|
||||
.LocalPipe.UploadFile(
|
||||
Context.NotNullSyncConfig.RemoteUrl,
|
||||
$"{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}/{Context.NotNullSyncConfig.Id}.zip",
|
||||
$"{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}.zip",
|
||||
(double current) =>
|
||||
{
|
||||
Context
|
||||
|
|
|
@ -100,13 +100,13 @@ public class DiffFileHelper(RemoteSyncServer context)
|
|||
}
|
||||
else
|
||||
{
|
||||
var nd = e.LocalDirInfo.Clone();
|
||||
nd.ResetRootPath(
|
||||
Context.NotNullSyncConfig.LocalRootPath,
|
||||
Context.NotNullSyncConfig.RemoteRootPath
|
||||
);
|
||||
var nd = new Dir
|
||||
{
|
||||
Path = Context.NotNullSyncConfig.RemoteRootPath + e.DirPath,
|
||||
Children = []
|
||||
};
|
||||
nd.ExtractInfo(e.CherryPicks, e.Excludes);
|
||||
e.DiffDirInfo = nd.Diff(nd);
|
||||
e.DiffDirInfo = e.LocalDirInfo.Diff(nd);
|
||||
e.RemoteDirInfo = nd;
|
||||
diffConfigs.Add(
|
||||
new DirFileConfig { DiffDirInfo = e.DiffDirInfo, DirPath = e.DirPath }
|
||||
|
|
|
@ -11,7 +11,7 @@ public class PipeSeed : IDisposable
|
|||
TestConfig = new Config
|
||||
{
|
||||
Name = "Test",
|
||||
RemoteUrl = "D:/FileSyncTest",
|
||||
RemoteUrl = "D:/FileSyncTest/dtemp",
|
||||
RemotePwd = "t123",
|
||||
IsDeployDb = true,
|
||||
IsDeployProject = true,
|
||||
|
|
|
@ -13,46 +13,48 @@ public class PipeTest
|
|||
[Fact]
|
||||
public async void TestCase()
|
||||
{
|
||||
// var p1 = new TestPipe(false, "1");
|
||||
// var x = Task.Run(async () =>
|
||||
// {
|
||||
// var rs = p1.Work(
|
||||
// (byte[] b) =>
|
||||
// {
|
||||
// Console.WriteLine(b);
|
||||
// return true;
|
||||
// }
|
||||
// );
|
||||
// await foreach (var r in rs)
|
||||
// {
|
||||
// Console.WriteLine(r);
|
||||
// }
|
||||
// });
|
||||
// //await p1.Close("sdf");
|
||||
// //await x;
|
||||
// var p2 = new TestPipe(false, "2");
|
||||
// p1.Other = p2;
|
||||
// p2.Other = p1;
|
||||
// var p3 = new TestPipe(true, "3");
|
||||
// var p4 = new TestPipe(true, "4");
|
||||
// p3.Other = p4;
|
||||
// p4.Other = p3;
|
||||
// RemoteSyncServerFactory.NamePwd = [new Tuple<string, string>("Test", "t123")];
|
||||
// var lf = new LocalSyncServerFactory();
|
||||
// lf.CreateLocalSyncServer(p2, "Test", p3);
|
||||
// var rf = new RemoteSyncServerFactory();
|
||||
// rf.CreateRemoteSyncServer(p4, "Test");
|
||||
// var starter = new SyncMsg
|
||||
// {
|
||||
// Body = JsonSerializer.Serialize(new PipeSeed().TestConfig),
|
||||
// Type = SyncMsgType.General,
|
||||
// Step = SyncProcessStep.Connect
|
||||
// };
|
||||
// await p1.SendMsg(starter);
|
||||
var p1 = new TestPipe(false, "1");
|
||||
var x = Task.Run(async () =>
|
||||
{
|
||||
var rs = p1.Work(
|
||||
(byte[] b) =>
|
||||
{
|
||||
Console.WriteLine(b);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
await foreach (var r in rs)
|
||||
{
|
||||
Console.WriteLine(r);
|
||||
}
|
||||
});
|
||||
//await p1.Close("sdf");
|
||||
//await x;
|
||||
// if (p1.ErrResult != null)
|
||||
// {
|
||||
// Assert.Fail(p1.ErrResult);
|
||||
// }
|
||||
var p2 = new TestPipe(false, "2");
|
||||
p1.Other = p2;
|
||||
p2.Other = p1;
|
||||
var p3 = new TestPipe(true, "3");
|
||||
var p4 = new TestPipe(true, "4");
|
||||
p3.Other = p4;
|
||||
p4.Other = p3;
|
||||
LocalSyncServer.TempRootFile = "D:/FileSyncTest/stemp";
|
||||
RemoteSyncServer.TempRootFile = "D:/FileSyncTest/dtemp";
|
||||
RemoteSyncServerFactory.NamePwd = [new Tuple<string, string>("Test", "t123")];
|
||||
var lf = new LocalSyncServerFactory();
|
||||
lf.CreateLocalSyncServer(p2, "Test", p3);
|
||||
var rf = new RemoteSyncServerFactory();
|
||||
rf.CreateRemoteSyncServer(p4, "Test");
|
||||
var starter = new SyncMsg
|
||||
{
|
||||
Body = JsonSerializer.Serialize(new PipeSeed().TestConfig),
|
||||
Type = SyncMsgType.General,
|
||||
Step = SyncProcessStep.Connect
|
||||
};
|
||||
await p1.SendMsg(starter);
|
||||
await x;
|
||||
if (p1.ErrResult != null)
|
||||
{
|
||||
Assert.Fail(p1.ErrResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Common;
|
||||
using RemoteServer;
|
||||
|
||||
namespace ServerTest
|
||||
{
|
||||
|
@ -25,14 +26,19 @@ namespace ServerTest
|
|||
}
|
||||
|
||||
public override async Task UploadFile(
|
||||
string filePath,
|
||||
string dst,
|
||||
string filePath,
|
||||
Func<double, bool> progressCb
|
||||
)
|
||||
{
|
||||
dst = Path.Combine(RemoteSyncServer.TempRootFile, Path.GetFileName(filePath));
|
||||
await Task.Run(() =>
|
||||
{
|
||||
progressCb(100);
|
||||
//if (!Directory.Exists(dst))
|
||||
//{
|
||||
// Directory.CreateDirectory(dst);
|
||||
//}
|
||||
System.IO.File.Copy(filePath, dst, true);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue