Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
Ftt_Common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Ftt_Common
Commits
abae6d68
Commit
abae6d68
authored
Feb 09, 2022
by
罗显健
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新器优化:1.发布按钮增加控制 2.执行的脚本文件显示相对路径。
parent
a5c81d7c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
71 deletions
+100
-71
Utils.cs
UpdateExecuter/Utils.cs
+11
-2
frmMain.cs
UpdateExecuter/frmMain.cs
+89
-69
No files found.
UpdateExecuter/Utils.cs
View file @
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
[]
{
'\\'
});
}
}
}
UpdateExecuter/frmMain.cs
View file @
abae6d68
...
...
@@ -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
其他
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment