lith il y a 4 ans
Parent
commit
605d45f2bd

+ 2 - 14
Library/Vit.Db.DbMng/MsSql/MsSqlDbMng.cs

@@ -661,22 +661,10 @@ deallocate   cDblogin
         }
         #endregion
 
-        #region RestoreBakByFileName 通过bak远程还原
-        /// <summary>
-        /// 通过备份文件名称远程还原数据库,备份文件在当前管理的备份文件夹中
-        /// </summary>
-        /// <param name="fileName"></param>
-        /// <returns></returns>
-        public string RestoreBakByFileName(string fileName)
-        {
-            return RestoreBak(BackupFile_GetPathByName(fileName));
-        }
-        #endregion
-
-   
+        
 
 
-        #region RestoreLocalBak  by filePath
+        #region RestoreLocalBak
         /// <summary>
         /// 还原数据库   
         /// </summary>

+ 3 - 15
Library/Vit.Db.DbMng/MySql/MySqlDbMng.cs

@@ -508,26 +508,14 @@ ORDER BY TABLE_NAME ASC, INDEX_NAME ASC;";
         /// </summary>
         /// <param name="filePath">数据库备份文件的路径</param>
         /// <returns>备份文件的路径</returns>
-        public string Restore(string filePath)
+        public void Restore(string filePath)
         {
-            RestoreSqler(filePath);
-            return filePath;
+            RestoreSqler(filePath);     
         }
         #endregion
 
 
-        #region RestoreByFileName
-
-        /// <summary>
-        /// 通过备份文件名称远程还原数据库,备份文件在当前管理的备份文件夹中
-        /// </summary>
-        /// <param name="fileName"></param>
-        /// <returns></returns>
-        public string RestoreByFileName(string fileName)
-        {
-            return Restore(BackupFile_GetPathByName(fileName));
-        }
-        #endregion
+      
                                  
 
 

+ 4 - 4
Library/Vit.Db.DbMng/Vit.Db.DbMng.csproj

@@ -11,13 +11,13 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Vit.Core" Version="2.1.1.457" />
-    <!--<PackageReference Include="Vit.Orm.Dapper" Version="2.1.1.457" />-->
+    <PackageReference Include="Vit.Core" Version="2.1.1.459" />
+    <PackageReference Include="Vit.Orm.Dapper" Version="2.1.1.459" />
     <PackageReference Include="sharpcompress" Version="0.27.0" />
   </ItemGroup>
 
-  <ItemGroup>
+  <!--<ItemGroup>
     <ProjectReference Include="..\..\..\..\..\Sers2.1.1\SersTool\Library\Dapper\Vit.Orm.Dapper\Vit.Orm.Dapper.csproj" />
-  </ItemGroup> 
+  </ItemGroup>--> 
   
 </Project>

+ 0 - 14
Sqler.sln

