Test.EIImageViewer
hang 2023-05-05 10:07:35 +08:00
parent 6d62206791
commit 7de5056715
5 changed files with 553 additions and 101 deletions

View File

@ -38,6 +38,9 @@
tabControl1 = new TabControl();
tabPage1 = new TabPage();
groupBox4 = new GroupBox();
serviceConfigSaveBtn = new Button();
servicePortTBox = new TextBox();
label6 = new Label();
serviceNameTBox = new TextBox();
label10 = new Label();
deleteService_Btn = new Button();
@ -55,16 +58,18 @@
label2 = new Label();
startOrStopServiceTbox = new TextBox();
tabPage2 = new TabPage();
bakConfigSaveBtn = new Button();
startBakBtn = new Button();
bakPublishPath = new TextBox();
backPublishPath = new TextBox();
label5 = new Label();
bakDbName = new TextBox();
label4 = new Label();
bakPathTBox = new TextBox();
backPathTBox = new TextBox();
label3 = new Label();
groupBox5 = new GroupBox();
netCorePublishBtn = new Button();
vuePublishBtn = new Button();
openFileDialog1 = new OpenFileDialog();
groupBox1.SuspendLayout();
groupBox3.SuspendLayout();
tabControl1.SuspendLayout();
@ -97,6 +102,7 @@
rb_production.TabIndex = 3;
rb_production.Text = "正式";
rb_production.UseVisualStyleBackColor = true;
rb_production.Click += rb_Env_CheckedChanged;
//
// rb_Verify
//
@ -107,6 +113,7 @@
rb_Verify.TabIndex = 2;
rb_Verify.Text = "验证";
rb_Verify.UseVisualStyleBackColor = true;
rb_Verify.Click += rb_Env_CheckedChanged;
//
// rb_test
//
@ -117,6 +124,7 @@
rb_test.TabIndex = 1;
rb_test.Text = "测试";
rb_test.UseVisualStyleBackColor = true;
rb_test.Click += rb_Env_CheckedChanged;
//
// rb_local
//
@ -129,13 +137,14 @@
rb_local.TabStop = true;
rb_local.Text = "本机";
rb_local.UseVisualStyleBackColor = true;
rb_local.Click += rb_Env_CheckedChanged;
//
// groupBox3
//
groupBox3.Controls.Add(logTBox);
groupBox3.Location = new Point(691, 24);
groupBox3.Name = "groupBox3";
groupBox3.Size = new Size(412, 1048);
groupBox3.Size = new Size(559, 1048);
groupBox3.TabIndex = 3;
groupBox3.TabStop = false;
groupBox3.Text = "日志";
@ -144,7 +153,7 @@
//
logTBox.Location = new Point(23, 21);
logTBox.Name = "logTBox";
logTBox.Size = new Size(359, 1013);
logTBox.Size = new Size(517, 1013);
logTBox.TabIndex = 1;
logTBox.Text = "";
//
@ -172,6 +181,9 @@
//
// groupBox4
//
groupBox4.Controls.Add(serviceConfigSaveBtn);
groupBox4.Controls.Add(servicePortTBox);
groupBox4.Controls.Add(label6);
groupBox4.Controls.Add(serviceNameTBox);
groupBox4.Controls.Add(label10);
groupBox4.Controls.Add(deleteService_Btn);
@ -185,11 +197,37 @@
groupBox4.Controls.Add(selectPathBtn);
groupBox4.Location = new Point(20, 28);
groupBox4.Name = "groupBox4";
groupBox4.Size = new Size(538, 311);
groupBox4.Size = new Size(538, 372);
groupBox4.TabIndex = 40;
groupBox4.TabStop = false;
groupBox4.Text = "服务创建与删除";
//
// serviceConfigSaveBtn
//
serviceConfigSaveBtn.Location = new Point(72, 278);
serviceConfigSaveBtn.Name = "serviceConfigSaveBtn";
serviceConfigSaveBtn.Size = new Size(128, 40);
serviceConfigSaveBtn.TabIndex = 41;
serviceConfigSaveBtn.Text = "服务配置保存";
serviceConfigSaveBtn.UseVisualStyleBackColor = true;
serviceConfigSaveBtn.Click += serviceConfigSaveBtn_Click;
//
// servicePortTBox
//
servicePortTBox.Location = new Point(141, 169);
servicePortTBox.Name = "servicePortTBox";
servicePortTBox.Size = new Size(259, 23);
servicePortTBox.TabIndex = 40;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(71, 172);
label6.Name = "label6";
label6.Size = new Size(32, 17);
label6.TabIndex = 39;
label6.Text = "端口";
//
// serviceNameTBox
//
serviceNameTBox.Location = new Point(140, 33);
@ -209,7 +247,6 @@
//
// deleteService_Btn
//
deleteService_Btn.Enabled = false;
deleteService_Btn.Location = new Point(417, 33);
deleteService_Btn.Name = "deleteService_Btn";
deleteService_Btn.Size = new Size(95, 27);
@ -229,8 +266,7 @@
//
// createService_Btn
//
createService_Btn.Enabled = false;
createService_Btn.Location = new Point(167, 232);
createService_Btn.Location = new Point(276, 278);
createService_Btn.Name = "createService_Btn";
createService_Btn.Size = new Size(128, 40);
createService_Btn.TabIndex = 37;
@ -248,11 +284,10 @@
//
// en_TBox
//
en_TBox.Location = new Point(140, 176);
en_TBox.Location = new Point(141, 214);
en_TBox.Name = "en_TBox";
en_TBox.Size = new Size(259, 23);
en_TBox.TabIndex = 36;
en_TBox.Text = "Development";
//
// label9
//
@ -266,7 +301,7 @@
// label1
//
label1.AutoSize = true;
label1.Location = new Point(71, 176);
label1.Location = new Point(72, 214);
label1.Name = "label1";
label1.Size = new Size(44, 17);
label1.TabIndex = 35;
@ -274,7 +309,6 @@
//
// exePathTbox
//
exePathTbox.Enabled = false;
exePathTbox.Location = new Point(140, 126);
exePathTbox.Name = "exePathTbox";
exePathTbox.Size = new Size(259, 23);
@ -282,7 +316,6 @@
//
// selectPathBtn
//
selectPathBtn.Enabled = false;
selectPathBtn.Location = new Point(417, 125);
selectPathBtn.Name = "selectPathBtn";
selectPathBtn.Size = new Size(95, 27);
@ -297,7 +330,7 @@
groupBox2.Controls.Add(startServiceBtn);
groupBox2.Controls.Add(label2);
groupBox2.Controls.Add(startOrStopServiceTbox);
groupBox2.Location = new Point(20, 391);
groupBox2.Location = new Point(19, 431);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(538, 187);
groupBox2.TabIndex = 39;
@ -306,7 +339,6 @@
//
// stopServiceBtn
//
stopServiceBtn.Enabled = false;
stopServiceBtn.Location = new Point(261, 101);
stopServiceBtn.Name = "stopServiceBtn";
stopServiceBtn.Size = new Size(128, 40);
@ -317,7 +349,6 @@
//
// startServiceBtn
//
startServiceBtn.Enabled = false;
startServiceBtn.Location = new Point(94, 101);
startServiceBtn.Name = "startServiceBtn";
startServiceBtn.Size = new Size(128, 40);
@ -341,16 +372,16 @@
startOrStopServiceTbox.Name = "startOrStopServiceTbox";
startOrStopServiceTbox.Size = new Size(259, 23);
startOrStopServiceTbox.TabIndex = 31;
startOrStopServiceTbox.Text = "EI_Image_Viewer";
//
// tabPage2
//
tabPage2.Controls.Add(bakConfigSaveBtn);
tabPage2.Controls.Add(startBakBtn);
tabPage2.Controls.Add(bakPublishPath);
tabPage2.Controls.Add(backPublishPath);
tabPage2.Controls.Add(label5);
tabPage2.Controls.Add(bakDbName);
tabPage2.Controls.Add(label4);
tabPage2.Controls.Add(bakPathTBox);
tabPage2.Controls.Add(backPathTBox);
tabPage2.Controls.Add(label3);
tabPage2.Location = new Point(4, 26);
tabPage2.Name = "tabPage2";
@ -360,9 +391,19 @@
tabPage2.Text = "备份与发布";
tabPage2.UseVisualStyleBackColor = true;
//
// bakConfigSaveBtn
//
bakConfigSaveBtn.Location = new Point(134, 207);
bakConfigSaveBtn.Name = "bakConfigSaveBtn";
bakConfigSaveBtn.Size = new Size(187, 53);
bakConfigSaveBtn.TabIndex = 42;
bakConfigSaveBtn.Text = "备份配置保存";
bakConfigSaveBtn.UseVisualStyleBackColor = true;
bakConfigSaveBtn.Click += bakConfigSaveBtn_Click;
//
// startBakBtn
//
startBakBtn.Location = new Point(160, 204);
startBakBtn.Location = new Point(375, 207);
startBakBtn.Name = "startBakBtn";
startBakBtn.Size = new Size(213, 53);
startBakBtn.TabIndex = 6;
@ -370,56 +411,53 @@
startBakBtn.UseVisualStyleBackColor = true;
startBakBtn.Click += startBakBtn_Click;
//
// bakPublishPath
// backPublishPath
//
bakPublishPath.Enabled = false;
bakPublishPath.Location = new Point(117, 125);
bakPublishPath.Name = "bakPublishPath";
bakPublishPath.Size = new Size(474, 23);
bakPublishPath.TabIndex = 5;
backPublishPath.Location = new Point(160, 125);
backPublishPath.Name = "backPublishPath";
backPublishPath.Size = new Size(431, 23);
backPublishPath.TabIndex = 5;
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(6, 128);
label5.Location = new Point(61, 125);
label5.Name = "label5";
label5.Size = new Size(104, 17);
label5.Size = new Size(92, 17);
label5.TabIndex = 4;
label5.Text = "发布程序备份路径";
label5.Text = "备份程序根路径";
//
// bakDbName
//
bakDbName.Enabled = false;
bakDbName.Location = new Point(114, 28);
bakDbName.Location = new Point(160, 28);
bakDbName.Name = "bakDbName";
bakDbName.Size = new Size(474, 23);
bakDbName.Size = new Size(428, 23);
bakDbName.TabIndex = 3;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(20, 31);
label4.Location = new Point(85, 28);
label4.Name = "label4";
label4.Size = new Size(68, 17);
label4.TabIndex = 2;
label4.Text = "备份数据库";
//
// bakPathTBox
// backPathTBox
//
bakPathTBox.Enabled = false;
bakPathTBox.Location = new Point(115, 75);
bakPathTBox.Name = "bakPathTBox";
bakPathTBox.Size = new Size(474, 23);
bakPathTBox.TabIndex = 1;
backPathTBox.Location = new Point(160, 75);
backPathTBox.Name = "backPathTBox";
backPathTBox.Size = new Size(429, 23);
backPathTBox.TabIndex = 1;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(6, 79);
label3.Name = "label3";
label3.Size = new Size(92, 17);
label3.Size = new Size(152, 17);
label3.TabIndex = 0;
label3.Text = "数据库备份路径";
label3.Text = "数据库和发布程序备份路径";
//
// groupBox5
//
@ -434,7 +472,6 @@
//
// netCorePublishBtn
//
netCorePublishBtn.Enabled = false;
netCorePublishBtn.Location = new Point(351, 50);
netCorePublishBtn.Name = "netCorePublishBtn";
netCorePublishBtn.Size = new Size(128, 40);
@ -445,7 +482,6 @@
//
// vuePublishBtn
//
vuePublishBtn.Enabled = false;
vuePublishBtn.Location = new Point(91, 50);
vuePublishBtn.Name = "vuePublishBtn";
vuePublishBtn.Size = new Size(128, 40);
@ -454,18 +490,21 @@
vuePublishBtn.UseVisualStyleBackColor = true;
vuePublishBtn.Click += vuePublishBtn_Click;
//
// openFileDialog1
//
openFileDialog1.FileName = "openFileDialog1";
//
// PublishForm
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1131, 1074);
ClientSize = new Size(1275, 1074);
Controls.Add(groupBox5);
Controls.Add(tabControl1);
Controls.Add(groupBox3);
Controls.Add(groupBox1);
Name = "PublishForm";
Text = "PublishForm";
Load += PublishForm_Load;
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupBox3.ResumeLayout(false);
@ -509,15 +548,20 @@
private Label label2;
private TextBox startOrStopServiceTbox;
private Label label4;
private TextBox bakPathTBox;
private TextBox backPathTBox;
private Label label3;
private TextBox bakDbName;
private TextBox bakPublishPath;
private TextBox backPublishPath;
private Label label5;
private GroupBox groupBox4;
private Button startBakBtn;
private GroupBox groupBox5;
private Button netCorePublishBtn;
private Button vuePublishBtn;
private TextBox servicePortTBox;
private Label label6;
private OpenFileDialog openFileDialog1;
private Button serviceConfigSaveBtn;
private Button bakConfigSaveBtn;
}
}

