Commit 27a3eb5a authored by 段廷瑞's avatar 段廷瑞

Merge branch 'master' of http://192.168.1.181/root/Ftt_Common

parents 78db6e2a abae6d68
......@@ -79,8 +79,6 @@ namespace UpdateExecuter
}
/// <summary>
/// 分割sql脚本,返回单条可执行脚本。
/// 处理 go 语句执行会报错的情况。
......@@ -130,6 +128,17 @@ namespace UpdateExecuter
return lstSql;
}
/// <summary>
/// 返回相对目录。A - B。
/// </summary>
/// <param name="pathSource">源路径 A</param>
/// <param name="pathBase">基础路径 B</param>
/// <returns></returns>
public static string GetRelativePath(string pathSource, string pathBase)
{
return pathSource.Replace(pathBase, "").TrimStart(new char[] { '\\' });
}
}
}
......@@ -162,80 +162,54 @@ namespace UpdateExecuter
private async void btnExecute_Click(object sender, System.EventArgs e)
{
Debug.WriteLine($"当前线程:{System.Threading.Thread.CurrentThread.ManagedThreadId }");
this._scriptPath = txtDBPath.Text;
this._updateFilePath = txtFilePath.Text;
if (string.IsNullOrEmpty(_scriptPath) && string.IsNullOrEmpty(_updateFilePath))
try
{
MessageBox.Show(this, "[脚本目录]和[文件目录]不能同时为空,请至少选择一个!", "提示");
return;
}
btnExecute.Enabled = false;
if (!string.IsNullOrEmpty(_scriptPath) && !Directory.Exists(_scriptPath))
{
MessageBox.Show(this, "目录有误!", "提示");
this.txtDBPath.Focus();
return;
}
Debug.WriteLine($"当前线程:{System.Threading.Thread.CurrentThread.ManagedThreadId }");
if (!string.IsNullOrEmpty(_updateFilePath) && !Directory.Exists(_updateFilePath))
{
MessageBox.Show(this, "目录有误!", "提示");
this.txtFilePath.Focus();
return;
}
if (!CheckExecuter()) return;
var items = lstClient.CheckedItems;
if (items.Count == 0)
{
MessageBox.Show("请选择客户...");
return;
}
var lstClientName = GetSelectedClient();
List<string> lstClientName = new List<string>();
for (var i = 0; i < items.Count; i++)
{
ListViewItem item = items[i];
item.ForeColor = System.Drawing.Color.Black;
item.BackColor = System.Drawing.Color.White;
lstClientName.Add(item.Text);
}
listViewMsg.Items.Clear();
listViewMsg.Items.Clear(); // 清空历史消息
#region 执行数据库脚本更新
#region 执行数据库脚本更新
if (!string.IsNullOrEmpty(_scriptPath))
{
DirectoryInfo theFolder = new DirectoryInfo(_scriptPath);
FileInfo[] dbFiles = theFolder.GetFiles("*.sql", SearchOption.AllDirectories);
if (dbFiles.Length > 0)
if (!string.IsNullOrEmpty(_scriptPath))
{
// 根据文件名排序、保证按顺序执行(脚本文件有依赖顺序)
Array.Sort(dbFiles, delegate (FileInfo x, FileInfo y) { return x.FullName.CompareTo(y.FullName); });
DirectoryInfo theFolder = new DirectoryInfo(_scriptPath);
FileInfo[] dbFiles = theFolder.GetFiles("*.sql", SearchOption.AllDirectories);
if (dbFiles.Length > 0)
{
// 根据文件名排序、保证按顺序执行(脚本文件有依赖顺序)
Array.Sort(dbFiles, delegate (FileInfo x, FileInfo y) { return x.FullName.CompareTo(y.FullName); });
Debug.WriteLine($"当前线程1:{System.Threading.Thread.CurrentThread.ManagedThreadId }");
Debug.WriteLine($"当前线程1:{System.Threading.Thread.CurrentThread.ManagedThreadId }");
await ExecDBScriptAsync(lstClientName, dbFiles);
await ExecDBScriptAsync(lstClientName, dbFiles);
}
}
}
#endregion
#endregion
#region 发布程序文件更新
#region 发布程序文件更新
if (!string.IsNullOrEmpty(_updateFilePath))
{
await ExecFileUpdatorAsync(lstClientName, _updateFilePath);
}
if (!string.IsNullOrEmpty(_updateFilePath))
#endregion
}
catch (Exception ex)
{
await ExecFileUpdatorAsync(lstClientName, _updateFilePath);
MessageBox.Show($"更新发布失败:{ex.Message}");
}
finally
{
btnExecute.Enabled = true;
}
#endregion
lblSpeed.Text = "更新发布完成!";
}
......@@ -267,6 +241,61 @@ namespace UpdateExecuter
}
}
/// <summary>
/// 更新之前的检查操作
/// </summary>
/// <returns></returns>
private bool CheckExecuter()
{
this._scriptPath = txtDBPath.Text;
this._updateFilePath = txtFilePath.Text;
if (string.IsNullOrEmpty(_scriptPath) && string.IsNullOrEmpty(_updateFilePath))
{
MessageBox.Show(this, "[脚本目录]和[文件目录]不能同时为空,请至少选择一个!", "提示");
return false;
}
if (!string.IsNullOrEmpty(_scriptPath) && !Directory.Exists(_scriptPath))
{
MessageBox.Show(this, "目录有误!", "提示");
this.txtDBPath.Focus();
return false;
}
if (!string.IsNullOrEmpty(_updateFilePath) && !Directory.Exists(_updateFilePath))
{
MessageBox.Show(this, "目录有误!", "提示");
this.txtFilePath.Focus();
return false;
}
var items = lstClient.CheckedItems;
if (items.Count == 0)
{
MessageBox.Show("请选择客户...");
return false;
}
return true;
}
/// <summary>
/// 获取选择的客户列表
/// </summary>
/// <returns></returns>
private List<string> GetSelectedClient()
{
List<string> lstClientName = new List<string>();
var items = lstClient.CheckedItems;
for (var i = 0; i < items.Count; i++)
{
ListViewItem item = items[i];
item.ForeColor = System.Drawing.Color.Black;
item.BackColor = System.Drawing.Color.White;
lstClientName.Add(item.Text);
}
return lstClientName;
}
#endregion
......@@ -345,7 +374,7 @@ namespace UpdateExecuter
// 执行环境切换到默认库。
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, $"USE {configDbName};");
_execFile = file;
_execFile = file;
ShowFileInfo($"在客户[{client}]执行脚本文件:{file.Name}.", file, true);
......@@ -368,7 +397,7 @@ namespace UpdateExecuter
num++;
_execSql = sql;
ShowProcessSpeed(file.FullName, $"执行进度:{num}/{lstSql.Count}", sql);
ShowProcessSpeed(Utils.GetRelativePath(file.FullName, _scriptPath), $"执行进度:{num}/{lstSql.Count}", sql);
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql);
}));
......@@ -383,7 +412,7 @@ namespace UpdateExecuter
}
catch (Exception ex)
{
ShowProcessSpeed(_execFile.FullName, $"执行失败:{ex.Message}", _execSql);
ShowProcessSpeed(Utils.GetRelativePath(_execFile.FullName, _scriptPath), $"执行失败:{ex.Message}", _execSql);
ShowFileInfo($"在客户[{client}]执行脚本文件失败:{_execFile.Name}.", _execFile, false);
MessageBox.Show($"在客户 [{client}] 执行脚本失败, Ctrl + V 查看脚本。 \r\n{ex.Message}");
return false;
......@@ -391,9 +420,6 @@ namespace UpdateExecuter
return true;
}
#endregion
#region 文件更新操作
......@@ -438,8 +464,6 @@ namespace UpdateExecuter
}
}
/// <summary>
/// 上传更新文件
/// </summary>
......@@ -499,10 +523,6 @@ namespace UpdateExecuter
}
#endregion
#region 其他
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment