From d572e9466eeebc527abd88457257c7925745d346 Mon Sep 17 00:00:00 2001 From: zerlei <1445089819@qq.com> Date: Fri, 27 Sep 2024 18:41:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E5=B0=86=E8=A6=81?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9A=84=E6=97=A7=E6=96=87=E4=BB=B6=E5=A4=87?= =?UTF-8?q?=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. websocket pipe测试 2. 需要更多测试 3. 需要前端操作页面 --- Server/Common/DirExtension.cs | 12 ++++++--- Server/Common/FileDirOp.cs | 36 ++++++++++++++++++++++++++- Server/LocalServer/LocalSyncServer.cs | 3 ++- Server/LocalServer/Program.cs | 7 +++--- Server/LocalServer/StateHelper.cs | 4 +++ Server/LocalServer/appsettings.json | 2 +- Server/ServerTest/PipeSeed.cs | 4 +-- Server/ServerTest/PipeTest.cs | 4 +-- 8 files changed, 59 insertions(+), 13 deletions(-) diff --git a/Server/Common/DirExtension.cs b/Server/Common/DirExtension.cs index 8e429df..8d9d27b 100644 --- a/Server/Common/DirExtension.cs +++ b/Server/Common/DirExtension.cs @@ -259,15 +259,21 @@ public static class DirExtension { if (child is Dir childDir) { - fileDirOp.DirCreate(childDir, false); - f(childDir, fileDirOp); + if (childDir.NextOp != NextOpType.Del) + { + fileDirOp.DirCreate(childDir, false); + f(childDir, fileDirOp); + } } } else { if (child is File childFile) { - fileDirOp.FileCreate(child.FormatedPath, childFile.MTime); + if (childFile.NextOp != NextOpType.Del) + { + fileDirOp.FileCreate(child.FormatedPath, childFile.MTime); + } } else { diff --git a/Server/Common/FileDirOp.cs b/Server/Common/FileDirOp.cs index d4dcb07..68cd78e 100644 --- a/Server/Common/FileDirOp.cs +++ b/Server/Common/FileDirOp.cs @@ -167,6 +167,37 @@ public class FileDirOpForPack(string srcRootPath, string dstRootPath) : FileDirO public class FileDirOpForUnpack(string srcRootPath, string dstRootPath) : FileDirOpStra { + /// + /// 备份文件 + /// + /// 源文件位置,将要删除的或者替换的 + private void BacklogFile(string absolutePath) + { + var dstPath = absolutePath.Replace(DstRootPath, SrcRootPath); + + var dstDirPath = + Path.GetDirectoryName(dstPath) ?? throw new NullReferenceException("父路径不存在!"); + if (!Directory.Exists(dstDirPath)) + { + Directory.CreateDirectory(dstDirPath); + } + + //文件时间不会更改 + System.IO.File.Move(absolutePath, dstPath + ".bak", true); + } + + private void BacklogDir(string absolutePath) + { + var dstPath = absolutePath.Replace(DstRootPath, SrcRootPath); + var dstDirPath = + Path.GetDirectoryName(dstPath) ?? throw new NullReferenceException("父路径不存在!"); + if (!Directory.Exists(dstDirPath)) + { + Directory.CreateDirectory(dstDirPath); + } + Directory.Move(absolutePath, dstPath); + } + /// /// 解压缩,必须首先调用 /// @@ -273,17 +304,20 @@ public class FileDirOpForUnpack(string srcRootPath, string dstRootPath) : FileDi public override void FileModify(string absolutePath, DateTime mtime) { + BacklogFile(absolutePath); this.FileCreate(absolutePath, mtime); } public override void FileDel(string absolutePath) { + BacklogFile(absolutePath); System.IO.File.Delete(absolutePath); } public override void DirDel(Dir dir, bool IsRecursion = true) { - System.IO.Directory.Delete(dir.FormatedPath, IsRecursion); + BacklogDir(dir.FormatedPath); + //System.IO.Directory.Delete(dir.FormatedPath, IsRecursion); } } diff --git a/Server/LocalServer/LocalSyncServer.cs b/Server/LocalServer/LocalSyncServer.cs index d4e524a..fecf825 100644 --- a/Server/LocalServer/LocalSyncServer.cs +++ b/Server/LocalServer/LocalSyncServer.cs @@ -8,7 +8,8 @@ public class LocalSyncServer #pragma warning disable CA2211 // Non-constant fields should not be visible public static string TempRootFile = "C:/TempPack"; public static string SqlPackageAbPath = "sqlpackage"; - public static string MsdeployAbPath = "msdeploy"; + + //public static string MsdeployAbPath = "msdeploy"; //与visual studio 匹配的Msbuild 路径。在vs 中打开power shell 命令行,使用 `(get-Command -Name msbuild).Source ` public static string MSBuildAbPath = "MSBuild"; diff --git a/Server/LocalServer/Program.cs b/Server/LocalServer/Program.cs index e3840d5..44cae58 100644 --- a/Server/LocalServer/Program.cs +++ b/Server/LocalServer/Program.cs @@ -11,9 +11,10 @@ IConfiguration _configuration = configurationBuilder.Build(); LocalSyncServer.TempRootFile = _configuration["TempDir"] ?? "C:/TempPack"; LocalSyncServer.SqlPackageAbPath = _configuration["SqlPackageAbPath"] ?? "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe"; -LocalSyncServer.MsdeployAbPath = - _configuration["MsdeployAbPath"] - ?? "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe"; + +//LocalSyncServer.MsdeployAbPath = +// _configuration["MsdeployAbPath"] +// ?? "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe"; // Add services to the container. diff --git a/Server/LocalServer/StateHelper.cs b/Server/LocalServer/StateHelper.cs index b5895cd..325fcc9 100644 --- a/Server/LocalServer/StateHelper.cs +++ b/Server/LocalServer/StateHelper.cs @@ -260,6 +260,7 @@ public class DiffFileAndPackHelper(LocalSyncServer context) }; e.LocalDirInfo.ExtractInfo(e.CherryPicks, e.Excludes); }); + //将配置信息发送到remoteServer var options = new JsonSerializerOptions { WriteIndented = true }; Context @@ -286,6 +287,9 @@ public class DiffFileAndPackHelper(LocalSyncServer context) Context.NotNullSyncConfig.LocalRootPath, LocalSyncServer.TempRootFile + "/" + Context.NotNullSyncConfig.Id.ToString() ); + Directory.CreateDirectory( + LocalSyncServer.TempRootFile + "/" + Context.NotNullSyncConfig.Id.ToString() + ); Context.NotNullSyncConfig.DirFileConfigs.ForEach(e => { if (e.DiffDirInfo != null) diff --git a/Server/LocalServer/appsettings.json b/Server/LocalServer/appsettings.json index 19d036b..d8da422 100644 --- a/Server/LocalServer/appsettings.json +++ b/Server/LocalServer/appsettings.json @@ -8,6 +8,6 @@ "AllowedHosts": "*", "TempDir": "D:/TempPack", "SqlPackageAbPath": "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe", - "MsdeployAbPath": "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe", + //"MsdeployAbPath": "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe", "MSBuildAbPath": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\amd64\\MSBuild.exe" } diff --git a/Server/ServerTest/PipeSeed.cs b/Server/ServerTest/PipeSeed.cs index fc8125d..e9b77a9 100644 --- a/Server/ServerTest/PipeSeed.cs +++ b/Server/ServerTest/PipeSeed.cs @@ -13,8 +13,8 @@ public class PipeSeed : IDisposable Name = "Test", RemoteUrl = "D:/FileSyncTest/dtemp", RemotePwd = "t123", - IsDeployDb = true, - IsDeployProject = true, + IsDeployDb = false, + IsDeployProject = false, LocalProjectAbsolutePath = "D:/git/HMES-H7-HNFY/HMES-H7-HNFYMF/HMES-H7-HNFYMF.WEB", LocalRootPath = "D:/FileSyncTest/src", diff --git a/Server/ServerTest/PipeTest.cs b/Server/ServerTest/PipeTest.cs index c209ab6..2769e1b 100644 --- a/Server/ServerTest/PipeTest.cs +++ b/Server/ServerTest/PipeTest.cs @@ -44,8 +44,8 @@ public class PipeTest p4.Other = p3; LocalSyncServer.TempRootFile = "D:/FileSyncTest/stemp"; RemoteSyncServer.SqlPackageAbPath = "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe"; - LocalSyncServer.MsdeployAbPath = - "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe"; + //LocalSyncServer.MsdeployAbPath = + // "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe"; LocalSyncServer.SqlPackageAbPath = "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe"; LocalSyncServer.MSBuildAbPath = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\amd64\\MSBuild.exe";