@@ -9,10 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Library", "Library", "{4EE8
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vit.Db.DbMng", "Library\Vit.Db.DbMng\Vit.Db.DbMng.csproj", "{CC6ED50C-5FED-41EF-9C31-E1727BDD131F}"
 EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vit.Orm.Dapper", "..\..\..\Sers2.1.1\SersTool\Library\Dapper\Vit.Orm.Dapper\Vit.Orm.Dapper.csproj", "{8F27A87B-AA8C-4866-8DC2-D1D12660BF8E}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vit.Db", "..\..\..\Sers2.1.1\SersTool\Library\Vit.Db\Vit.Db\Vit.Db.csproj", "{94880F36-3545-4393-AE81-6559A7F0E5E1}"
-EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -27,22 +23,12 @@ Global
 		{CC6ED50C-5FED-41EF-9C31-E1727BDD131F}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{CC6ED50C-5FED-41EF-9C31-E1727BDD131F}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{CC6ED50C-5FED-41EF-9C31-E1727BDD131F}.Release|Any CPU.Build.0 = Release|Any CPU
-		{8F27A87B-AA8C-4866-8DC2-D1D12660BF8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{8F27A87B-AA8C-4866-8DC2-D1D12660BF8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{8F27A87B-AA8C-4866-8DC2-D1D12660BF8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{8F27A87B-AA8C-4866-8DC2-D1D12660BF8E}.Release|Any CPU.Build.0 = Release|Any CPU
-		{94880F36-3545-4393-AE81-6559A7F0E5E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{94880F36-3545-4393-AE81-6559A7F0E5E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{94880F36-3545-4393-AE81-6559A7F0E5E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{94880F36-3545-4393-AE81-6559A7F0E5E1}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
 	EndGlobalSection
 	GlobalSection(NestedProjects) = preSolution
 		{CC6ED50C-5FED-41EF-9C31-E1727BDD131F} = {4EE8188B-B9C2-4229-8181-5AAD9A5382C3}
-		{8F27A87B-AA8C-4866-8DC2-D1D12660BF8E} = {4EE8188B-B9C2-4229-8181-5AAD9A5382C3}
-		{94880F36-3545-4393-AE81-6559A7F0E5E1} = {4EE8188B-B9C2-4229-8181-5AAD9A5382C3}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {C7DA16E3-9949-49FA-B0B4-F830636DE60F}

+ 8 - 8
Sqler/Module/Sqler/ConsoleCommand/MySqlCommand.cs

@@ -57,16 +57,16 @@ namespace App.Module.Sqler.ConsoleCommand
         }
         #endregion
 
-        #region RemoteRestore
-        [Command("MySql.RemoteRestore")]
+        #region Restore
+        [Command("MySql.Restore")]
         [Remarks("通过备份文件远程还原数据库。参数说明:备份文件名称和路径指定其一即可")]
         [Remarks("-f[--force] 强制还原数据库。若指定此参数,则在数据库已经存在时仍然还原数据库;否则仅在数据库尚未存在时还原数据库。")]
         [Remarks("-fn[--fileName] (可选)备份文件名称,备份文件在当前管理的备份文件夹中。例如 \"DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-fp[--filePath] (可选)备份文件路径,例如 \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-ConnStr[--ConnectionString] (可选)数据库连接字符串 例如 \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\"")]
         [Remarks("--DataPath (可选)Data文件夹的路径。可为相对或绝对路径,默认:\"Data\"")]
-        [Remarks("示例: MySql.RemoteRestore -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
-        public static void RemoteRestore(string[] args)
+        [Remarks("示例: MySql.Restore -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
+        public static void Restore(string[] args)
         {
             ConsoleHelp.Log("通过备份文件远程还原数据库...");
 
@@ -92,14 +92,14 @@ namespace App.Module.Sqler.ConsoleCommand
 
 
         #region RemoteBackup
-        [Command("MySql.RemoteBackup")]
+        [Command("MySql.BackupSqler")]
         [Remarks("远程备份数据库。参数说明:备份文件名称和路径指定其一即可")]
         [Remarks("-fn[--fileName] (可选)备份文件名称,备份文件在当前管理的备份文件夹中。例如 \"DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-fp[--filePath] (可选)备份文件路径,例如 \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-ConnStr[--ConnectionString] (可选)数据库连接字符串 例如 \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\"")]
         [Remarks("--DataPath (可选)Data文件夹的路径。可为相对或绝对路径,默认:\"Data\"")]
-        [Remarks("示例: MySql.RemoteBackup -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
-        public static void RemoteBackup(string[] args)
+        [Remarks("示例: MySql.BackupSqler -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
+        public static void BackupSqler(string[] args)
         {
             ConsoleHelp.Log("远程备份数据库...");
 
@@ -115,7 +115,7 @@ namespace App.Module.Sqler.ConsoleCommand
             string filePath = ConsoleHelp.GetArg(args, "-fp") ?? ConsoleHelp.GetArg(args, "--filePath");
 
 
-            MySqlLogical.SqlerBackup(filePath, fileName);
+            MySqlLogical.BackupSqler(filePath, fileName);
 
             ConsoleHelp.Log("操作成功");
         }

+ 62 - 26
Sqler/Module/Sqler/ConsoleCommand/SqlServerCommand.cs

@@ -58,9 +58,13 @@ namespace App.Module.Sqler.ConsoleCommand
 
 
 
+
+
+
         #region Restore
         [Command("SqlServer.Restore")]
-        [Remarks("通过备份文件还原数据库。参数说明:备份文件名称和路径指定其一即可")]
+        [Remarks("远程还原数据库。参数说明:备份文件名称和路径指定其一即可")]
+        [Remarks("-f[--force] 强制还原数据库。若指定此参数,则在数据库已经存在时仍然还原数据库;否则仅在数据库尚未存在时还原数据库。")]
         [Remarks("-fn[--fileName] (可选)备份文件名称,备份文件在当前管理的备份文件夹中。例如 \"DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-fp[--filePath] (可选)备份文件路径,例如 \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-ConnStr[--ConnectionString] (可选)数据库连接字符串 例如 \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\"")]
@@ -68,7 +72,7 @@ namespace App.Module.Sqler.ConsoleCommand
         [Remarks("示例: SqlServer.Restore -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
         public static void Restore(string[] args)
         {
-            ConsoleHelp.Log("通过备份文件还原数据库...");
+            ConsoleHelp.Log("远程还原数据库...");
 
             #region (x.1) arg SqlBackup.SqlServerBackup.ConnectionString
             string connStr = ConsoleHelp.GetArg(args, "-ConnStr") ?? ConsoleHelp.GetArg(args, "--ConnectionString");
@@ -81,26 +85,26 @@ namespace App.Module.Sqler.ConsoleCommand
             string fileName = ConsoleHelp.GetArg(args, "-fn") ?? ConsoleHelp.GetArg(args, "--fileName");
             string filePath = ConsoleHelp.GetArg(args, "-fp") ?? ConsoleHelp.GetArg(args, "--filePath");
 
+            bool force = (ConsoleHelp.GetArg(args, "-f") ?? ConsoleHelp.GetArg(args, "--force")) != null;
 
-            SqlServerLogical.RestoreLocalBak(filePath: filePath, fileName: fileName);
+            SqlServerLogical.Restore(filePath: filePath, fileName: fileName);
 
             ConsoleHelp.Log("操作成功");
         }
         #endregion
 
 
-
-        #region RemoteRestore
-        [Command("SqlServer.RemoteRestore")]
-        [Remarks("通过备份文件远程还原数据库。参数说明:备份文件名称和路径指定其一即可")]
+        #region RestoreLocalBak
+        [Command("SqlServer.RestoreLocalBak")]
+        [Remarks("通过本地bak文件还原数据库。参数说明:备份文件名称和路径指定其一即可")]
         [Remarks("-fn[--fileName] (可选)备份文件名称,备份文件在当前管理的备份文件夹中。例如 \"DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-fp[--filePath] (可选)备份文件路径,例如 \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-ConnStr[--ConnectionString] (可选)数据库连接字符串 例如 \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\"")]
         [Remarks("--DataPath (可选)Data文件夹的路径。可为相对或绝对路径,默认:\"Data\"")]
-        [Remarks("示例: SqlServer.RemoteRestore -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
-        public static void RemoteRestore(string[] args)
+        [Remarks("示例: SqlServer.RestoreLocalBak -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
+        public static void RestoreLocalBak(string[] args)
         {
-            ConsoleHelp.Log("通过备份文件远程还原数据库...");
+            ConsoleHelp.Log("通过本地bak文件还原数据库...");
 
             #region (x.1) arg SqlBackup.SqlServerBackup.ConnectionString
             string connStr = ConsoleHelp.GetArg(args, "-ConnStr") ?? ConsoleHelp.GetArg(args, "--ConnectionString");
@@ -114,26 +118,56 @@ namespace App.Module.Sqler.ConsoleCommand
             string filePath = ConsoleHelp.GetArg(args, "-fp") ?? ConsoleHelp.GetArg(args, "--filePath");
 
 
-            SqlServerLogical.Restore(filePath: filePath, fileName: fileName);
+            SqlServerLogical.RestoreLocalBak(filePath: filePath, fileName: fileName);
 
             ConsoleHelp.Log("操作成功");
         }
         #endregion
 
 
+        #region BackupBak
+        [Command("SqlServer.BackupBak")]
+        [Remarks("远程bak备份数据库。参数说明:备份文件名称和路径指定其一即可")]
+        [Remarks("-fn[--fileName] (可选)备份文件名称,备份文件在当前管理的备份文件夹中。例如 \"DbDev_2020-06-08_135203.bak\"")]
+        [Remarks("-fp[--filePath] (可选)备份文件路径,例如 \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
+        [Remarks("-ConnStr[--ConnectionString] (可选)数据库连接字符串 例如 \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\"")]
+        [Remarks("--DataPath (可选)Data文件夹的路径。可为相对或绝对路径,默认:\"Data\"")]
+        [Remarks("示例: SqlServer.BackupBak -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
+        public static void BackupBak(string[] args)
+        {
+            ConsoleHelp.Log("远程bak备份数据库...");
 
+            #region (x.1) arg SqlBackup.SqlServerBackup.ConnectionString
+            string connStr = ConsoleHelp.GetArg(args, "-ConnStr") ?? ConsoleHelp.GetArg(args, "--ConnectionString");
+            if (!string.IsNullOrEmpty(connStr))
+            {
+                SqlerHelp.sqlerConfig.root.ValueSetByPath(connStr, "SqlBackup", "SqlServerBackup", "ConnectionString");
+            }
+            #endregion
 
-        #region Backup
-        [Command("SqlServer.Backup")]
-        [Remarks("备份数据库。参数说明:备份文件名称和路径指定其一即可")]
+            string fileName = ConsoleHelp.GetArg(args, "-fn") ?? ConsoleHelp.GetArg(args, "--fileName");
+            string filePath = ConsoleHelp.GetArg(args, "-fp") ?? ConsoleHelp.GetArg(args, "--filePath");
+
+
+            SqlServerLogical.BackupBak(filePath, fileName);
+
+            ConsoleHelp.Log("操作成功");
+        }
+        #endregion
+
+
+
+        #region BackupSqler
+        [Command("SqlServer.BackupSqler")]
+        [Remarks("Sqler备份数据库。参数说明:备份文件名称和路径指定其一即可")]
         [Remarks("-fn[--fileName] (可选)备份文件名称,备份文件在当前管理的备份文件夹中。例如 \"DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-fp[--filePath] (可选)备份文件路径,例如 \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-ConnStr[--ConnectionString] (可选)数据库连接字符串 例如 \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\"")]
         [Remarks("--DataPath (可选)Data文件夹的路径。可为相对或绝对路径,默认:\"Data\"")]
-        [Remarks("示例: SqlServer.Backup -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
-        public static void Backup(string[] args)
+        [Remarks("示例: SqlServer.BackupSqler -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.zip\"")]
+        public static void BackupSqler(string[] args)
         {
-            ConsoleHelp.Log("备份数据库...");
+            ConsoleHelp.Log("Sqler备份数据库...");
 
             #region (x.1) arg SqlBackup.SqlServerBackup.ConnectionString
             string connStr = ConsoleHelp.GetArg(args, "-ConnStr") ?? ConsoleHelp.GetArg(args, "--ConnectionString");
@@ -147,25 +181,24 @@ namespace App.Module.Sqler.ConsoleCommand
             string filePath = ConsoleHelp.GetArg(args, "-fp") ?? ConsoleHelp.GetArg(args, "--filePath");
 
 
-            SqlServerLogical.BackupLocalBak(filePath, fileName);
+            SqlServerLogical.BackupSqler(filePath, fileName);
 
             ConsoleHelp.Log("操作成功");
         }
         #endregion
 
 
-
-        #region RemoteBackup
-        [Command("SqlServer.RemoteBackup")]
-        [Remarks("远程备份数据库。参数说明:备份文件名称和路径指定其一即可")]
+        #region BackupLocalBak
+        [Command("SqlServer.BackupLocalBak")]
+        [Remarks("本地bak备份数据库。参数说明:备份文件名称和路径指定其一即可")]
         [Remarks("-fn[--fileName] (可选)备份文件名称,备份文件在当前管理的备份文件夹中。例如 \"DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-fp[--filePath] (可选)备份文件路径,例如 \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
         [Remarks("-ConnStr[--ConnectionString] (可选)数据库连接字符串 例如 \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\"")]
         [Remarks("--DataPath (可选)Data文件夹的路径。可为相对或绝对路径,默认:\"Data\"")]
-        [Remarks("示例: SqlServer.RemoteBackup -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
-        public static void RemoteBackup(string[] args)
+        [Remarks("示例: SqlServer.BackupLocalBak -ConnStr \"Data Source=.;Database=Db_Dev;UID=sa;PWD=123456;\" --filePath \"/root/docker/DbDev_2020-06-08_135203.bak\"")]
+        public static void BackupLocalBak(string[] args)
         {
-            ConsoleHelp.Log("远程备份数据库...");
+            ConsoleHelp.Log("本地bak备份数据库...");
 
             #region (x.1) arg SqlBackup.SqlServerBackup.ConnectionString
             string connStr = ConsoleHelp.GetArg(args, "-ConnStr") ?? ConsoleHelp.GetArg(args, "--ConnectionString");
@@ -179,7 +212,7 @@ namespace App.Module.Sqler.ConsoleCommand
             string filePath = ConsoleHelp.GetArg(args, "-fp") ?? ConsoleHelp.GetArg(args, "--filePath");
 
 
-            SqlServerLogical.BackupBak(filePath, fileName);
+            SqlServerLogical.BackupLocalBak(filePath, fileName);
 
             ConsoleHelp.Log("操作成功");
         }
@@ -187,5 +220,8 @@ namespace App.Module.Sqler.ConsoleCommand
 
 
 
+
+
+
     }
 }

+ 1 - 1
Sqler/Module/Sqler/Controllers/SqlBackup/MySqlBackupController.cs

@@ -305,7 +305,7 @@ namespace App.Module.Sqler.Controllers.SqlBackup
         [HttpPost("SqlerBackup")]
         public ApiReturn SqlerBackup()
         {
-            MySqlLogical.SqlerBackup();
+            MySqlLogical.BackupSqler();
             return new ApiReturn();
         }
         #endregion

+ 295 - 0
Sqler/Module/Sqler/Logical/DbPort/DataOutput.cs

@@ -0,0 +1,295 @@
+using Dapper;
+using Sqler.Module.Sqler.Logical.Message;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Vit.Core.Module.Log;
+using Vit.Orm.Dapper;
+using Vit.Extensions;
+using static Sqler.Module.Sqler.Logical.DbPort.DbPortLogical;
+
+namespace Sqler.Module.Sqler.Logical.DbPort
+{
+
+    public class DataOutput
+    {
+        public Action<EMsgType, string> SendMsg;
+        public string type;
+        public string ConnectionString; //数据库连接字符串。亦可从配置文件获取,如 sqler.config:SqlBackup.SqlServerBackup.ConnectionString
+        public bool createTable;
+        public bool delete;
+        public bool truncate;
+
+        public List<TableInfo> tableInfos;
+        public int sourceSumRowCount=0;
+
+        public Func<string, int, DataTableReader> GetDataTableReader;
+
+
+        public int importedSumRowCount { get; private set; } = 0;
+        int sourceRowCount=0;
+
+
+
+        #region WriteProcess
+        void WriteProcess(int importedRowCount)
+        {
+            SendMsg(EMsgType.Nomal, "");
+
+            if (sourceRowCount > 0)
+            {
+                var process = (((float)importedRowCount) / sourceRowCount * 100).ToString("f2");
+                SendMsg(EMsgType.Nomal, $"           cur: [{process}%] {importedRowCount }/{sourceRowCount}");
+            }
+            else 
+            {
+                SendMsg(EMsgType.Nomal, $"           cur: { importedRowCount }");
+            }
+
+            if (sourceSumRowCount > 0)
+            {
+                var process = (((float)importedSumRowCount) / sourceSumRowCount * 100).ToString("f2");
+                SendMsg(EMsgType.Nomal, $"           sum: [{process}%] {importedSumRowCount }/{sourceSumRowCount}");
+            }
+            else
+            {
+                SendMsg(EMsgType.Nomal, $"           sum: { importedSumRowCount }");
+            }
+            
+        }
+        #endregion
+
+
+      
+ 
+
+
+        #region Output
+        public void Output()
+        {
+            using (var conn = ConnectionFactory.GetConnection(new Vit.Orm.Dapper.ConnectionInfo { type = type, ConnectionString = ConnectionString }))
+            {           
+
+                SendMsg(EMsgType.Title, "   Output to database " + conn.Database);
+                SendMsg(EMsgType.Title, "   sum row count: " + sourceSumRowCount);
+                SendMsg(EMsgType.Title, "   table count: " + tableInfos.Count);
+                SendMsg(EMsgType.Title, "   table name: " + tableInfos.Select(m=>m.tableName).Serialize());
+
+
+                foreach (var tableInfo in tableInfos)
+                {
+                    var tableName = tableInfo.tableName;
+
+                    sourceRowCount = tableInfo.rowCount;
+
+                    var curTbIndex = tableInfo.tableIndex;
+
+                    using (var tableReader = GetDataTableReader(tableName, curTbIndex))
+                    {
+                        int importedRowCount = 0;
+
+                        SendMsg(EMsgType.Title, "");
+                        SendMsg(EMsgType.Title, "");
+                        SendMsg(EMsgType.Title, "");
+                        SendMsg(EMsgType.Title, $"       [{(curTbIndex + 1)}/{tableInfos.Count}]start import table " + tableName + ",sourceRowCount:" + sourceRowCount);
+
+
+                        #region (x.1)数据源为DataReader
+                        if (tableReader.GetDataReader != null)
+                        {
+
+                            //(x.x.1)read data
+                            SendMsg(EMsgType.Nomal, " ");
+                            SendMsg(EMsgType.Nomal, "           [x.x.1]read data ");
+                            var dr = tableReader.GetDataReader();
+
+
+                            //(x.x.2)
+                            if (createTable)
+                            {
+                                SendMsg(EMsgType.Title, "           [x.x.2]create table ");
+                                try
+                                {
+                                    conn.CreateTable(dr, tableName);
+                                }
+                                catch (Exception ex)
+                                {
+                                    Logger.Error(ex);
+                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
+                                }
+                            }
+
+                            //(x.x.3)
+                            if (delete)
+                            {
+                                SendMsg(EMsgType.Title, "           [x.x.3]delete table ");
+                                try
+                                {
+                                    conn.Execute("delete from  " + conn.Quote(tableName));
+                                }
+                                catch (Exception ex)
+                                {
+                                    Logger.Error(ex);
+                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
+                                }
+                            }
+
+                            //(x.x.4)
+                            if (truncate)
+                            {
+                                SendMsg(EMsgType.Title, "           [x.x.4]truncate table ");
+                                try
+                                {
+                                    conn.Execute("truncate table " + conn.Quote(tableName));
+                                }
+                                catch (Exception ex)
+                                {
+                                    Logger.Error(ex);
+                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
+                                }
+                            }
+
+
+                            //(x.x.5)import data   
+                            SendMsg(EMsgType.Nomal, "           [x.x.5]write data");
+                            try
+                            {
+                                while (true)
+                                {
+
+                                    int rowCount = conn.BulkImport(dr, tableName, maxRowCount: DbPortLogical.batchRowCount);
+
+
+
+                                    importedRowCount += rowCount;
+                                    importedSumRowCount += rowCount;
+
+                                    WriteProcess(importedRowCount);
+
+                                    if (rowCount < DbPortLogical.batchRowCount)
+                                    {
+                                        break;
+                                    }
+
+                                }
+
+                            }
+                            catch (Exception ex)
+                            {
+                                Logger.Error(ex);
+                                SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
+                            }
+
+                        }
+                        #endregion
+
+
+                        #region (x.2)数据源为DataTable
+                        if (tableReader.GetDataTable != null)
+                        {
+                            //(x.x.1)read data
+                            SendMsg(EMsgType.Nomal, " ");
+                            SendMsg(EMsgType.Nomal, "           [x.x.1]read data ");
+                            var dt = tableReader.GetDataTable();
+                            dt.TableName = tableName;
+
+                            //(x.x.2)
+                            if (createTable)
+                            {
+                                SendMsg(EMsgType.Title, "           [x.x.2]create table ");
+                                try
+                                {
+                                    conn.CreateTable(dt);
+                                }
+                                catch (Exception ex)
+                                {
+                                    Logger.Error(ex);
+                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
+                                }
+                            }
+
+                            //(x.x.3)
+                            if (delete)
+                            {
+                                SendMsg(EMsgType.Title, "           [x.x.3]delete table ");
+                                try
+                                {
+                                    conn.Execute("delete from  " + conn.Quote(tableName));
+                                }
+                                catch (Exception ex)
+                                {
+                                    Logger.Error(ex);
+                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
+                                }
+                            }
+
+                            //(x.x.4)
+                            if (truncate)
+                            {
+                                SendMsg(EMsgType.Title, "           [x.x.4]truncate table ");
+                                try
+                                {
+                                    conn.Execute("truncate table " + conn.Quote(tableName));
+                                }
+                                catch (Exception ex)
+                                {
+                                    Logger.Error(ex);
+                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
+                                }
+                            }
+
+
+                            //(x.x.5)import data   
+                            SendMsg(EMsgType.Nomal, "           [x.x.5]write data,row count:" + dt.Rows.Count);
+                            try
+                            {
+                                while (true)
+                                {
+
+
+                                    dt.TableName = tableName;
+                                    conn.BulkImport(dt);
+
+                                    int rowCount = dt.Rows.Count;
+                                    importedRowCount += dt.Rows.Count;
+                                    importedSumRowCount += dt.Rows.Count;
+
+
+                                    WriteProcess(importedRowCount);
+
+
+                                    SendMsg(EMsgType.Nomal, " ");
+                                    SendMsg(EMsgType.Nomal, "           [x.x.x.1]read data ");
+                                    dt = tableReader.GetDataTable();
+                                    if (dt == null)
+                                    {
+                                        break;
+                                    }
+                                }
+
+                            }
+                            catch (Exception ex)
+                            {
+                                Logger.Error(ex);
+                                SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
+                            }
+
+                        }
+                        #endregion
+
+
+                        SendMsg(EMsgType.Title, "                    import table " + tableName + " success,row count:" + importedRowCount);
+                    }
+                }
+
+             
+            }
+        }
+        #endregion
+
+
+
+
+
+    }
+}

+ 17 - 0
Sqler/Module/Sqler/Logical/DbPort/DataTableReader.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Data;
+
+namespace Sqler.Module.Sqler.Logical.DbPort
+{
+    public class DataTableReader : IDisposable
+    {
+        public Action OnDispose = null;
+        public void Dispose()
+        {
+            OnDispose?.Invoke();
+        }
+        public Func<IDataReader> GetDataReader = null;
+        public Func<DataTable> GetDataTable = null;
+
+    }
+}

+ 71 - 413
Sqler/Module/Sqler/Logical/DbPort/DbPortLogical.cs

@@ -23,8 +23,8 @@ namespace Sqler.Module.Sqler.Logical.DbPort
 
         public static int? commandTimeout => Vit.Orm.Dapper.DapperConfig.CommandTimeout;
 
-        //public static readonly int batchRowCount = Vit.Core.Util.ConfigurationManager.ConfigurationManager.Instance.GetByPath<int?>("Sqler.DbPort_batchRowCount") ?? 100000;
-        public static readonly int batchRowCount = 1000;
+        public static readonly int batchRowCount = Vit.Core.Util.ConfigurationManager.ConfigurationManager.Instance.GetByPath<int?>("Sqler.DbPort_batchRowCount") ?? 100000;
+  
 
         #region GetSqlRunConfig
         public static Dictionary<string, string> GetSqlRunConfig(string sql)
@@ -54,6 +54,8 @@ namespace Sqler.Module.Sqler.Logical.DbPort
 
         #endregion
 
+                   
+     
 
 
 
@@ -517,23 +519,19 @@ namespace Sqler.Module.Sqler.Logical.DbPort
 
 
 
+
+
+
+
         #region (x.2)Import
-        class DataTableReader : IDisposable
-        {
-            public Action OnDispose=null;     
-            public void Dispose()
-            {
-                OnDispose?.Invoke();
-            }
-            public Func<IDataReader> GetDataReader=null;
-            public Func<DataTable> GetDataTable=null;
-        }
+      
 
 
  
         public static void Import(
              Action<EMsgType, string> SendMsg,
              string filePath,
+
              string type,
              string ConnectionString, //数据库连接字符串。亦可从配置文件获取,如 sqler.config:SqlBackup.SqlServerBackup.ConnectionString
              bool createTable,
@@ -651,253 +649,38 @@ namespace Sqler.Module.Sqler.Logical.DbPort
                 }
                 #endregion
 
-
-                int sourceSumRowCount = rowCounts.Sum();
-                int importedSumRowCount = 0;
-                int sourceRowCount;
-
-                #region WriteProcess
-                void WriteProcess(int importedRowCount)
-                {
-                    SendMsg(EMsgType.Nomal, "");
-
-                    var process = (((float)importedRowCount) / sourceRowCount * 100).ToString("f2");
-                    SendMsg(EMsgType.Nomal, $"           cur: [{process}%] {importedRowCount }/{sourceRowCount}");
-
-                    process = (((float)importedSumRowCount) / sourceSumRowCount * 100).ToString("f2");
-                    SendMsg(EMsgType.Nomal, $"           sum: [{process}%] {importedSumRowCount }/{sourceSumRowCount}");
-                }
-                #endregion
-
-
-                #region (x.5)import data to database
-              
-      
-                using (var conn = ConnectionFactory.GetConnection(new Vit.Orm.Dapper.ConnectionInfo { type = type, ConnectionString = ConnectionString }))
-                {
-                    var startTime = DateTime.Now;
-
-
-                    SendMsg(EMsgType.Title, "   to database " + conn.Database);
-
-                    SendMsg(EMsgType.Title, "   sum row count: " + sourceSumRowCount);
-                    SendMsg(EMsgType.Title, "   table count: " + tableNames.Count);
-                    SendMsg(EMsgType.Title, "   table name: " + tableNames.Serialize());
-
                  
-                    for (var curTbIndex = 0; curTbIndex < tableNames.Count; curTbIndex++)
-                    {
-                        var tableName = tableNames[curTbIndex];
-                
-                        sourceRowCount = rowCounts[curTbIndex];
-
-                        using (var tableReader = GetDataTableReader(tableName,curTbIndex))
-                        {
-                            int importedRowCount = 0;
-
-                            SendMsg(EMsgType.Title, "");
-                            SendMsg(EMsgType.Title, "");
-                            SendMsg(EMsgType.Title, "");
-                            SendMsg(EMsgType.Title, $"       [{(curTbIndex + 1)}/{tableNames.Count}]start import table " + tableName + ",sourceRowCount:" + sourceRowCount);
-
-
-                            #region (x.1)数据源为DataReader
-                            if (tableReader.GetDataReader != null)
-                            {
-
-                                //(x.x.1)read data
-                                SendMsg(EMsgType.Nomal, " ");
-                                SendMsg(EMsgType.Nomal, "           [x.x.1]read data ");
-                                var dr = tableReader.GetDataReader();
-                               
-
-                                //(x.x.2)
-                                if (createTable)
-                                {
-                                    SendMsg(EMsgType.Title, "           [x.x.2]create table ");
-                                    try
-                                    {
-                                        conn.CreateTable(dr, tableName);
-                                    }
-                                    catch (Exception ex)
-                                    {
-                                        Logger.Error(ex);
-                                        SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                    }
-                                }
 
-                                //(x.x.3)
-                                if (delete)
-                                {
-                                    SendMsg(EMsgType.Title, "           [x.x.3]delete table ");
-                                    try
-                                    {
-                                        conn.Execute("delete from  " + conn.Quote(tableName));
-                                    }
-                                    catch (Exception ex)
-                                    {
-                                        Logger.Error(ex);
-                                        SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                    }
-                                }
-
-                                //(x.x.4)
-                                if (truncate)
-                                {
-                                    SendMsg(EMsgType.Title, "           [x.x.4]truncate table ");
-                                    try
-                                    {
-                                        conn.Execute("truncate table " + conn.Quote(tableName));
-                                    }
-                                    catch (Exception ex)
-                                    {
-                                        Logger.Error(ex);
-                                        SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                    }
-                                }
-
-
-                                //(x.x.5)import data   
-                                SendMsg(EMsgType.Nomal, "           [x.x.5]write data");
-                                try
-                                {
-                                    while (true)
-                                    {
-
-                                        int rowCount = conn.BulkImport(dr, tableName, maxRowCount: batchRowCount);
-
-                                        
-
-                                        importedRowCount += rowCount;
-                                        importedSumRowCount += rowCount;
-
-                                        WriteProcess(importedRowCount);
-
-                                        if (rowCount < batchRowCount)
-                                        {
-                                            break;
-                                        }
-
-                                    }
-
-                                }
-                                catch (Exception ex)
-                                {
-                                    Logger.Error(ex);
-                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                }
-
-                            }
-                            #endregion
-
-
-                            #region (x.2)数据源为DataTable
-                            if (tableReader.GetDataTable != null)
-                            {
-                                //(x.x.1)read data
-                                SendMsg(EMsgType.Nomal, " ");
-                                SendMsg(EMsgType.Nomal, "           [x.x.1]read data ");
-                                var dt = tableReader.GetDataTable();
-                                dt.TableName = tableName;
-
-                                //(x.x.2)
-                                if (createTable)
-                                {
-                                    SendMsg(EMsgType.Title, "           [x.x.2]create table ");
-                                    try
-                                    {
-                                        conn.CreateTable(dt);
-                                    }
-                                    catch (Exception ex)
-                                    {
-                                        Logger.Error(ex);
-                                        SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                    }
-                                }
-
-                                //(x.x.3)
-                                if (delete)
-                                {
-                                    SendMsg(EMsgType.Title, "           [x.x.3]delete table ");
-                                    try
-                                    {
-                                        conn.Execute("delete from  " + conn.Quote(tableName));
-                                    }
-                                    catch (Exception ex)
-                                    {
-                                        Logger.Error(ex);
-                                        SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                    }
-                                }
-
-                                //(x.x.4)
-                                if (truncate)
-                                {
-                                    SendMsg(EMsgType.Title, "           [x.x.4]truncate table ");
-                                    try
-                                    {
-                                        conn.Execute("truncate table " + conn.Quote(tableName));
-                                    }
-                                    catch (Exception ex)
-                                    {
-                                        Logger.Error(ex);
-                                        SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                    }
-                                }
-
-
-                                //(x.x.5)import data   
-                                SendMsg(EMsgType.Nomal, "           [x.x.5]write data,row count:" + dt.Rows.Count);
-                                try
-                                {
-                                    while (true)
-                                    {
-
-                                    
-                                        dt.TableName = tableName;
-                                        conn.BulkImport(dt);
-
-                                        int rowCount = dt.Rows.Count;
-                                        importedRowCount += dt.Rows.Count;
-                                        importedSumRowCount += dt.Rows.Count;
-
-
-                                        WriteProcess(importedRowCount);
-
-
-                                        SendMsg(EMsgType.Nomal, " ");
-                                        SendMsg(EMsgType.Nomal, "           [x.x.x.1]read data ");
-                                        dt = tableReader.GetDataTable();
-                                        if (dt == null)
-                                        {                                           
-                                            break;
-                                        }
-                                    }
-
-                                }
-                                catch (Exception ex)
-                                {
-                                    Logger.Error(ex);
-                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                }
-
-                            }
-                            #endregion
-
-
-                            SendMsg(EMsgType.Title, "                    import table " + tableName + " success,row count:" + importedRowCount);
-                        }
-                    }
-
-                    var span = (DateTime.Now - startTime);
+ 
 
-                    SendMsg(EMsgType.Title, "");
-                    SendMsg(EMsgType.Title, "");
-                    SendMsg(EMsgType.Title, "");
-                    SendMsg(EMsgType.Title, "   Import success");
-                    SendMsg(EMsgType.Title, "   sum row count:" + importedSumRowCount);
-                    SendMsg(EMsgType.Nomal, $"   耗时:{span.Hours}小时{span.Minutes}分{span.Seconds}秒{span.Milliseconds}毫秒");
-                }
+                #region (x.4)import data to database
+
+                //(x.x.1)初始化
+                var output = new DataOutput();
+                output.SendMsg=SendMsg;
+                output.type=type;
+                output.ConnectionString=ConnectionString;  
+                output.createTable=createTable;
+                output.delete=delete;
+                output.truncate=truncate;
+                output.tableInfos = tableNames.Select( (tableName, index) =>
+                    new TableInfo { tableName = tableName, tableIndex = index, rowCount = rowCounts[index] }
+                ).ToList();
+                output.sourceSumRowCount= rowCounts.Sum();
+
+                output.GetDataTableReader = GetDataTableReader;
+
+                //(x.x.2)数据导入
+                var startTime = DateTime.Now;
+                output.Output();
+
+                var span = (DateTime.Now - startTime);
+                SendMsg(EMsgType.Title, "");
+                SendMsg(EMsgType.Title, "");
+                SendMsg(EMsgType.Title, "");
+                SendMsg(EMsgType.Title, "   Import success");
+                SendMsg(EMsgType.Title, "   sum row count:" + output.importedSumRowCount);
+                SendMsg(EMsgType.Nomal, $"   耗时:{span.Hours}小时{span.Minutes}分{span.Seconds}秒{span.Milliseconds}毫秒");
                 #endregion
 
             }
@@ -920,9 +703,9 @@ namespace Sqler.Module.Sqler.Logical.DbPort
            string from_type,
            string from_ConnectionString,
            string from_sql,
+
            string to_type,
            string to_ConnectionString,
-
            bool createTable,
            bool delete,
            bool truncate
@@ -971,7 +754,7 @@ namespace Sqler.Module.Sqler.Logical.DbPort
                 List<string> tableNames = null;
                 List<int> rowCounts = null;
 
-                Func<DataTableReader> GetDataTableReader;
+                Func<string,int,DataTableReader> GetDataTableReader;
 
                 #region (x.2)init from_data
                 SendMsg(EMsgType.Title, "   init from_data");
@@ -998,10 +781,9 @@ namespace Sqler.Module.Sqler.Logical.DbPort
                 }
                 #endregion
 
-                var curTbIndex = 0;
-
+            
                 GetDataTableReader =
-                    () =>
+                    (tableName, curTbIndex) =>
                     {
                         var conn = ConnectionFactory.GetConnection(new Vit.Orm.Dapper.ConnectionInfo
                         { type = from_type, ConnectionString = from_ConnectionString });
@@ -1014,12 +796,7 @@ namespace Sqler.Module.Sqler.Logical.DbPort
                                 dataReader.Dispose();
                                 conn.Dispose();
                             },
-                            GetDataTable = () =>
-                            {
-                                if (curTbIndex < tableIndex)
-                                {
-                                    throw new Exception("系统出错!lith_20201004_01");
-                                }
+                            GetDataReader = () => {
 
                                 while (curTbIndex > tableIndex)
                                 {
@@ -1027,165 +804,46 @@ namespace Sqler.Module.Sqler.Logical.DbPort
                                     tableIndex++;
                                 }
 
-
-                                var dt = dataReader.ReadDataToDataTable(DbPortLogical.batchRowCount);
-
-                                if (dt == null)
-                                {
-                                    dataReader.NextResult();
-                                    tableIndex++;
-                                }
-                                else
-                                {
-                                    dt.TableName = tableNames[tableIndex];
-                                }
-                                return dt;
+                                return dataReader;
                             }
                         };
                     };
                 #endregion
 
 
-                #region (x.3)import data to to_data
-                int? sourceSumRowCount = rowCounts?.Sum();
-                using (var conn = ConnectionFactory.GetConnection(new Vit.Orm.Dapper.ConnectionInfo { type = to_type, ConnectionString = to_ConnectionString }))
-                using (var tableReader = GetDataTableReader())
-                {
-                    var startTime = DateTime.Now;
-
-                    SendMsg(EMsgType.Title, "   to database " + conn.Database);
 
-                    SendMsg(EMsgType.Title, "   sum row count: " + sourceSumRowCount);
-                    SendMsg(EMsgType.Title, "   table count: " + tableNames.Count);
-                    SendMsg(EMsgType.Title, "   table name: " + tableNames.Serialize());
+                #region (x.3)import data to database
 
-                    int importedSumRowCount = 0;
-                    for (; curTbIndex < tableNames.Count; curTbIndex++)
-                    {
-                        var tableName = tableNames[curTbIndex];
-                        int? sourceRowCount = rowCounts?[curTbIndex];
-                        {
-                            SendMsg(EMsgType.Title, "");
-                            SendMsg(EMsgType.Title, "");
-                            SendMsg(EMsgType.Title, "");
-                            SendMsg(EMsgType.Title, $"       [{(curTbIndex + 1)}/{tableNames.Count}]start import table " + tableName + ",sourceRowCount:" + sourceRowCount);
+                //(x.x.1)初始化
+                var output = new DataOutput();
+                output.SendMsg = SendMsg;
+                output.type = to_type;
+                output.ConnectionString = to_ConnectionString;
+                output.createTable = createTable;
+                output.delete = delete;
+                output.truncate = truncate;
+                output.tableInfos = tableNames.Select((tableName, index) =>
+                   new TableInfo { tableName = tableName, tableIndex = index, rowCount = rowCounts?[index]??-1 }
+                ).ToList();
+                output.sourceSumRowCount = rowCounts?.Sum()??-1;
 
-                            //(x.x.1)read data
-                            SendMsg(EMsgType.Nomal, " ");
-                            SendMsg(EMsgType.Nomal, "           [x.x.1]read data ");
+                output.GetDataTableReader = GetDataTableReader;
 
-                            var dt = tableReader.GetDataTable();
-                            if (dt == null)
-                            {
-                                SendMsg(EMsgType.Nomal, "           read none data!");
-                                continue;
-                            }
-                            //(x.x.2)
-                            if (createTable)
-                            {
-                                SendMsg(EMsgType.Title, "           [x.x.2]create table ");
-                                try
-                                {
-                                    conn.CreateTable(dt);
-                                }
-                                catch (Exception ex)
-                                {
-                                    Logger.Error(ex);
-                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                }
-                            }
+                //(x.x.2)数据导入
+                var startTime = DateTime.Now;
+                output.Output();
 
-                            //(x.x.3)
-                            if (delete)
-                            {
-                                SendMsg(EMsgType.Title, "           [x.x.3]delete table ");
-                                try
-                                {
-                                    conn.Execute("delete from  " + conn.Quote(dt.TableName));
-                                }
-                                catch (Exception ex)
-                                {
-                                    Logger.Error(ex);
-                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                }
-                            }
-
-                            //(x.x.4)
-                            if (truncate)
-                            {
-                                SendMsg(EMsgType.Title, "           [x.x.4]truncate table ");
-                                try
-                                {
-                                    conn.Execute("truncate table " + conn.Quote(dt.TableName));
-                                }
-                                catch (Exception ex)
-                                {
-                                    Logger.Error(ex);
-                                    SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                                }
-                            }
-
-
-                            //(x.x.5)import data
-                            int importedRowCount = 0;
-                            try
-                            {
-                                
-
-                                while (true)
-                                {
-
-                                    SendMsg(EMsgType.Nomal, "           [x.x.5]write data,row count:" + dt.Rows.Count);
-
-                                    conn.BulkImport(dt);
-
-                                    importedRowCount += dt.Rows.Count;
-                                    importedSumRowCount += dt.Rows.Count;
-
-                                    SendMsg(EMsgType.Nomal, "                      current              sum");
-                                    SendMsg(EMsgType.Nomal, $"            imported: {importedRowCount }      {importedSumRowCount }");
-
-                                    if (sourceRowCount.HasValue || sourceSumRowCount.HasValue)
-                                    {
-                                        SendMsg(EMsgType.Nomal, $"            total :   {sourceRowCount ?? 0}    {sourceSumRowCount ?? 0}");
-
-                                        SendMsg(EMsgType.Nomal, $@"            progress:   {
-                                            (sourceRowCount.HasValue ? (((float)importedRowCount) / sourceRowCount.Value * 100).ToString("f2") : "    ")
-                                            }%   {
-                                            (sourceSumRowCount.HasValue ? (((float)importedSumRowCount) / sourceSumRowCount.Value * 100).ToString("f2") : "")
-                                            }%");
-                                    }
-
-
-                                    SendMsg(EMsgType.Nomal, " ");
-                                    SendMsg(EMsgType.Nomal, "           [x.x.1]read data ");
-                                    dt = tableReader.GetDataTable();
-                                    if (dt == null)
-                                    {
-                                        SendMsg(EMsgType.Nomal, "           already read all data!");
-                                        break;
-                                    }
-                                }
-                            }
-                            catch (Exception ex)
-                            {
-                                Logger.Error(ex);
-                                SendMsg(EMsgType.Err, "出错。" + ex.GetBaseException().Message);
-                            }
-                            SendMsg(EMsgType.Title, "                    import table " + tableName + " success,row count:" + importedRowCount);
-                        }
-                    }
+                var span = (DateTime.Now - startTime);
+                SendMsg(EMsgType.Title, "");
+                SendMsg(EMsgType.Title, "");
+                SendMsg(EMsgType.Title, "");
+                SendMsg(EMsgType.Title, "   DataTransfer success");
+                SendMsg(EMsgType.Title, "   sum row count:" + output.importedSumRowCount);
+                SendMsg(EMsgType.Nomal, $"   耗时:{span.Hours}小时{span.Minutes}分{span.Seconds}秒{span.Milliseconds}毫秒");
+                #endregion
 
-                    var span = (DateTime.Now - startTime);
 
-                    SendMsg(EMsgType.Title, "");
-                    SendMsg(EMsgType.Title, "");
-                    SendMsg(EMsgType.Title, "");
-                    SendMsg(EMsgType.Title, "   DataTransfer success");
-                    SendMsg(EMsgType.Title, "   sum row count:" + importedSumRowCount);
-                    SendMsg(EMsgType.Nomal, $"   耗时:{span.Hours}小时{span.Minutes}分{span.Seconds}秒{span.Milliseconds}毫秒");
-                }
-                #endregion
+ 
 
             }
             catch (Exception ex)

+ 9 - 0
Sqler/Module/Sqler/Logical/DbPort/TableInfo.cs

@@ -0,0 +1,9 @@
+namespace Sqler.Module.Sqler.Logical.DbPort
+{
+    public class TableInfo
+    {
+        public int tableIndex;
+        public string tableName;
+        public int rowCount;
+    }
+}

+ 4 - 4
Sqler/Module/Sqler/Logical/SqlBackup/MySqlBackup/MySqlLogical.cs

@@ -42,9 +42,9 @@ namespace Sqler.Module.Sqler.Logical.SqlBackup.MySqlBackup
 
 
 
-        #region (x.8) SqlerBackup
+        #region (x.8) BackupSqler
 
-        public static void SqlerBackup(string filePath = null, string fileName = null)
+        public static void BackupSqler(string filePath = null, string fileName = null)
         {
             Logger.Info("[Sqler]MySqlDbMng Sqler备份数据库...");
             var startTime = DateTime.Now;
@@ -69,7 +69,7 @@ namespace Sqler.Module.Sqler.Logical.SqlBackup.MySqlBackup
 
 
 
-        #region (x.9) RemoteRestore
+        #region (x.9) Restore
         /// <summary>
         /// 
         /// </summary>
@@ -99,7 +99,7 @@ namespace Sqler.Module.Sqler.Logical.SqlBackup.MySqlBackup
                     }
                 }
 
-                filePath = dbMng.Restore(filePath); 
+                dbMng.Restore(filePath); 
             }
 
             var span = (DateTime.Now - startTime);

+ 18 - 3
Sqler/Module/Sqler/Logical/SqlBackup/SqlServerBackup/SqlServerLogical.cs

@@ -168,7 +168,13 @@ namespace App.Module.Sqler.Logical.SqlBackup.SqlServerBackup
 
         #region (x.9) Restore
 
-        public static void Restore(string filePath = null, string fileName = null)
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="filePath"></param>
+        /// <param name="fileName"></param>
+        /// <param name="force">若数据库已经存在,是否仍然还原</param>
+        public static void Restore(string filePath = null, string fileName = null, bool force = true)
         {
             Logger.Info("[Sqler]MsSqlDbMng 远程还原数据库...");
             var startTime = DateTime.Now;
@@ -182,6 +188,15 @@ namespace App.Module.Sqler.Logical.SqlBackup.SqlServerBackup
                     filePath = dbMng.BackupFile_GetPathByName(fileName);
                 }
 
+                if (!force)
+                {
+                    if (dbMng.GetDataBaseState() == Vit.Db.DbMng.EDataBaseState.online)
+                    {
+                        Logger.Info("[Sqler]MsSqlDbMng 已取消。数据库已经存在,且没有指定强制还原参数。");
+                        return;
+                    }
+                }
+
                 dbMng.Restore(filePath);
             }
 
@@ -196,7 +211,7 @@ namespace App.Module.Sqler.Logical.SqlBackup.SqlServerBackup
         #region (x.10) RestoreLocalBak
         public static void RestoreLocalBak( string filePath=null, string fileName = null)
         {
-            Logger.Info("[Sqler]MsSqlDbMng 还原本地数据库...");
+            Logger.Info("[Sqler]MsSqlDbMng 通过本地bak文件还原数据库...");
             var startTime = DateTime.Now;
 
             using (var conn = SqlerHelp.SqlServerBackup_CreateDbConnection())
@@ -212,7 +227,7 @@ namespace App.Module.Sqler.Logical.SqlBackup.SqlServerBackup
  
             }
             var span = (DateTime.Now - startTime);
-            Logger.Info("[Sqler]MsSqlDbMng 数据库已本地还原");
+            Logger.Info("[Sqler]MsSqlDbMng 数据库已通过本地bak文件还原");
             Logger.Info($"       耗时:{span.Hours}小时{span.Minutes}分{span.Seconds}秒{span.Milliseconds}毫秒");
             Logger.Info("       filePath:" + filePath);
         }

+ 3 - 3
Sqler/Sqler.csproj

@@ -5,7 +5,7 @@
     <ApplicationIcon />
     <OutputType>Exe</OutputType>
     <StartupObject /> 
-    <Version>2.25.310</Version>
+    <Version>2.25.313</Version>
     <Description>https://github.com/sersms/Sqler</Description>
     <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
     <PreserveCompilationContext>true</PreserveCompilationContext>
@@ -22,8 +22,8 @@
     <PackageReference Include="Microsoft.AspNetCore.App" />
     <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.8.0" />
  
-    <PackageReference Include="Vit.Orm.EntityFramework.Dynamic" Version="2.1.1.457" />
-    <PackageReference Include="Vit.WebHost" Version="2.1.1.457" />
+    <PackageReference Include="Vit.Orm.EntityFramework.Dynamic" Version="2.1.1.459" />
+    <PackageReference Include="Vit.WebHost" Version="2.1.1.459" />
   </ItemGroup>
   
   <ItemGroup>