diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs index f065e06..923a6cb 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs @@ -16,6 +16,7 @@ using static Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS.FolderToClean.X using System.Reflection; using System.Threading; using System.Windows.Forms; +using Microsoft.SqlServer.Management.SqlParser.Diagnostics; namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS { @@ -78,18 +79,33 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS { if (SilentMode) { return GetConsoleKey(ConsoleKey.Enter); } if (maxwaittime ==null || maxwaittime == TimeSpan.Zero) { return Console.ReadKey(); } - else - { - var strtime = DateTime.Now; - var endtime = strtime.Add(maxwaittime.Value); - var nexttime = strtime; - while (nexttime <= endtime) - { - if (Console.KeyAvailable) return Console.ReadKey(true); - Thread.Sleep(50); - nexttime = DateTime.Now; - } - return null; + + var strtime = DateTime.Now; + var endtime = strtime.Add(maxwaittime.Value); + + System.Timers.Timer t = new System.Timers.Timer(); + t.Interval = 500; + t.AutoReset = true; + t.Elapsed += T_Elapsed; + t.Start(); + + var nexttime = strtime; + while (nexttime <= endtime) + { + if (Console.KeyAvailable) break; + Thread.Sleep(50); + nexttime = DateTime.Now; + } + t.Stop(); + t.Dispose(); + t = null; + return Console.KeyAvailable ? Console.ReadKey(true) : (ConsoleKeyInfo?)null; + void T_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + var cursorposition_left = ColorConsole.CursorLeft; + var cursorposition_top = ColorConsole.CursorTop; + ColorConsole.Write($"{(int)(endtime.Subtract(DateTime.Now).TotalSeconds + 1)}", ConsoleColor.Yellow, prefix: " >>> ", suffix: " "); + ColorConsole.SetCursorPosition(cursorposition_left, cursorposition_top); } } public static ConsoleKeyInfo ReadKey() diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs index d9a0534..be1aeb7 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs @@ -995,7 +995,7 @@ GO { ColorConsole.Write(s.Key, ConsoleColor.Yellow, bracket: "[]",suffix:" ",prefix: " "); ColorConsole.Write(s.Name, ConsoleColor.Yellow, bracket: "[]", prefix: "Script:"); - if (s.Multirun) ColorConsole.Write("MULTIRUN", ConsoleColor.Red, bracket: "[]",prefix: " "); + if (!string.IsNullOrWhiteSpace(s.MultirunParameters)) ColorConsole.Write("MULTIRUN", ConsoleColor.Red, bracket: "[]",prefix: " "); ColorConsole.Write(s.Description, ConsoleColor.Yellow, prefix: " "); if (!string.IsNullOrWhiteSpace(s.FilePath)) { ColorConsole.Write(s.FilePath, ConsoleColor.Yellow, prefix: ", from file:"); } @@ -1012,15 +1012,15 @@ GO var confirm = ColorConsole.ReadLine("Enter CONFIRM to start! [EX]=exit.", ConsoleColor.Yellow, prefix:" ", suffix: " --> ", validitylist: new List() {"CONFIRM"}); if (confirm == "CONFIRM") { - bool multirunmode = ss.Multirun; + bool multirunmode = !string.IsNullOrWhiteSpace(ss.MultirunParameters); int commandtimeout = ss.CommandTimeout; ReturnInfoJSON result = null; using (var sqlc = ServerConnectionPool.GetSqlConnection(sqld.SQLCS, open: true)) { - if (multirunmode) { result = SQLDataBaseManagerCore.ExecuteMultirunSQLScript(sqlc, ss, ExitAfterOneRun); } + if (multirunmode) { result = SQLDataBaseManagerCore.ExecuteMultirunSQLScript(sqlc, ss, ExitAtThisPoint); } else { - if (!Tools.KvpString.Resolve(ss.ArgumentParameters, ss.ScriptText, out string ssScriptText)) { return o; } + if (!Tools.KvpString.Resolve(ss.ScriptParameters, ss.ScriptText, out string ssScriptText)) { return o; } ColorConsole.WriteLine(ssScriptText); result = SQLDataBaseManagerCore.ExecuteSQLScript(sqlc, ssScriptText, commandtimeout, null); } @@ -1045,16 +1045,26 @@ GO } return o; } - static bool ExitAfterOneRun(ReturnInfoJSON runresult) + private static DateTime timerend; + static bool ExitAtThisPoint(ReturnInfoJSON runresult,TimeSpan? waittime=null) { + if (waittime == TimeSpan.Zero) waittime = null; if (runresult != null) { ColorConsole.Write(runresult.ReturnValue==0?"OK":"NOK", runresult.ReturnValue == 0 ? ConsoleColor.Green : ConsoleColor.Red); ColorConsole.WriteLine(runresult.ReturnMessage, ConsoleColor.White,prefix:" "); } - var returnkey = ColorConsole.ReadKey(new TimeSpan(0, 0, 5)); - return returnkey != null; + ConsoleKeyInfo? returnkey = null; + if (waittime != null) + { + timerend = DateTime.Now.Add(waittime.Value); + ColorConsole.Write("Press any key to exit!", ConsoleColor.Yellow, prefix: " "); + returnkey = ColorConsole.ReadKey(waittime); + ColorConsole.WriteLine(); + } + return returnkey != null; } + private static object DropDB(object parameter, object o) { var config = (parameter as Menu.ExecutorParameter).GetConfig(); @@ -1932,105 +1942,82 @@ GO { DBKEY,DATABASE,DATASOURCE,DBOTYPE,DBONAME,DBDATAGROUP,BACKUPTS,SHRINKOPTION,SHRINKFREESPACEPERCENT, } - #endregion DBSubstitution + #endregion DBSubstitution - #region ExecuteSQLScriptWithMultipleRuns - /// - /// Executes a multirun script. Its parameters are in the