From fa64f0c6d5cfc9aa6162c0a58c4a57a8be1402c3 Mon Sep 17 00:00:00 2001 From: ZhaoLei Date: Tue, 29 Oct 2024 18:08:34 +0800 Subject: [PATCH] =?UTF-8?q?fix&feat:=20=20c#=20=E4=B8=8A=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=AD=98=E5=9C=A8=E6=9C=80=E5=A4=A7=E9=99=90=E5=88=B6?= =?UTF-8?q?=E3=80=82=E6=B6=88=E6=81=AF=E4=BC=98=E5=8C=96=E5=92=8C=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E7=8E=B0=E5=9C=A8=E5=87=8F=E5=B0=91=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BD=BF=E7=94=A8=E6=97=B6=E7=9A=84=E6=8B=85=E5=BF=83?= =?UTF-8?q?=EF=BC=8C=E5=AE=83=E6=9B=B4=E5=8A=A0=E4=BA=BA=E6=80=A7=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ```csharp // 使用默认的Kestrel 服务器部署,将默认限制最大文件的上传,使用这个取消限制 [DisableRequestSizeLimit] [HttpPost("/UploadFile")] public async Task UploadFile(IFormFile file) { ``` --- Server/Common/Message.cs | 6 +- Server/Common/ProgressStreamContent.cs | 4 +- Server/LocalServer/StateHelper.cs | 8 ++- Tool/JsScript/release.js | 89 ++++++++++++++++-------- Tool/webtool/src/App.vue | 96 ++++++++++++++++++++++---- Tool/webtool/src/connect.js | 4 +- Tool/webtool/src/style.css | 2 +- 7 files changed, 161 insertions(+), 48 deletions(-) diff --git a/Server/Common/Message.cs b/Server/Common/Message.cs index 9c0c93b..6c3d73c 100644 --- a/Server/Common/Message.cs +++ b/Server/Common/Message.cs @@ -4,8 +4,12 @@ public enum SyncMsgType { Error = 0, General = 1, + + //Ϣ Process = 2, - // DirFilePack = 3 + + //ļչʾϢ + DirFileDiff = 3 } public enum SyncProcessStep diff --git a/Server/Common/ProgressStreamContent.cs b/Server/Common/ProgressStreamContent.cs index 4130261..7361c8a 100644 --- a/Server/Common/ProgressStreamContent.cs +++ b/Server/Common/ProgressStreamContent.cs @@ -8,10 +8,10 @@ using System.Threading; namespace Common; public class ProgressStreamContent(Stream stream_, IProgress progress) - : StreamContent(stream_, 1024 * 1024) + : StreamContent(stream_, 5 * 1024 * 1024) { private readonly Stream FileStream = stream_; - private readonly int BufferSize = 1024 * 1024; + private readonly int BufferSize = 5 * 1024 * 1024; private readonly IProgress Progress = progress; protected override async Task SerializeToStreamAsync( diff --git a/Server/LocalServer/StateHelper.cs b/Server/LocalServer/StateHelper.cs index 0bc1f49..4a85eec 100644 --- a/Server/LocalServer/StateHelper.cs +++ b/Server/LocalServer/StateHelper.cs @@ -286,6 +286,11 @@ public class DiffFileAndPackHelper(LocalSyncServer context) Context.NotNullSyncConfig.LocalRootPath ); e.DiffDirInfo.WriteByThisInfo(PackOp); + Context + .LocalPipe.SendMsg( + CreateMsg(JsonSerializer.Serialize(e.DiffDirInfo), SyncMsgType.DirFileDiff) + ) + .Wait(); } }); Context.LocalPipe.SendMsg(CreateMsg("文件差异比较成功!")).Wait(); @@ -318,6 +323,7 @@ public class DeployMSSqlHelper(LocalSyncServer context) } else { + Context.LocalPipe.SendMsg(CreateMsg("正在打包数据库...")).Wait(); var arguments = $" /Action:Extract /TargetFile:{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id.ToString()}/{Context.NotNullSyncConfig.Id.ToString()}.dacpac" // 不要log file 了 @@ -387,7 +393,7 @@ public class UploadPackedHelper(LocalSyncServer context) $"{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}.zip", (double current) => { - //这里可能需要降低获取上传进度的频率 + // 每上传1Mb 更新一下进度 Context .LocalPipe.SendMsg(CreateMsg(current.ToString(), SyncMsgType.Process)) .Wait(); diff --git a/Tool/JsScript/release.js b/Tool/JsScript/release.js index 2ce4a76..1feb3f0 100644 --- a/Tool/JsScript/release.js +++ b/Tool/JsScript/release.js @@ -6,21 +6,21 @@ import WebSocket from "ws"; const LocalHost = "127.0.0.1"; const config = { //发布的名称,每个项目具有唯一的一个名称 - Name: "FYMF", - RemotePwd: "FYMF", + Name: "Test", + RemotePwd: "t123", //远程服务器地址,也就是发布的目的地,它是正式环境 - RemoteUrl: "127.0.0.1:8007", + RemoteUrl: "127.0.0.1:6819", //是否发布数据库 sqlserver IsDeployDb: true, //是否发布前重新构建项目 - IsDeployProject: false, + IsDeployProject: true, //项目地址 LocalProjectAbsolutePath: "D:/git/HMES-H7-HNFY/HMES-H7-HNFYMF/HMES-H7-HNFYMF.WEB", //源文件目录地址,是要发布的文件根目录,它是绝对路径,!执行发布时将发布到这个目录! LocalRootPath: "D:/FileSyncTest/src", //目标文件目录地址,也就是部署服务的机器上的项目文件根目录,它是绝对路径 - RemoteRootPath: "D:/FYMF", + RemoteRootPath: "D:/FileSyncTest/dst", //源数据库配置 SqlServer,将会同步数据库的结构 SrcDb: { //Host @@ -44,7 +44,7 @@ const config = { ServerName: "127.0.0.1", DatabaseName: "HMES_H7_HNFYMF", User: "sa", - Password: "Yuanmo520...", + Password: "0", TrustServerCertificate: "True", }, //子目录配置,每个子目录都有自己不同的发布策略,它是相对路径,即相对于LocalRootPath和RemoteRootPath(注意 '/',这将拼成一个完整的路径),文件数据依此进行, @@ -82,20 +82,20 @@ let IsSuccess = false; * 在新行打印错误信息 */ function PrintErrInNewLine(str) { - process.stdout.write("\n"); var chunk = chalk["red"]("[错误]: "); process.stdout.write(chunk); process.stdout.write(str); + process.stdout.write("\n"); } /** * 在新行打印成功信息 */ function PrintSuccessInNewLine(str) { - process.stdout.write("\n"); var chunk = chalk["green"]("[成功]: "); process.stdout.write(chunk); process.stdout.write(str); + process.stdout.write("\n"); } /** @@ -111,8 +111,11 @@ function PrintCloseNewLine(str) { /** * 在当前行打印一般信息,打印此行信息之前会清除当前行 */ -function PrintGeneralInCurrentLine(str) { - process.stdout.write(`\r${str}`); +function PrintProcessLine(str) { + var chunk = chalk["yellow"]("[上传进度]: "); + process.stdout.write(chunk); + process.stdout.write(`${str}`); + process.stdout.write("\n"); } //#endregion @@ -122,26 +125,52 @@ function PrintGeneralInCurrentLine(str) { /** * 1-n. localServer 工作,此处只展示信息 */ -let ws = null; -function MsgCb(MsgIt) { - if (MsgIt.Type == 2) { - PrintGeneralInCurrentLine(MsgIt.Body); - } else { - if (MsgIt.Step <= 6) { - PrintSuccessInNewLine(`(${MsgIt.Step}/6) ${MsgIt.Body}`); - if (MsgIt.Step == 6) { - if (MsgIt.Body == "发布完成!") { - IsSuccess = true; - ws.close(); - } - } - } else if (MsgIt == 7) { - PrintErrInNewLine(MsgIt.Body); - } else { - PrintCloseNewLine("(关闭)" + MsgIt.Body); - } + +function getOpEmoj(Op) { + switch (Op) { + case 0: + return "➕"; + case 1: + return "Ⓜ️"; + case 2: + return "❌"; + default: + return "🚀"; } } +let ws = null; +function MsgCb(MsgIt) { + if (MsgIt.Step <= 6) { + if (MsgIt.Type == 2) { + PrintProcessLine(`(${MsgIt.Step}/6) ${MsgIt.Body}`); + if (parseFloat(MsgIt.Body) == 1) { + var chunk = chalk["green"]("[上传成功]"); + process.stdout.write(chunk); + process.stdout.write("\n"); + } + } else if (MsgIt.Type == 3) { + var it = JSON.parse(MsgIt.Body); + it.Children.forEach((e) => { + PrintSuccessInNewLine( + `(${MsgIt.Step}/6) [${getOpEmoj(e.NextOp)}] ${e.FormatedPath}` + ); + }); + } else { + PrintSuccessInNewLine(`(${MsgIt.Step}/6) ${MsgIt.Body}`); + } + if (MsgIt.Step == 6) { + if (MsgIt.Body == "发布完成!") { + IsSuccess = true; + ws.close(); + } + } + } else if (MsgIt.Step == 7) { + PrintErrInNewLine(MsgIt.Body); + } else { + PrintCloseNewLine("(关闭)" + MsgIt.Body); + } +} + //#endregion async function connectWebSocket() { return new Promise((resolve, reject) => { @@ -183,6 +212,10 @@ async function connectWebSocket() { } (async function main() { try { + // for(var i = 0;i<10;++i) { + // PrintGeneralInCurrentLine(`${i}`) + // } + // PrintSuccessInNewLine("11") await connectWebSocket(); // console.log('WebSocket has closed'); // The script will wait here until the WebSocket connection is closed diff --git a/Tool/webtool/src/App.vue b/Tool/webtool/src/App.vue index e3e4764..b057daa 100644 --- a/Tool/webtool/src/App.vue +++ b/Tool/webtool/src/App.vue @@ -12,26 +12,27 @@ const options = ref({ tabSize: 2, }) +let IsSuccess = false let Pipe = null const Msgs = ref([]) const code = ref(` config = { //发布的名称,每个项目具有唯一的一个名称 - Name: "FYMF", - RemotePwd: "FYMF", + Name: "Test", + RemotePwd: "t123", //远程服务器地址,也就是发布的目的地,它是正式环境 - RemoteUrl: "127.0.0.1:8007", + RemoteUrl: "127.0.0.1:6819", //是否发布数据库 sqlserver IsDeployDb: true, //是否发布前重新构建项目 - IsDeployProject: false, + IsDeployProject: true, //项目地址 LocalProjectAbsolutePath: "D:/git/HMES-H7-HNFY/HMES-H7-HNFYMF/HMES-H7-HNFYMF.WEB", //源文件目录地址,是要发布的文件根目录,它是绝对路径,!执行发布时将发布到这个目录! LocalRootPath: "D:/FileSyncTest/src", //目标文件目录地址,也就是部署服务的机器上的项目文件根目录,它是绝对路径 - RemoteRootPath: "D:/FYMF", + RemoteRootPath: "D:/FileSyncTest/dst", //源数据库配置 SqlServer,将会同步数据库的结构 SrcDb: { //Host @@ -55,7 +56,7 @@ config = { ServerName: "127.0.0.1", DatabaseName: "HMES_H7_HNFYMF", User: "sa", - Password: "Yuanmo520...", + Password: "0", TrustServerCertificate: "True", }, //子目录配置,每个子目录都有自己不同的发布策略,它是相对路径,即相对于LocalRootPath和RemoteRootPath(注意 '/',这将拼成一个完整的路径),文件数据依此进行, @@ -86,16 +87,40 @@ config = { }; `) var CStatus = ref('None') +function getOpEmoj(Op) { + switch (Op) { + case 0: + return "➕"; + case 1: + return "Ⓜ️"; + case 2: + return "❌"; + default: + return "🚀"; + } +} function publishCB(MsgIt) { - + console.log(MsgIt) if (MsgIt.Type == 2) { Msgs.value[Msgs.value.length - 1] = MsgIt - } else { + } else if (MsgIt.Type == 3) { + var it = JSON.parse(MsgIt.Body); + it.Children.forEach((e) => { + Msgs.value.push({ + Step: MsgIt.Step, + Type: MsgIt.Type, + Body: `[${getOpEmoj(e.NextOp)}] ${e.FormatedPath}` + }) + + }); + } + else { Msgs.value.push(MsgIt) } if (MsgIt.Step == 6) { if (MsgIt.Body == "发布完成!") { CStatus.value = 'Success' + IsSuccess = true Pipe.ClosePipe() dialogShow("正确:发布完成!") } @@ -154,7 +179,7 @@ onMounted(() => { } }) -const dMsg = ref('') +const dMsg = ref('') function dialogClose() { document.getElementById('dialog').close() } @@ -162,6 +187,46 @@ function dialogShow(msg) { dMsg.value = msg document.getElementById('dialog').showModal() } +function getColor(msg) { + if (msg.Step >= 7) { + if (IsSuccess) { + return "green" + } + return "red" + } else if (msg.Type == 2) { + return "yellow" + } else { + return "green" + } +} +function getTitle(msg) { + + var x = getColor(msg) + switch (x) { + case "green": + return "[成功]" + break; + case "red": + return "[失败]" + break; + case "yellow": + return "[上传进度]" + break; + + default: + break; + } + +} +function getStep(msg) { + if (msg.Step > 6) { + return "" + } + return `(${msg.Step}/6)` +} +function getBody(msg) { + return msg.Body +}