View File

@ -13,6 +13,12 @@ using System.Security;
using System.Diagnostics;
using System.Net;
using Renci.SshNet;
using Serilog;
using Newtonsoft.Json.Linq;
using System.ServiceProcess;
using Renci.SshNet.Messages;
using System.Management;
using System.IO;
namespace PublishSite
{
@ -21,10 +27,16 @@ namespace PublishSite
public PublishForm()
{
InitializeComponent();
Serilog.Log.Logger = new LoggerConfiguration()
.WriteTo.File("logs\\log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
}
public string EnvName = "";
public string CurrentEnv = "Local";
public JObject jObjectCofig;
public string Host = "";
@ -32,29 +44,229 @@ namespace PublishSite
public string Password = "";
private void PublishForm_Load(object sender, EventArgs e)
private void WinformLog(string message, Color? color = null)
{
string remoteComputerName = "123.56.94.154"; // 远程计算机名称
string userName = "Administrator"; // 用户名
string password = "WHxckj2019"; // 密码
if (InvokeRequired)
{
Invoke(new Action(() => WinformLog(message, color)));
return;
}
string localFilePath = $@"D:\testUpload.txt";
string remoteFilePath = $@"C:\temp\testUpload.txt";
CopyFileToRemote(localFilePath, remoteFilePath, remoteComputerName, userName, password);
logTBox.SelectionColor = color == null ? Color.Green : (Color)color;
logTBox.AppendText($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}: {message}" + Environment.NewLine);
Serilog.Log.Information(message);
}
private void startBakBtn_Click(object sender, EventArgs e)
#region 切换环境 配置回写
private void rb_Env_CheckedChanged(object sender, EventArgs e)
{
//本地
if (rb_local.Checked)
{
EnvName = "本地";
WinformLog($"当前操作环境切换为: 本地", Color.DarkRed);
var configJson = File.ReadAllText("appsettings.local.json");
jObjectCofig = JObject.Parse(configJson);
}
//测试
if (rb_test.Checked)
{
EnvName = "测试";
WinformLog($"当前操作环境切换为: 测试", Color.DarkRed);
var configJson = File.ReadAllText("appsettings.Development.json");
jObjectCofig = JObject.Parse(configJson);
}
//验证
if (rb_Verify.Checked)
{
EnvName = "验证";
WinformLog($"当前操作环境切换为: 验证", Color.DarkRed);
var configJson = File.ReadAllText("appsettings.Verify.json");
jObjectCofig = JObject.Parse(configJson);
}
//生产
if (rb_production.Checked)
{
EnvName = "生产";
WinformLog($"当前操作环境切换为: 生产", Color.DarkRed);
var configJson = File.ReadAllText("appsettings.Production.json");
jObjectCofig = JObject.Parse(configJson);
}
#region 界面控件赋值
Host = rb_local.Checked ? "" : jObjectCofig["Credential"]["Host"].ToString();
UserName = rb_local.Checked ? "" : jObjectCofig["Credential"]["UserName"].ToString();
Password = rb_local.Checked ? "" : jObjectCofig["Credential"]["Password"].ToString();
serviceNameTBox.Text = jObjectCofig["DefaultService"]["ServiceName"].ToString();
serviceDisplayNameTBox.Text = jObjectCofig["DefaultService"]["ServiceDisplayName"].ToString();
servicePortTBox.Text = jObjectCofig["DefaultService"]["ServicePort"].ToString();
exePathTbox.Text = jObjectCofig["DefaultService"]["BinPath"].ToString();
en_TBox.Text = jObjectCofig["DefaultService"]["Env"].ToString();
startOrStopServiceTbox.Text = jObjectCofig["DefaultService"]["ServiceName"].ToString();
bakDbName.Text = jObjectCofig["BackUp"]["DataBaseName"].ToString();
backPathTBox.Text = jObjectCofig["BackUp"]["BackPath"].ToString();
backPublishPath.Text = jObjectCofig["BackUp"]["ProgramRootPath"].ToString();
var credentialNode = jObjectCofig["Credential"];
var defaultServiceNode = jObjectCofig["DefaultService"];
var BackUpNode = jObjectCofig["BackUp"];
#endregion
}
private void serviceConfigSaveBtn_Click(object sender, EventArgs e)
{
var serviceName = serviceNameTBox.Text;
DialogResult dr = MessageBox.Show($"{EnvName}环境服务配置回写 ", "保存提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (dr == DialogResult.OK)
{
var path = string.Empty;
if (rb_local.Checked)
{
path = "appsettings.local.json";
}
if (rb_test.Checked)
{
path = "appsettings.Development.json";
}
if (rb_Verify.Checked)
{
path = "appsettings.Verify.json";
}
if (rb_production.Checked)
{
path = "appsettings.Production.json";
}
var configJson = File.ReadAllText(path);
jObjectCofig = JObject.Parse(configJson);
jObjectCofig["DefaultService"]["ServiceName"] = serviceNameTBox.Text.Trim();
jObjectCofig["DefaultService"]["ServiceDisplayName"] = serviceDisplayNameTBox.Text.Trim();
jObjectCofig["DefaultService"]["ServicePort"] = servicePortTBox.Text.Trim();
jObjectCofig["DefaultService"]["BinPath"] = exePathTbox.Text.Trim();
jObjectCofig["DefaultService"]["Env"] = en_TBox.Text.Trim();
File.WriteAllText(path, jObjectCofig.ToString());
WinformLog("服务配置回写成功!");
}
}
private void bakConfigSaveBtn_Click(object sender, EventArgs e)
{
var serviceName = serviceNameTBox.Text;
DialogResult dr = MessageBox.Show($"{EnvName}环境备份配置回写 ", "保存提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (dr == DialogResult.OK)
{
var path = string.Empty;
if (rb_local.Checked)
{
path = "appsettings.local.json";
}
if (rb_test.Checked)
{
path = "appsettings.Development.json";
}
if (rb_Verify.Checked)
{
path = "appsettings.Verify.json";
}
if (rb_production.Checked)
{
path = "appsettings.Production.json";
}
var configJson = File.ReadAllText(path);
jObjectCofig = JObject.Parse(configJson);
jObjectCofig["BackUp"]["DataBaseName"] = bakDbName.Text.Trim();
jObjectCofig["BackUp"]["BackPath"] = backPathTBox.Text.Trim();
jObjectCofig["BackUp"]["ProgramRootPath"] = backPublishPath.Text.Trim();
File.WriteAllText(path, jObjectCofig.ToString());
WinformLog("备份配置回写成功!");
}
}
#endregion
#region 备份
private async void startBakBtn_Click(object sender, EventArgs e)
{
await Task.Run(() =>
{
if (rb_local.Checked)
{
}
else
{
using (var client = new SshClient(Host, UserName, Password))
{
var backRootPath = jObjectCofig[]
// 判断文件夹是否存在
var backupFolderPath = "/path/to/backup/folder";
var command = $"if [ ! -d '{backupFolderPath}' ]; then mkdir {backupFolderPath}; fi";
var result = client.RunCommand(command);
}
}
});
}
#endregion
#region 服务的创建与删除
private void createService_Btn_Click(object sender, EventArgs e)
@ -62,14 +274,101 @@ namespace PublishSite
}
private void deleteService_Btn_Click(object sender, EventArgs e)
private async void deleteService_Btn_Click(object sender, EventArgs e)
{
var serviceName = serviceNameTBox.Text;
DialogResult dr = MessageBox.Show($"{EnvName}环境删除服务:{serviceName}", "删除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (dr == DialogResult.OK)
{
await Task.Run(() =>
{
if (rb_local.Checked)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = $"/c sc query {serviceName} | find \"STATE\" | find /i \"RUNNING\" && net stop {serviceName} & sc delete {serviceName}";
// 在后台运行命令行窗口
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
using (Process process = new Process())
{
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
if (process.ExitCode == 0)
{
WinformLog($"{serviceName} 服务已经成功删除!");
}
else
{
WinformLog($"尝试停止并删除 {serviceName} 服务失败,请检查是否拥有管理员权限或服务是否存在。", Color.Red);
}
}
}
else
{
using (var client = new SshClient(Host, UserName, Password))
{
// 连接到远程服务器
client.Connect();
// 停止服务
string stopCommand = $"sc stop {serviceName}";
using (var stopCmd = client.CreateCommand(stopCommand))
{
WinformLog(stopCommand);
var stopOutput = stopCmd.Execute();
WinformLog(stopOutput);
}
// 删除服务
string deleteCommand = $"sc delete {serviceName}";
using (var deleteCmd = client.CreateCommand(deleteCommand))
{
WinformLog(deleteCommand);
var deleteOutput = deleteCmd.Execute();
WinformLog(deleteOutput);
}
// 断开SSH连接
client.Disconnect();
}
}
});
}
}
private void selectPathBtn_Click(object sender, EventArgs e)
{
if (rb_local.Checked)
{
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
exePathTbox.Text = dialog.FileName;
WinformLog($"部署启动文件选择成功", Color.Green);
}
}
else
{
WinformLog("远程环境不支持直接选择目录", Color.Red);
}
}
#endregion
@ -78,72 +377,90 @@ namespace PublishSite
#region 测试环境发布
private void vuePublishBtn_Click(object sender, EventArgs e)
private async void vuePublishBtn_Click(object sender, EventArgs e)
{
vuePublishBtn.Enabled = false;
using (var client = new SshClient("123.56.94.154", "Administrator", "WHxckj2019"))
await Task.Run(() =>
{
// 连接到远程服务器
client.Connect();
//&& ./IRaCIS_Vue_Web.bat
string command = $@"cd C:\Users\Administrator\VueSourceCode && npm i && npm run build";
using (var cmd = client.CreateCommand(command))
using (var client = new SshClient("123.56.94.154", "Administrator", "WHxckj2019"))
{
// 连接到远程服务器
client.Connect();
Console.WriteLine("开始执行");
Console.WriteLine(command);
//&& ./IRaCIS_Vue_Web.bat
string command = $@"cd C:\Users\Administrator\VueSourceCode && npm i && npm run build";
var output = cmd.Execute();
using (var cmd = client.CreateCommand(command))
{
Console.WriteLine(output);
WinformLog("测试环境:开始执行前端发布");
WinformLog(command);
var output3 = cmd.Execute($@"xcopy /Y /Q ""C:\Users\Administrator\VueSourceCode\dist\index.html"" ""D:\Develop\PublishSite\IRaCIS.Vue.Web\dist\""");
var output = cmd.Execute();
Console.WriteLine(output);
WinformLog(output);
Console.WriteLine("发布成功");
var output3 = cmd.Execute($@"xcopy /Y /Q ""C:\Users\Administrator\VueSourceCode\dist\index.html"" ""D:\Develop\PublishSite\IRaCIS.Vue.Web\dist\""");
WinformLog(output);
WinformLog("测试环境:前端发布成功");
}
// 断开SSH连接
client.Disconnect();
}
// 断开SSH连接
client.Disconnect();
}
});
vuePublishBtn.Enabled = true;
}
private void netCorePublishBtn_Click(object sender, EventArgs e)
private async void netCorePublishBtn_Click(object sender, EventArgs e)
{
using (var client = new SshClient("123.56.94.154", "Administrator", "WHxckj2019"))
netCorePublishBtn.Enabled = false;
await Task.Run(() =>
{
// 连接到远程服务器
client.Connect();
//&& ./IRaCIS_Vue_Web.bat
string command = $@"cd C:\Users\Administrator\bat\ && ./IRaCIS_Core_API.bat";
using (var cmd = client.CreateCommand(command))
using (var client = new SshClient("123.56.94.154", "Administrator", "WHxckj2019"))
{
// 连接到远程服务器
client.Connect();
Console.WriteLine("开始执行");
string command = $@"C:\Users\Administrator\bat\IRaCIS_Core_API.bat";
Console.WriteLine(command);
var output = cmd.Execute();
using (var cmd = client.CreateCommand(command))
{
Console.WriteLine(output);
WinformLog("测试环境:开始执行后端发布");
Console.WriteLine("发布成功");
WinformLog(command);
var output = cmd.Execute();
WinformLog(output);
WinformLog("测试环境:后端发布成功");
}
// 断开SSH连接
client.Disconnect();
}
// 断开SSH连接
client.Disconnect();
}
});
netCorePublishBtn.Enabled = true;
}
#endregion
@ -151,19 +468,105 @@ namespace PublishSite
#region 服务的启动与停止
private void startServiceBtn_Click(object sender, EventArgs e)
private async void startServiceBtn_Click(object sender, EventArgs e)
{
startServiceBtn.Enabled = false;
await Task.Run(() =>
{
if (rb_local.Checked)
{
ServiceController controller = new ServiceController($"{startOrStopServiceTbox.Text}");
if (controller?.Status == ServiceControllerStatus.Running)
{
controller.Stop();
controller.WaitForStatus(ServiceControllerStatus.Stopped);
}
else
{
WinformLog("服务不是停止状态", Color.Red);
}
return;
}
using (var client = new SshClient(Host, UserName, Password))
{
// 连接到远程服务器
client.Connect();
string command = $@"sc start {startOrStopServiceTbox.Text}";
using (var cmd = client.CreateCommand(command))
{
WinformLog(command);
var output = cmd.Execute();
WinformLog(output);
}
// 断开SSH连接
client.Disconnect();
}
});
startServiceBtn.Enabled = true;
}
private void stopServiceBtn_Click(object sender, EventArgs e)
private async void stopServiceBtn_Click(object sender, EventArgs e)
{
startServiceBtn.Enabled = false;
await Task.Run(() =>
{
if (rb_local.Checked)
{
ServiceController controller = new ServiceController($"{startOrStopServiceTbox.Text}");
if (controller?.Status == ServiceControllerStatus.Running)
{
controller.Stop();
controller.WaitForStatus(ServiceControllerStatus.Stopped);
}
else
{
WinformLog("服务不是启动状态", Color.Red);
}
return;
}
using (var client = new SshClient(Host, UserName, Password))
{
// 连接到远程服务器
client.Connect();
string command = $@"sc stop {startOrStopServiceTbox.Text}";
using (var cmd = client.CreateCommand(command))
{
WinformLog(command);
var output = cmd.Execute();
WinformLog(output);
}
// 断开SSH连接
client.Disconnect();
}
});
startServiceBtn.Enabled = true;
}
#endregion
}
}

View File

@ -57,4 +57,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -44,8 +44,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="Microsoft.WSMan.Management" Version="7.2.10" />
<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" />
</ItemGroup>

View File

@ -1,7 +1,7 @@
{
"BackUp": {
"DataBaseName": "IRaCIS_New_Tet",
"FullDBRootPath": "Warning",
"BackPath": "D:\\Develop\\PublishSite\\发布备份",
"ProgramRootPath": "D:\\Develop\\PublishSite\\发布备份",
"ConnectionStrings": "Server=.;Database=IRaCIS;Trusted_Connection=True;TrustServerCertificate=true"
},