diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
index 799a0ab..f065e06 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
+++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
@@ -10,6 +10,12 @@ using System.Diagnostics;
using Vrh.XmlProcessing;
using System.Xml.Linq;
+using Microsoft.SqlServer.Management.Smo;
+using static Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS.CLP.Module.ScheduledTaskManager.Function;
+using static Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS.FolderToClean.XmlStructure.FolderToClean.Conditions.Condition.Attributes;
+using System.Reflection;
+using System.Threading;
+using System.Windows.Forms;
namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS
{
@@ -68,17 +74,35 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS
/// Visszaadja a lenyomott billentyűt, ha van, commandmode-ban pedig az enter-t
///
///
- public static ConsoleKeyInfo ReadKey()
- {
- if (SilentMode) { return GetConsoleKey(ConsoleKey.Enter); }
- else { return Console.ReadKey(); }
- }
+ public static ConsoleKeyInfo? ReadKey(TimeSpan? maxwaittime)
+ {
+ 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;
+ }
+ }
+ public static ConsoleKeyInfo ReadKey()
+ {
+ if (SilentMode) { return GetConsoleKey(ConsoleKey.Enter); }
+ else { return Console.ReadKey(); }
+ }
- ///
- /// Visszaadja a lenyomott billentyűt, ha van, commandmode-ban pedig az enter-t
- ///
- ///
- public static ConsoleKeyInfo GetConsoleKey(ConsoleKey ck, bool shift = false, bool alt=false,bool control=false)
+ ///
+ /// Visszaadja a lenyomott billentyűt, ha van, commandmode-ban pedig az enter-t
+ ///
+ ///
+ public static ConsoleKeyInfo GetConsoleKey(ConsoleKey ck, bool shift = false, bool alt=false,bool control=false)
{
switch (ck)
{
diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs
index 3889178..486cdf9 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs
+++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs
@@ -65,7 +65,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS
ExternalProcess.StartInfo.FileName = config.Exe;
ExternalProcess.StartInfo.WindowStyle = config.ProcessWindowsStyle;
- if (!Tools.ResolveArguments(config.ArgumentParameters, config.Arguments, out string resolvedtext)) { return o; };
+ if (!Tools.KvpString.Resolve(config.ArgumentParameters, config.Arguments, out string resolvedtext)) { return o; };
ExternalProcess.StartInfo.Arguments = resolvedtext;
ExternalProcess.Start();
int waitingtime = config.WaitForExit ? -1 : 0;
@@ -633,8 +633,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS
Exe = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Exe), x, "");
this.Key = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Key), x, "");
this.Description = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Description), x, Exe);
- Tools.ResolveArguments(ArgumentParameters, this.Key,out this.Key,interactive:false);
- Tools.ResolveArguments(ArgumentParameters, this.Description, out this.Description, interactive: false);
+ Tools.KvpString.Resolve(ArgumentParameters, this.Key,out this.Key,disableinteractive:true);
+ Tools.KvpString.Resolve(ArgumentParameters, this.Description, out this.Description, disableinteractive: true);
Arguments = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Arguments), x, XmlStructure.ExternalUtility.Attributes.Arguments.Values.DEFAULT);
ProcessWindowsStyle = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.WindowStyle), x, XmlStructure.ExternalUtility.Attributes.WindowStyle.Values.DEFAULT);
diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
index 51ba6f4..d9a0534 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
+++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
@@ -26,6 +26,12 @@ using System.Text.RegularExpressions;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.Data.SqlClient;
+using Microsoft.Identity.Client;
+using VRH.Common.Log4ProIS;
+using System.Security.Cryptography;
+using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
+using System.Windows.Controls;
+using Menu = Vrh.Log4Pro.MaintenanceConsole.MenuNS.Menu;
namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS
{
@@ -926,27 +932,30 @@ GO
else { return null; }
}
- string ssScriptText = null;
- string LastUpdatedTrigger_parameters = $"DBNAME={triggertoexecute.Db};SCHEMA={triggertoexecute.Schema};TABLE={triggertoexecute.Table};COLUMN={triggertoexecute.Column};TRIGGER={LastUpdatedTrigger_triggername};";
- if (!Tools.ResolveArguments(LastUpdatedTrigger_parameters, RemoveLastUpdatedTrigger_Script, out ssScriptText)) { throw new ApplicationException(); }
- try { SQLDataBaseManagerCore.ExecuteSQLScript(sqlcs, ssScriptText, 5000, null); }
- catch (Exception e) { ColorConsole.WriteLine(e.MessageNested(), ConsoleColor.Yellow); }
- if (!Tools.ResolveArguments(LastUpdatedTrigger_parameters, RemoveLastUpdatedColumn_Script, out ssScriptText)) { throw new ApplicationException(); }
- try { SQLDataBaseManagerCore.ExecuteSQLScript(sqlcs, ssScriptText, 5000, null); }
- catch (Exception e) { ColorConsole.WriteLine(e.MessageNested(), ConsoleColor.Yellow); }
-
- if (!triggertoexecute.Remove)
+ using (var sqlc = ServerConnectionPool.GetSqlConnection(sqlcs, open: true))
{
- if (!Tools.ResolveArguments(LastUpdatedTrigger_parameters, CreateLastUpdatedColumn_Script, out ssScriptText)) { throw new ApplicationException(); }
- SQLDataBaseManagerCore.ExecuteSQLScript(sqlcs, ssScriptText, 5000, null);
+ string ssScriptText = null;
+ string LastUpdatedTrigger_parameters = $"DBNAME={triggertoexecute.Db};SCHEMA={triggertoexecute.Schema};TABLE={triggertoexecute.Table};COLUMN={triggertoexecute.Column};TRIGGER={LastUpdatedTrigger_triggername};";
+ if (!Tools.KvpString.Resolve(LastUpdatedTrigger_parameters, RemoveLastUpdatedTrigger_Script, out ssScriptText)) { throw new ApplicationException(); }
+ try { SQLDataBaseManagerCore.ExecuteSQLScript(sqlc, ssScriptText, 5000, null); }
+ catch (Exception e) { ColorConsole.WriteLine(e.MessageNested(), ConsoleColor.Yellow); }
+ if (!Tools.KvpString.Resolve(LastUpdatedTrigger_parameters, RemoveLastUpdatedColumn_Script, out ssScriptText)) { throw new ApplicationException(); }
+ try { SQLDataBaseManagerCore.ExecuteSQLScript(sqlc, ssScriptText, 5000, null); }
+ catch (Exception e) { ColorConsole.WriteLine(e.MessageNested(), ConsoleColor.Yellow); }
+
+ if (!triggertoexecute.Remove)
+ {
+ if (!Tools.KvpString.Resolve(LastUpdatedTrigger_parameters, CreateLastUpdatedColumn_Script, out ssScriptText)) { throw new ApplicationException(); }
+ SQLDataBaseManagerCore.ExecuteSQLScript(sqlc, ssScriptText, 5000, null);
- if (!Tools.ResolveArguments(LastUpdatedTrigger_parameters, CreateLastUpdatedTrigger_Script, out ssScriptText)) { throw new ApplicationException(); }
- SQLDataBaseManagerCore.ExecuteSQLScript(sqlcs, ssScriptText, 5000, null);
+ if (!Tools.KvpString.Resolve(LastUpdatedTrigger_parameters, CreateLastUpdatedTrigger_Script, out ssScriptText)) { throw new ApplicationException(); }
+ SQLDataBaseManagerCore.ExecuteSQLScript(sqlc, ssScriptText, 5000, null);
- if (!Tools.ResolveArguments(LastUpdatedTrigger_parameters, EnableLastUpdatedTrigger_Script, out ssScriptText)) { throw new ApplicationException(); }
- SQLDataBaseManagerCore.ExecuteSQLScript(sqlcs, ssScriptText, 5000, null);
+ if (!Tools.KvpString.Resolve(LastUpdatedTrigger_parameters, EnableLastUpdatedTrigger_Script, out ssScriptText)) { throw new ApplicationException(); }
+ SQLDataBaseManagerCore.ExecuteSQLScript(sqlc, ssScriptText, 5000, null);
+ }
}
- ColorConsole.WriteLine($"SUCCESS! {removeactionText} trigger to store LastUpdate TimeStamp: {LastUpdatedTrigger_fulldesignation}", ConsoleColor.Green);
+ ColorConsole.WriteLine($"SUCCESS! {removeactionText} trigger to store LastUpdate TimeStamp: {LastUpdatedTrigger_fulldesignation}", ConsoleColor.Green);
}
catch (ApplicationException e) { ColorConsole.WriteLine("FATAL ERROR! in script parameter substitution!", ConsoleColor.Red); returntext = null; }
catch (Exception e) { ColorConsole.WriteLine("FATAL ERROR! " + e.MessageNested(), ConsoleColor.Red); returntext = null; }
@@ -985,29 +994,49 @@ GO
foreach (var s in sqld.Xml_SQLScriptList)
{
ColorConsole.Write(s.Key, ConsoleColor.Yellow, bracket: "[]",suffix:" ",prefix: " ");
- var fromfile = string.IsNullOrWhiteSpace(s.FilePath) ? "": $",from:{s.FilePath}";
- ColorConsole.Write($"{s.Description} ({s.Name}{fromfile})", ConsoleColor.Yellow, prefix: "Script:");
- ColorConsole.WriteLine();
+ ColorConsole.Write(s.Name, ConsoleColor.Yellow, bracket: "[]", prefix: "Script:");
+ if (s.Multirun) 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:");
+ }
+ ColorConsole.WriteLine();
vlist.Add(s.Key);
}
var scriptkey = ColorConsole.ReadLine("Select the script! [empty]=next DB, [*]=all, [EX]=exit.", ConsoleColor.Yellow, prefix:" ", suffix: " --> ", validitylist: vlist);
if (string.IsNullOrWhiteSpace(scriptkey)) { continue; }
if (scriptkey.ToUpper() == "EX") { return o; }
SQLDataBase.SQLScript ss = sqld.Xml_SQLScriptList.FirstOrDefault(s=>s.Key==scriptkey);
- if (!Tools.ResolveArguments(ss.ArgumentParameters, ss.ScriptText,out string ssScriptText)) { return o; }
- if (ss.ScriptText == null)
- {
- ColorConsole.WriteLine($"Nothing to execute!. Check script definition entry!", ConsoleColor.Red);
- }
+ if (string.IsNullOrWhiteSpace(ss.ScriptText)) { ColorConsole.WriteLine($"Nothing to execute!. Check script definition entry!", ConsoleColor.Red); }
else
{
- ColorConsole.WriteLine(ssScriptText);
var confirm = ColorConsole.ReadLine("Enter CONFIRM to start! [EX]=exit.", ConsoleColor.Yellow, prefix:" ", suffix: " --> ", validitylist: new List() {"CONFIRM"});
if (confirm == "CONFIRM")
{
- SQLDataBaseManagerCore.ExecuteSQLScript(sqld.SQLCS, ssScriptText, ss.CommandTimeout, null);
- ColorConsole.WriteLine($"Script executed. Name:{sqld.DBName}, script name: {ss.Name}", ConsoleColor.Green);
- }
+ bool multirunmode = ss.Multirun;
+ int commandtimeout = ss.CommandTimeout;
+ ReturnInfoJSON result = null;
+ using (var sqlc = ServerConnectionPool.GetSqlConnection(sqld.SQLCS, open: true))
+ {
+ if (multirunmode) { result = SQLDataBaseManagerCore.ExecuteMultirunSQLScript(sqlc, ss, ExitAfterOneRun); }
+ else
+ {
+ if (!Tools.KvpString.Resolve(ss.ArgumentParameters, ss.ScriptText, out string ssScriptText)) { return o; }
+ ColorConsole.WriteLine(ssScriptText);
+ result = SQLDataBaseManagerCore.ExecuteSQLScript(sqlc, ssScriptText, commandtimeout, null);
+ }
+ }
+ if (result.ReturnValue == 0)
+ {
+ ColorConsole.WriteLine(result.ReturnMessage, ConsoleColor.White);
+ ColorConsole.WriteLine($"Script execution SUCCESS. Name:{sqld.DBName}, script name: {ss.Name}", ConsoleColor.Green);
+ }
+ else
+ {
+ ColorConsole.WriteLine(result.ReturnMessage, ConsoleColor.White);
+ ColorConsole.WriteLine($"Script execution FAILURE. Name:{sqld.DBName}, script name: {ss.Name}", ConsoleColor.Red);
+ }
+
+ }
else {ColorConsole.WriteLine($"Script was NOT executed!", ConsoleColor.Red);}
}
}
@@ -1016,6 +1045,16 @@ GO
}
return o;
}
+ static bool ExitAfterOneRun(ReturnInfoJSON runresult)
+ {
+ 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;
+ }
private static object DropDB(object parameter, object o)
{
var config = (parameter as Menu.ExecutorParameter).GetConfig();
@@ -1893,32 +1932,218 @@ 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