增加在本地电脑发布
parent
e815e5f705
commit
a5cbcb035c
|
@ -172,13 +172,13 @@
|
||||||
//
|
//
|
||||||
// tabControl1
|
// tabControl1
|
||||||
//
|
//
|
||||||
tabControl1.Controls.Add(tabPage1);
|
|
||||||
tabControl1.Controls.Add(tabPage2);
|
tabControl1.Controls.Add(tabPage2);
|
||||||
|
tabControl1.Controls.Add(tabPage1);
|
||||||
tabControl1.Location = new Point(12, 318);
|
tabControl1.Location = new Point(12, 318);
|
||||||
tabControl1.Name = "tabControl1";
|
tabControl1.Name = "tabControl1";
|
||||||
tabControl1.SelectedIndex = 0;
|
tabControl1.SelectedIndex = 0;
|
||||||
tabControl1.Size = new Size(796, 764);
|
tabControl1.Size = new Size(796, 764);
|
||||||
tabControl1.TabIndex = 4;
|
tabControl1.TabIndex = 2;
|
||||||
//
|
//
|
||||||
// tabPage1
|
// tabPage1
|
||||||
//
|
//
|
||||||
|
@ -189,7 +189,7 @@
|
||||||
tabPage1.Padding = new Padding(3);
|
tabPage1.Padding = new Padding(3);
|
||||||
tabPage1.Size = new Size(788, 734);
|
tabPage1.Size = new Size(788, 734);
|
||||||
tabPage1.TabIndex = 0;
|
tabPage1.TabIndex = 0;
|
||||||
tabPage1.Text = "服务";
|
tabPage1.Text = "服务相关操作";
|
||||||
tabPage1.UseVisualStyleBackColor = true;
|
tabPage1.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// groupBox4
|
// groupBox4
|
||||||
|
@ -414,7 +414,7 @@
|
||||||
groupBox6.Controls.Add(selectPublishFilePathBtn);
|
groupBox6.Controls.Add(selectPublishFilePathBtn);
|
||||||
groupBox6.Controls.Add(publishFileTBox);
|
groupBox6.Controls.Add(publishFileTBox);
|
||||||
groupBox6.Controls.Add(label7);
|
groupBox6.Controls.Add(label7);
|
||||||
groupBox6.Location = new Point(6, 315);
|
groupBox6.Location = new Point(3, 292);
|
||||||
groupBox6.Name = "groupBox6";
|
groupBox6.Name = "groupBox6";
|
||||||
groupBox6.Size = new Size(776, 413);
|
groupBox6.Size = new Size(776, 413);
|
||||||
groupBox6.TabIndex = 43;
|
groupBox6.TabIndex = 43;
|
||||||
|
@ -446,9 +446,9 @@
|
||||||
label8.AutoSize = true;
|
label8.AutoSize = true;
|
||||||
label8.Location = new Point(14, 245);
|
label8.Location = new Point(14, 245);
|
||||||
label8.Name = "label8";
|
label8.Name = "label8";
|
||||||
label8.Size = new Size(360, 17);
|
label8.Size = new Size(384, 17);
|
||||||
label8.TabIndex = 50;
|
label8.TabIndex = 50;
|
||||||
label8.Text = "方式二: 后端发布程序文件夹(自己打成压缩包,上传然后发布)";
|
label8.Text = "方式二: 后端发布程序文件夹(程序自动打成压缩包,上传然后发布)";
|
||||||
//
|
//
|
||||||
// publishFolderTBox
|
// publishFolderTBox
|
||||||
//
|
//
|
||||||
|
@ -499,15 +499,15 @@
|
||||||
label7.AutoSize = true;
|
label7.AutoSize = true;
|
||||||
label7.Location = new Point(27, 65);
|
label7.Location = new Point(27, 65);
|
||||||
label7.Name = "label7";
|
label7.Name = "label7";
|
||||||
label7.Size = new Size(276, 17);
|
label7.Size = new Size(368, 17);
|
||||||
label7.TabIndex = 44;
|
label7.TabIndex = 44;
|
||||||
label7.Text = "方式一: 前端发布选择html | 后端发布选择压缩包";
|
label7.Text = "方式一: 前端发布选择html | 后端发布选择压缩包 (上传后发布)";
|
||||||
//
|
//
|
||||||
// bakConfigSaveBtn
|
// bakConfigSaveBtn
|
||||||
//
|
//
|
||||||
bakConfigSaveBtn.Location = new Point(160, 186);
|
bakConfigSaveBtn.Location = new Point(160, 186);
|
||||||
bakConfigSaveBtn.Name = "bakConfigSaveBtn";
|
bakConfigSaveBtn.Name = "bakConfigSaveBtn";
|
||||||
bakConfigSaveBtn.Size = new Size(187, 53);
|
bakConfigSaveBtn.Size = new Size(128, 40);
|
||||||
bakConfigSaveBtn.TabIndex = 42;
|
bakConfigSaveBtn.TabIndex = 42;
|
||||||
bakConfigSaveBtn.Text = "备份配置保存";
|
bakConfigSaveBtn.Text = "备份配置保存";
|
||||||
bakConfigSaveBtn.UseVisualStyleBackColor = true;
|
bakConfigSaveBtn.UseVisualStyleBackColor = true;
|
||||||
|
@ -517,7 +517,7 @@
|
||||||
//
|
//
|
||||||
startBakBtn.Location = new Point(494, 186);
|
startBakBtn.Location = new Point(494, 186);
|
||||||
startBakBtn.Name = "startBakBtn";
|
startBakBtn.Name = "startBakBtn";
|
||||||
startBakBtn.Size = new Size(213, 53);
|
startBakBtn.Size = new Size(128, 40);
|
||||||
startBakBtn.TabIndex = 6;
|
startBakBtn.TabIndex = 6;
|
||||||
startBakBtn.Text = "开始备份";
|
startBakBtn.Text = "开始备份";
|
||||||
startBakBtn.UseVisualStyleBackColor = true;
|
startBakBtn.UseVisualStyleBackColor = true;
|
||||||
|
@ -616,8 +616,8 @@
|
||||||
AutoScaleDimensions = new SizeF(7F, 17F);
|
AutoScaleDimensions = new SizeF(7F, 17F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1488, 1094);
|
ClientSize = new Size(1488, 1094);
|
||||||
Controls.Add(groupBox5);
|
|
||||||
Controls.Add(tabControl1);
|
Controls.Add(tabControl1);
|
||||||
|
Controls.Add(groupBox5);
|
||||||
Controls.Add(groupBox3);
|
Controls.Add(groupBox3);
|
||||||
Controls.Add(groupBox1);
|
Controls.Add(groupBox1);
|
||||||
Name = "PublishForm";
|
Name = "PublishForm";
|
||||||
|
|
|
@ -21,6 +21,8 @@ using System.Management;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
||||||
using System.Management.Automation.Host;
|
using System.Management.Automation.Host;
|
||||||
|
using SharpCompress.Common;
|
||||||
|
using System.IO.Compression;
|
||||||
|
|
||||||
namespace PublishSite
|
namespace PublishSite
|
||||||
{
|
{
|
||||||
|
@ -679,14 +681,14 @@ namespace PublishSite
|
||||||
|
|
||||||
private async void sshVuePublishBtn_Click(object sender, EventArgs e)
|
private async void sshVuePublishBtn_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
var desTinationFoder = jObjectCofig["BackUp"]["VuePublishFolder"].ToString();
|
||||||
|
|
||||||
|
|
||||||
sshVuePublishBtn.Enabled = false;
|
sshVuePublishBtn.Enabled = false;
|
||||||
var filePath = publishFileTBox.Text;
|
var filePath = publishFileTBox.Text;
|
||||||
|
|
||||||
var realName = Path.GetFileName(filePath);
|
var realName = Path.GetFileName(filePath);
|
||||||
|
|
||||||
var desTinationFoder = jObjectCofig["BackUp"]["VuePublishFolder"].ToString();
|
|
||||||
|
|
||||||
var storeTempName = $"{Guid.NewGuid()}_{realName}";
|
var storeTempName = $"{Guid.NewGuid()}_{realName}";
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
|
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
|
||||||
|
@ -695,7 +697,8 @@ namespace PublishSite
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WinformLog($"开始上传前端部署文件{realName}...");
|
|
||||||
|
WinformLog($"开始上传前端部署文件{Path.GetFileName(filePath)}...");
|
||||||
|
|
||||||
|
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
|
@ -758,23 +761,163 @@ namespace PublishSite
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
WinformLog($"前端你发布结束");
|
||||||
|
|
||||||
sshVuePublishBtn.Enabled = true;
|
sshVuePublishBtn.Enabled = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sshNetCorePublishBtn_Click(object sender, EventArgs e)
|
private async void sshNetCorePublishBtn_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
var binPath = jObjectCofig["DefaultService"]["BinPath"].ToString();
|
||||||
|
|
||||||
|
var desTinationFoder = Path.GetDirectoryName(binPath);
|
||||||
|
|
||||||
|
sshNetCorePublishBtn.Enabled = false;
|
||||||
var filePath = publishFileTBox.Text;
|
var filePath = publishFileTBox.Text;
|
||||||
|
var realName = Path.GetFileName(filePath);
|
||||||
|
|
||||||
|
var storeTempName = $"{Guid.NewGuid()}_{realName}";
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
|
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
|
||||||
{
|
{
|
||||||
WinformLog($"请选择存在的文件才能开始发布", Color.Red);
|
WinformLog($"请选择存在的文件才能开始发布", Color.Red);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!string.Equals(Path.GetExtension(realName), ".zip", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
WinformLog($"后端远程发布的压缩包必须是zip格式,并且不带目录", Color.Red);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sshNetCorePublishBtn2_Click(object sender, EventArgs e)
|
WinformLog($"开始上传后端部署文件{realName}...");
|
||||||
|
|
||||||
|
await NetCoreZipPublishAsync(filePath, desTinationFoder);
|
||||||
|
|
||||||
|
WinformLog($"后端发布结束");
|
||||||
|
sshNetCorePublishBtn.Enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task NetCoreZipPublishAsync(string filePath, string desTinationFoder)
|
||||||
|
{
|
||||||
|
var realName = Path.GetFileName(filePath);
|
||||||
|
|
||||||
|
var storeTempName = $"{Guid.NewGuid()}_{realName}";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
using (var client = new SshClient(Host, UserName, Password))
|
||||||
|
{
|
||||||
|
client.ConnectionInfo.Encoding = System.Text.Encoding.UTF8;
|
||||||
|
// 连接到远程服务器
|
||||||
|
client.Connect();
|
||||||
|
|
||||||
|
using (var scpClient = new ScpClient(Host, UserName, Password))
|
||||||
|
{
|
||||||
|
scpClient.Connect();
|
||||||
|
|
||||||
|
using (var fileStream = new FileStream(filePath, FileMode.Open))
|
||||||
|
{
|
||||||
|
scpClient.Upload(fileStream, @$"/{storeTempName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
scpClient.Disconnect();
|
||||||
|
|
||||||
|
WinformLog($"上传{realName}结束");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//后端发布,处理压缩包流程
|
||||||
|
|
||||||
|
//停止服务
|
||||||
|
stopServiceBtn_Click(null, null);
|
||||||
|
|
||||||
|
await Task.Delay(2000);
|
||||||
|
|
||||||
|
//解压到发布的目录
|
||||||
|
string expandCommand = $"Expand-Archive -Path '{filePath}' -DestinationPath '{desTinationFoder}' -Force";
|
||||||
|
|
||||||
|
|
||||||
|
using (var cmd = client.CreateCommand($"powershell.exe {expandCommand}"))
|
||||||
|
{
|
||||||
|
WinformLog(expandCommand);
|
||||||
|
|
||||||
|
var output = cmd.Execute();
|
||||||
|
|
||||||
|
WinformLog(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
//启动服务
|
||||||
|
startServiceBtn_Click(null, null);
|
||||||
|
|
||||||
|
|
||||||
|
//删除临时文件
|
||||||
|
|
||||||
|
var delCommand = $" del C:\\{storeTempName}";
|
||||||
|
|
||||||
|
using (var cmd = client.CreateCommand(delCommand))
|
||||||
|
{
|
||||||
|
WinformLog(delCommand);
|
||||||
|
|
||||||
|
var output = cmd.Execute();
|
||||||
|
|
||||||
|
WinformLog(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
WinformLog($"清除零时文件{storeTempName}完成");
|
||||||
|
|
||||||
|
// 断开SSH连接
|
||||||
|
client.Disconnect();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private async void sshNetCorePublishBtn2_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var binPath = jObjectCofig["DefaultService"]["BinPath"].ToString();
|
||||||
|
|
||||||
|
var localSourceFolder = publishFolderTBox.Text;
|
||||||
|
|
||||||
|
var desTinationFoder = Path.GetDirectoryName(binPath);
|
||||||
|
|
||||||
|
sshNetCorePublishBtn2.Enabled = false;
|
||||||
|
|
||||||
|
WinformLog($"开始打包该文件夹下的内容...");
|
||||||
|
|
||||||
|
var filePath = Path.Combine(localSourceFolder, "NetCorePublish.zip");
|
||||||
|
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
{
|
||||||
|
File.Delete(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//将文件夹里的内容打包成压缩包
|
||||||
|
ZipFile.CreateFromDirectory(localSourceFolder, filePath);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
WinformLog("错误:" + ex.Message, Color.Red);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
await NetCoreZipPublishAsync(filePath, desTinationFoder);
|
||||||
|
|
||||||
|
WinformLog($"后端发布结束");
|
||||||
|
sshNetCorePublishBtn2.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -40,14 +40,10 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.PowerShell.Commands.Diagnostics" Version="7.2.10" />
|
|
||||||
<PackageReference Include="Microsoft.PowerShell.Commands.Management" Version="7.2.10" />
|
<PackageReference Include="Microsoft.PowerShell.Commands.Management" Version="7.2.10" />
|
||||||
<PackageReference Include="Microsoft.PowerShell.Commands.Utility" Version="7.2.10" />
|
|
||||||
<PackageReference Include="Microsoft.PowerShell.ConsoleHost" Version="7.2.10" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
<PackageReference Include="Microsoft.WSMan.Management" Version="7.2.10" />
|
<PackageReference Include="SharpCompress" Version="0.33.0" />
|
||||||
<PackageReference Include="SSH.NET" Version="2020.0.2" />
|
<PackageReference Include="SSH.NET" Version="2020.0.2" />
|
||||||
<PackageReference Include="System.Management" Version="6.0.0" />
|
|
||||||
<PackageReference Include="System.Management.Automation" Version="7.2.10" />
|
<PackageReference Include="System.Management.Automation" Version="7.2.10" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -143,8 +143,6 @@ else
|
||||||
};
|
};
|
||||||
MyLog("激活信息读取完毕,开始准备卸载...");
|
MyLog("激活信息读取完毕,开始准备卸载...");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Process process = new Process();
|
Process process = new Process();
|
||||||
process.StartInfo.FileName = "cmd.exe";
|
process.StartInfo.FileName = "cmd.exe";
|
||||||
process.StartInfo.RedirectStandardInput = true;
|
process.StartInfo.RedirectStandardInput = true;
|
||||||
|
@ -211,7 +209,7 @@ else
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
||||||
MyLog("错误:" + ex.Message);
|
MyLog("卸载过程遇到问题:" + ex.Message + " 请检查是否有其他程序占用了相关资源,请确认后再重新卸载。");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue