Commit 5449f858071a3036f1aa18b3652a9e96108b230b
1 parent
d4dde2c4
v1.31.1.0
Showing
3 changed files
with
159 additions
and
118 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
... | ... | @@ -16,6 +16,7 @@ using static Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS.FolderToClean.X |
16 | 16 | using System.Reflection; |
17 | 17 | using System.Threading; |
18 | 18 | using System.Windows.Forms; |
19 | +using Microsoft.SqlServer.Management.SqlParser.Diagnostics; | |
19 | 20 | |
20 | 21 | namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
21 | 22 | { |
... | ... | @@ -78,18 +79,33 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
78 | 79 | { |
79 | 80 | if (SilentMode) { return GetConsoleKey(ConsoleKey.Enter); } |
80 | 81 | if (maxwaittime ==null || maxwaittime == TimeSpan.Zero) { return Console.ReadKey(); } |
81 | - else | |
82 | - { | |
83 | - var strtime = DateTime.Now; | |
84 | - var endtime = strtime.Add(maxwaittime.Value); | |
85 | - var nexttime = strtime; | |
86 | - while (nexttime <= endtime) | |
87 | - { | |
88 | - if (Console.KeyAvailable) return Console.ReadKey(true); | |
89 | - Thread.Sleep(50); | |
90 | - nexttime = DateTime.Now; | |
91 | - } | |
92 | - return null; | |
82 | + | |
83 | + var strtime = DateTime.Now; | |
84 | + var endtime = strtime.Add(maxwaittime.Value); | |
85 | + | |
86 | + System.Timers.Timer t = new System.Timers.Timer(); | |
87 | + t.Interval = 500; | |
88 | + t.AutoReset = true; | |
89 | + t.Elapsed += T_Elapsed; | |
90 | + t.Start(); | |
91 | + | |
92 | + var nexttime = strtime; | |
93 | + while (nexttime <= endtime) | |
94 | + { | |
95 | + if (Console.KeyAvailable) break; | |
96 | + Thread.Sleep(50); | |
97 | + nexttime = DateTime.Now; | |
98 | + } | |
99 | + t.Stop(); | |
100 | + t.Dispose(); | |
101 | + t = null; | |
102 | + return Console.KeyAvailable ? Console.ReadKey(true) : (ConsoleKeyInfo?)null; | |
103 | + void T_Elapsed(object sender, System.Timers.ElapsedEventArgs e) | |
104 | + { | |
105 | + var cursorposition_left = ColorConsole.CursorLeft; | |
106 | + var cursorposition_top = ColorConsole.CursorTop; | |
107 | + ColorConsole.Write($"{(int)(endtime.Subtract(DateTime.Now).TotalSeconds + 1)}", ConsoleColor.Yellow, prefix: " >>> ", suffix: " "); | |
108 | + ColorConsole.SetCursorPosition(cursorposition_left, cursorposition_top); | |
93 | 109 | } |
94 | 110 | } |
95 | 111 | public static ConsoleKeyInfo ReadKey() | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
... | ... | @@ -995,7 +995,7 @@ GO |
995 | 995 | { |
996 | 996 | ColorConsole.Write(s.Key, ConsoleColor.Yellow, bracket: "[]",suffix:" ",prefix: " "); |
997 | 997 | ColorConsole.Write(s.Name, ConsoleColor.Yellow, bracket: "[]", prefix: "Script:"); |
998 | - if (s.Multirun) ColorConsole.Write("MULTIRUN", ConsoleColor.Red, bracket: "[]",prefix: " "); | |
998 | + if (!string.IsNullOrWhiteSpace(s.MultirunParameters)) ColorConsole.Write("MULTIRUN", ConsoleColor.Red, bracket: "[]",prefix: " "); | |
999 | 999 | ColorConsole.Write(s.Description, ConsoleColor.Yellow, prefix: " "); |
1000 | 1000 | if (!string.IsNullOrWhiteSpace(s.FilePath)) { ColorConsole.Write(s.FilePath, ConsoleColor.Yellow, prefix: ", from file:"); |
1001 | 1001 | } |
... | ... | @@ -1012,15 +1012,15 @@ GO |
1012 | 1012 | var confirm = ColorConsole.ReadLine("Enter CONFIRM to start! [EX]=exit.", ConsoleColor.Yellow, prefix:" ", suffix: " --> ", validitylist: new List<string>() {"CONFIRM"}); |
1013 | 1013 | if (confirm == "CONFIRM") |
1014 | 1014 | { |
1015 | - bool multirunmode = ss.Multirun; | |
1015 | + bool multirunmode = !string.IsNullOrWhiteSpace(ss.MultirunParameters); | |
1016 | 1016 | int commandtimeout = ss.CommandTimeout; |
1017 | 1017 | ReturnInfoJSON result = null; |
1018 | 1018 | using (var sqlc = ServerConnectionPool.GetSqlConnection(sqld.SQLCS, open: true)) |
1019 | 1019 | { |
1020 | - if (multirunmode) { result = SQLDataBaseManagerCore.ExecuteMultirunSQLScript(sqlc, ss, ExitAfterOneRun); } | |
1020 | + if (multirunmode) { result = SQLDataBaseManagerCore.ExecuteMultirunSQLScript(sqlc, ss, ExitAtThisPoint); } | |
1021 | 1021 | else |
1022 | 1022 | { |
1023 | - if (!Tools.KvpString.Resolve(ss.ArgumentParameters, ss.ScriptText, out string ssScriptText)) { return o; } | |
1023 | + if (!Tools.KvpString.Resolve(ss.ScriptParameters, ss.ScriptText, out string ssScriptText)) { return o; } | |
1024 | 1024 | ColorConsole.WriteLine(ssScriptText); |
1025 | 1025 | result = SQLDataBaseManagerCore.ExecuteSQLScript(sqlc, ssScriptText, commandtimeout, null); |
1026 | 1026 | } |
... | ... | @@ -1045,16 +1045,26 @@ GO |
1045 | 1045 | } |
1046 | 1046 | return o; |
1047 | 1047 | } |
1048 | - static bool ExitAfterOneRun(ReturnInfoJSON runresult) | |
1048 | + private static DateTime timerend; | |
1049 | + static bool ExitAtThisPoint(ReturnInfoJSON runresult,TimeSpan? waittime=null) | |
1049 | 1050 | { |
1051 | + if (waittime == TimeSpan.Zero) waittime = null; | |
1050 | 1052 | if (runresult != null) |
1051 | 1053 | { |
1052 | 1054 | ColorConsole.Write(runresult.ReturnValue==0?"OK":"NOK", runresult.ReturnValue == 0 ? ConsoleColor.Green : ConsoleColor.Red); |
1053 | 1055 | ColorConsole.WriteLine(runresult.ReturnMessage, ConsoleColor.White,prefix:" "); |
1054 | 1056 | } |
1055 | - var returnkey = ColorConsole.ReadKey(new TimeSpan(0, 0, 5)); | |
1056 | - return returnkey != null; | |
1057 | + ConsoleKeyInfo? returnkey = null; | |
1058 | + if (waittime != null) | |
1059 | + { | |
1060 | + timerend = DateTime.Now.Add(waittime.Value); | |
1061 | + ColorConsole.Write("Press any key to exit!", ConsoleColor.Yellow, prefix: " "); | |
1062 | + returnkey = ColorConsole.ReadKey(waittime); | |
1063 | + ColorConsole.WriteLine(); | |
1064 | + } | |
1065 | + return returnkey != null; | |
1057 | 1066 | } |
1067 | + | |
1058 | 1068 | private static object DropDB(object parameter, object o) |
1059 | 1069 | { |
1060 | 1070 | var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); |
... | ... | @@ -1932,105 +1942,82 @@ GO |
1932 | 1942 | { |
1933 | 1943 | DBKEY,DATABASE,DATASOURCE,DBOTYPE,DBONAME,DBDATAGROUP,BACKUPTS,SHRINKOPTION,SHRINKFREESPACEPERCENT, |
1934 | 1944 | } |
1935 | - #endregion DBSubstitution | |
1945 | + #endregion DBSubstitution | |
1936 | 1946 | |
1937 | - #region ExecuteSQLScriptWithMultipleRuns | |
1938 | - /// <summary> | |
1939 | - /// Executes a multirun script. Its parameters are in the <Script Parameters=> attribute, as list of KEY=VALUE; pairs. | |
1940 | - /// Keys: | |
1941 | - /// DAYSBACK (C# int value) or LIMITDATE (C# DateTime value): how many days from now, or from when the older rows should be deleted | |
1942 | - /// NUMOFDAYSINONERUN (C# int value): how many days are deleted in one run | |
1943 | - /// DELAYBETWEENRUNS (C# TimeSpan value): how much delay will be between runs | |
1944 | - /// TESTMODE (C# bool value): if testmode, no delete takes place | |
1945 | - /// </summary> | |
1946 | - /// <param name="sqlc">connectionstring az sql server-hez</param> | |
1947 | - /// <param name="sqlscript">az sql script (multirun interfész szerint!!!) | |
1948 | - /// this should be used in the script in the following way: | |
1949 | - /// DECLARE @RUNNINGMODE AS varchar(20) = '{RUNNINGMODE}' | |
1950 | - /// IF @RUNNINGMODE = 'GETTOTALRECORDS' | |
1951 | - /// THEN | |
1952 | - /// -- this part of the script should count the number of the rows of the dab, that will decrease after each run | |
1953 | - /// SELECT @RV, @RM -- @RV:0, @RM:the number of rows | |
1954 | - /// END | |
1955 | - /// ELSE IF @RUNNINGMODE = 'GETMINDATE' | |
1956 | - /// THEN | |
1957 | - /// -- this part of the script should return a DateTime value, that is the oldest date in the database | |
1958 | - /// SELECT @RV, @RM -- @RV:0, @RM:the Date, that is considered the oldest; no rows will be deleted before this | |
1959 | - /// END | |
1960 | - /// ELSE IF @RUNNINGMODE = 'ONERUN' | |
1961 | - /// THEN | |
1962 | - /// -- this part of the script deletes some rows from the database, older then a limitdate(parameter) | |
1963 | - /// -- parameter usage: DECLARE @RUNDELETEBEFOREDATE AS DATE = '{RUNDELETEBEFOREDATE}' | |
1964 | - /// SELECT @RV, @RM -- @RV:(0=OK, otherwise NOK), @RM:message with the result description | |
1965 | - /// END | |
1966 | - /// </param> | |
1967 | - /// <param name="ExitAfterOneRun">az a függvény, ami minde run után végrehajtásra kerül; | |
1968 | - /// bemenő paramétere az előző run eredménye, | |
1969 | - /// kimenő paramétere pedig igaz, ha ki kell lépni a végrehajtásból. | |
1970 | - /// </param> | |
1971 | - /// <returns></returns> | |
1972 | - public static ReturnInfoJSON ExecuteMultirunSQLScript(SqlConnection sqlc, SQLDataBase.SQLScript sqlscript, Func<ReturnInfoJSON, bool> ExitAfterOneRun=null) | |
1973 | - { | |
1974 | - var multirunresult = new List<KeyValuePair<string, string>>(); | |
1975 | - | |
1976 | - var argkvplist = (new Tools.KvpString(sqlscript.ArgumentParameters)).ResolveInteractive(); | |
1977 | - if(argkvplist==null) { return Finalize(0, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE)); } //user exit with selecting EX | |
1947 | + #region ExecuteSQLScriptWithMultipleRuns | |
1948 | + /// <summary> | |
1949 | + /// Executes a multirun script. Its parameters are in the <Script Parameters=> attribute, as list of KEY=VALUE; pairs. | |
1950 | + /// Keys: | |
1951 | + /// DAYSBACK (C# int value) or LIMITDATE (C# DateTime value): how many days from now, or from when the older rows should be deleted | |
1952 | + /// NUMOFDAYSINONERUN (C# int value): how many days are deleted in one run | |
1953 | + /// DELAYBETWEENRUNS (C# TimeSpan value): how much delay will be between runs | |
1954 | + /// TESTMODE (C# bool value): if testmode, no delete takes place | |
1955 | + /// </summary> | |
1956 | + /// <param name="sqlc">connectionstring az sql server-hez</param> | |
1957 | + /// <param name="sqlscript">az sql script (multirun interfész szerint!!!) | |
1958 | + /// this should be used in the script in the following way: | |
1959 | + /// DECLARE @RUNNINGMODE AS varchar(20) = '{RUNNINGMODE}' | |
1960 | + /// IF @RUNNINGMODE = 'GETTOTALRECORDS' | |
1961 | + /// THEN | |
1962 | + /// -- this part of the script should count the number of the rows of the dab, that will decrease after each run | |
1963 | + /// SELECT @RV, @RM -- @RV:0, @RM:the number of rows | |
1964 | + /// END | |
1965 | + /// ELSE IF @RUNNINGMODE = 'GETMINDATE' | |
1966 | + /// THEN | |
1967 | + /// -- this part of the script should return a DateTime value, that is the oldest date in the database | |
1968 | + /// SELECT @RV, @RM -- @RV:0, @RM:the Date, that is considered the oldest; no rows will be deleted before this | |
1969 | + /// END | |
1970 | + /// ELSE IF @RUNNINGMODE = 'ONERUN' | |
1971 | + /// THEN | |
1972 | + /// -- this part of the script deletes some rows from the database, older then a limitdate(parameter) | |
1973 | + /// -- parameter usage: DECLARE @RUNDELETEBEFOREDATE AS DATE = '{RUNDELETEBEFOREDATE}' | |
1974 | + /// SELECT @RV, @RM -- @RV:(0=OK, otherwise NOK), @RM:message with the result description | |
1975 | + /// END | |
1976 | + /// </param> | |
1977 | + /// <param name="ExitAtThisPoint">az a függvény, ami minde run után végrehajtásra kerül; | |
1978 | + /// bemenő paramétere az előző run eredménye, | |
1979 | + /// kimenő paramétere pedig igaz, ha ki kell lépni a végrehajtásból. | |
1980 | + /// </param> | |
1981 | + /// <returns></returns> | |
1978 | 1982 | |
1979 | - bool par_testmode; | |
1980 | - int par_limitdays; | |
1981 | - DateTime par_limitdate; | |
1982 | - TimeSpan par_lengthofonerun; | |
1983 | - TimeSpan par_delaybetweenruns; | |
1983 | + public static ReturnInfoJSON ExecuteMultirunSQLScript(SqlConnection sqlc, SQLDataBase.SQLScript sqlscript, Func<ReturnInfoJSON,TimeSpan?, bool> ExitAtThisPoint=null) | |
1984 | + { | |
1985 | + ReturnInfoJSON ret1=null; | |
1986 | + string sqltxt = null; | |
1987 | + int? getdbnumofrowsresult=null; | |
1988 | + DateTime? getdbmindateresult=null; | |
1984 | 1989 | |
1985 | - #region parameterek feldolgozása | |
1986 | - var testmodestring = argkvplist.GetValue(XMLPAR_TESTMODE, "false"); | |
1987 | - if ( !bool.TryParse(testmodestring, out par_testmode)) { return Finalize(1, Add(multirunresult, "Result", $"Parameter error:{XMLPAR_TESTMODE}")); } | |
1990 | + var multirunresult = new List<KeyValuePair<string, string>>(); | |
1988 | 1991 | |
1989 | - var daysbackstring = argkvplist.GetValue(XMLPAR_DAYSBACK, null); | |
1990 | - var limitdatestring = argkvplist.GetValue(XMLPAR_LIMITDATE, null); | |
1991 | - if (daysbackstring == null && limitdatestring == null) { par_limitdays = 90; par_limitdate = DateTime.Now.Subtract(new TimeSpan(par_limitdays, 0, 0, 0)); } | |
1992 | - else if (!string.IsNullOrEmpty(daysbackstring) && !string.IsNullOrEmpty(limitdatestring)) { return Finalize(1, Add(multirunresult, "Result", $"Parameter error:{XMLPAR_DAYSBACK} and {XMLPAR_LIMITDATE} are both defined.")); } | |
1993 | - else if (!string.IsNullOrEmpty(limitdatestring)) | |
1994 | - { | |
1995 | - if (!DateTime.TryParse(limitdatestring, out par_limitdate)) return Finalize(1, Add(multirunresult, "Result", $"Parameter error:" + XMLPAR_LIMITDATE)); | |
1996 | - par_limitdays = (int)DateTime.Now.Subtract(par_limitdate).TotalDays; | |
1997 | - } | |
1998 | - else /*if (!string.IsNullOrEmpty(daysbackstring)) */ | |
1999 | - { | |
2000 | - if(!int.TryParse(daysbackstring, out par_limitdays)) return Finalize(1, Add(multirunresult, "Result", $"Parameter error:" + XMLPAR_DAYSBACK)); | |
2001 | - par_limitdate = DateTime.Now.Subtract(new TimeSpan(par_limitdays, 0, 0, 0)); | |
2002 | - } | |
1992 | + var scriptparameterkvplist = (new Tools.KvpString(sqlscript.ScriptParameters)).ResolveInteractive(); | |
1993 | + string sqltxtalmostresolved = scriptparameterkvplist.Substitute(sqlscript.ScriptText); //parameters of the run are still unresolved | |
1994 | + if (sqltxtalmostresolved == null) {return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE));} //won't really get, but we never know... | |
2003 | 1995 | |
2004 | - if (!TimeSpan.TryParse(argkvplist.GetValue(XMLPAR_NUMOFDAYSINONERUN, "#$NONE#$"), out par_lengthofonerun)) { par_lengthofonerun = new TimeSpan(0, 12, 0); } | |
2005 | - if (!TimeSpan.TryParse(argkvplist.GetValue(XMLPAR_DELAYBETWEENRUNS, "#$NONE#$"), out par_delaybetweenruns)) { par_delaybetweenruns = new TimeSpan(0, 0, 10); } | |
2006 | - #endregion parameterek feldolgozása | |
2007 | - if (par_limitdays<=0) { return Finalize(0, Add(multirunresult, "Result", $"SKIPPED (function disabled).")); } | |
1996 | + //get number of total records in the database | |
1997 | + getdbnumofrowsresult = GetDBNumofRows(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); | |
1998 | + if (getdbnumofrowsresult == null) return Finalize(1, multirunresult); | |
1999 | + int numoftotaldbrecords_before = getdbnumofrowsresult.Value; | |
2008 | 2000 | |
2009 | - Add(multirunresult, $"LIMIT", $"{par_limitdays}days (before:{par_limitdate})"); | |
2010 | - Add(multirunresult, $"STAT", $"run length:{par_lengthofonerun.TotalHours}hours, delay between runs:{par_delaybetweenruns.TotalSeconds}sec"); | |
2011 | - Add(multirunresult, $"TESTMODE", $"{par_testmode}"); | |
2001 | + //get minimum date in the database | |
2002 | + getdbmindateresult = GetDBMindate(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); | |
2003 | + if (getdbmindateresult == null) return Finalize(1, multirunresult); | |
2004 | + DateTime mindateTS_before = getdbmindateresult.Value; | |
2005 | + var _multirunresult = multirunresult.Select(kvp => new KeyValuePair<string, string>(kvp.Key, kvp.Value)).ToList(); | |
2006 | + Add(_multirunresult, $"DBRECORDS", $"{numoftotaldbrecords_before}"); | |
2007 | + Add(_multirunresult, $"MINDATE", $"{mindateTS_before}"); | |
2008 | + | |
2009 | + var exithere = (ExitAtThisPoint?.Invoke(Finalize(0, _multirunresult),null)) ?? false; | |
2010 | + if (exithere) { Add(_multirunresult, $"Exit requested by user"); return Finalize(0, _multirunresult); } | |
2011 | + | |
2012 | + var multirunparameterskvplist = (new Tools.KvpString(sqlscript.MultirunParameters)).ResolveInteractive(); | |
2013 | + if(multirunparameterskvplist == null) { return Finalize(0, Add(multirunresult, ERRMSG_NOMULTIRUNPARAMETERS)); } //user exit with selecting EX | |
2014 | + var smrp = SetMultirunParameters(multirunparameterskvplist, multirunresult); | |
2015 | + if (smrp == null) { return Finalize(1, multirunresult);} | |
2016 | + (bool par_testmode, DateTime par_limitdate, TimeSpan par_lengthofonerun, TimeSpan par_delaybetweenruns) = smrp.Value; | |
2012 | 2017 | |
2013 | 2018 | try |
2014 | 2019 | { |
2015 | 2020 | DateTime starttime = DateTime.Now; |
2016 | - string sqltxtalmostresolved = argkvplist.Substitute(sqlscript.ScriptText); //parameters of the run are still unresolved | |
2017 | - if (sqltxtalmostresolved == null) {return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE));} //won't really get, but we never know... | |
2018 | - | |
2019 | - ReturnInfoJSON ret1=null; | |
2020 | - string sqltxt = null; | |
2021 | - int? getdbnumofrowsresult=null; | |
2022 | - DateTime? getdbmindateresult=null; | |
2023 | - | |
2024 | - //get number of total records in the database | |
2025 | - getdbnumofrowsresult = GetDBNumofRows(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); | |
2026 | - if (getdbnumofrowsresult == null) return Finalize(1, multirunresult); | |
2027 | - int numoftotaldbrecords_before = getdbnumofrowsresult.Value; | |
2028 | - | |
2029 | - //get minimum date in the database | |
2030 | - getdbmindateresult = GetDBMindate(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); | |
2031 | - if (getdbmindateresult == null) return Finalize(1, multirunresult); | |
2032 | - DateTime mindateTS_before = getdbmindateresult.Value; | |
2033 | - | |
2034 | 2021 | var limitdatefornextrun = mindateTS_before; |
2035 | 2022 | int exceptioncounter = 0; |
2036 | 2023 | const int MAXEXCEPTIONS = 3; //after this number of subsequent exceptions we exit |
... | ... | @@ -2064,7 +2051,7 @@ GO |
2064 | 2051 | runresult = 1; |
2065 | 2052 | if (exceptioncounter > MAXEXCEPTIONS) { return Finalize(1, multirunresult); } |
2066 | 2053 | } |
2067 | - var exitfromloop = (ExitAfterOneRun?.Invoke(Finalize(runresult, loople))) ?? false; | |
2054 | + var exitfromloop = (ExitAtThisPoint?.Invoke(Finalize(runresult, loople),new TimeSpan(0,0,5))) ?? false; | |
2068 | 2055 | if (exitfromloop) { Add(multirunresult, $"Exit requested by user"); break; } |
2069 | 2056 | Thread.Sleep((int)(par_delaybetweenruns.TotalMilliseconds)); |
2070 | 2057 | } |
... | ... | @@ -2087,6 +2074,43 @@ GO |
2087 | 2074 | } |
2088 | 2075 | catch (Exception ex) { return Finalize(1, Add(multirunresult, ex)); } |
2089 | 2076 | } |
2077 | + private static (bool par_testmode, DateTime par_limitdate, TimeSpan par_lengthofonerun, TimeSpan par_delaybetweenruns)? SetMultirunParameters(Tools.KvpString argkvplist,List<KeyValuePair<string, string>> multirunresult) | |
2078 | + { | |
2079 | + bool par_testmode; | |
2080 | + int par_limitdays; | |
2081 | + DateTime par_limitdate; | |
2082 | + TimeSpan par_lengthofonerun; | |
2083 | + TimeSpan par_delaybetweenruns; | |
2084 | + | |
2085 | + #region parameterek feldolgozása | |
2086 | + var testmodestring = argkvplist.GetValue(XMLPAR_TESTMODE, "false"); | |
2087 | + if (!bool.TryParse(testmodestring, out par_testmode)) { Add(multirunresult, "Result", $"Parameter error:{XMLPAR_TESTMODE}"); return null; } | |
2088 | + | |
2089 | + var daysbackstring = argkvplist.GetValue(XMLPAR_DAYSBACK, null); | |
2090 | + var limitdatestring = argkvplist.GetValue(XMLPAR_LIMITDATE, null); | |
2091 | + if (daysbackstring == null && limitdatestring == null) { par_limitdays = 90; par_limitdate = DateTime.Now.Subtract(new TimeSpan(par_limitdays, 0, 0, 0)); } | |
2092 | + else if (!string.IsNullOrEmpty(daysbackstring) && !string.IsNullOrEmpty(limitdatestring)) { Add(multirunresult, "Result", $"Parameter error:{XMLPAR_DAYSBACK} and {XMLPAR_LIMITDATE} are both defined."); return null; } | |
2093 | + else if (!string.IsNullOrEmpty(limitdatestring)) | |
2094 | + { | |
2095 | + if (!DateTime.TryParse(limitdatestring, out par_limitdate)) { Add(multirunresult, "Result", $"Parameter error:" + XMLPAR_LIMITDATE); return null; } | |
2096 | + par_limitdays = (int)DateTime.Now.Subtract(par_limitdate).TotalDays; | |
2097 | + } | |
2098 | + else /*if (!string.IsNullOrEmpty(daysbackstring)) */ | |
2099 | + { | |
2100 | + if (!int.TryParse(daysbackstring, out par_limitdays)) { Add(multirunresult, "Result", $"Parameter error:" + XMLPAR_DAYSBACK); return null; } | |
2101 | + par_limitdate = DateTime.Now.Subtract(new TimeSpan(par_limitdays, 0, 0, 0)); | |
2102 | + } | |
2103 | + | |
2104 | + if (!TimeSpan.TryParse(argkvplist.GetValue(XMLPAR_NUMOFDAYSINONERUN, "#$NONE#$"), out par_lengthofonerun)) { par_lengthofonerun = new TimeSpan(0, 12, 0); } | |
2105 | + if (!TimeSpan.TryParse(argkvplist.GetValue(XMLPAR_DELAYBETWEENRUNS, "#$NONE#$"), out par_delaybetweenruns)) { par_delaybetweenruns = new TimeSpan(0, 0, 10); } | |
2106 | + #endregion parameterek feldolgozása | |
2107 | + if (par_limitdays <= 0) { Add(multirunresult, "Result", $"SKIPPED (function disabled)."); return null; } | |
2108 | + | |
2109 | + Add(multirunresult, $"LIMIT", $"{par_limitdays}days (before:{par_limitdate})"); | |
2110 | + Add(multirunresult, $"STAT", $"run length:{par_lengthofonerun.TotalHours}hours, delay between runs:{par_delaybetweenruns.TotalSeconds}sec"); | |
2111 | + Add(multirunresult, $"TESTMODE", $"{par_testmode}"); | |
2112 | + return (par_testmode, par_limitdate, par_lengthofonerun, par_delaybetweenruns); | |
2113 | + } | |
2090 | 2114 | private static DateTime? GetDBMindate(string sqltxtalmostresolved, List<KeyValuePair<string, string>> multirunresult,int commandtimeout, SqlConnection sqlc) |
2091 | 2115 | { |
2092 | 2116 | //get minimum date in the database |
... | ... | @@ -2118,6 +2142,7 @@ GO |
2118 | 2142 | const string XMLPAR_LIMITDATE = "LIMITDATE"; |
2119 | 2143 | |
2120 | 2144 | const string ERRMSG_NOTHINGTOEXECUTE = "FAILURE! Nothing to execute! Check script definition entry!"; |
2145 | + const string ERRMSG_NOMULTIRUNPARAMETERS = "FAILURE! Multirun parameters are not defined!"; | |
2121 | 2146 | |
2122 | 2147 | private static List<KeyValuePair<string, string>> Add(List<KeyValuePair<string, string>> kvp, string a, string b=null) { kvp.Add(new KeyValuePair<string, string>(a, b)); return kvp; } |
2123 | 2148 | private static List<KeyValuePair<string, string>> Add(List<KeyValuePair<string, string>> kvp,Exception ex) { string errmsg = ""; while (ex != null) { errmsg += ex.Message; ex = ex.InnerException; } return Add(kvp, "EXCEPTION RESULT",errmsg); } |
... | ... | @@ -2832,7 +2857,7 @@ GO |
2832 | 2857 | public static class Description { public static class Values { public const string DEFAULT = ""; } } |
2833 | 2858 | public static class ScriptCommandTimeout { public static class Values { public const int DEFAULT = 10000; } } |
2834 | 2859 | public static class Parameters { public static class Values { public const string DEFAULT = ""; } } |
2835 | - public static class Multirun { public static class Values { public const bool DEFAULT = false; } } | |
2860 | + public static class Multirun { public static class Values { public const string DEFAULT = ""; } } | |
2836 | 2861 | } |
2837 | 2862 | } |
2838 | 2863 | } |
... | ... | @@ -2848,23 +2873,23 @@ GO |
2848 | 2873 | public string Description = ""; |
2849 | 2874 | public string ScriptText = ""; |
2850 | 2875 | public int CommandTimeout = 10000; |
2851 | - public string ArgumentParameters; | |
2852 | - public bool Multirun = false; | |
2876 | + public string ScriptParameters=null; | |
2877 | + public string MultirunParameters=null; | |
2853 | 2878 | |
2854 | 2879 | public SQLScript() { } |
2855 | 2880 | public SQLScript(SQLScript sqls) { Name = sqls.Name; Description = sqls.Description; ScriptText= sqls.ScriptText; } |
2856 | 2881 | public SQLScript(XElement sqlscriptXml, int defaultcommandtimeout, int index) |
2857 | 2882 | { |
2858 | - ArgumentParameters = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Parameters), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Parameters.Values.DEFAULT); | |
2883 | + ScriptParameters = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Parameters), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Parameters.Values.DEFAULT); | |
2884 | + MultirunParameters= GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Multirun), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Multirun.Values.DEFAULT); | |
2859 | 2885 | |
2860 | 2886 | Key = $"S{index}"; |
2861 | 2887 | Name = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Name), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Name.Values.DEFAULT); |
2862 | 2888 | FilePath = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.File), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.File.Values.DEFAULT); |
2863 | 2889 | Description= GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Description), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Description.Values.DEFAULT); |
2864 | - Multirun= GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Multirun), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Multirun.Values.DEFAULT); | |
2865 | 2890 | |
2866 | - Tools.KvpString.Resolve(ArgumentParameters, this.Name, out this.Name, disableinteractive: true); | |
2867 | - Tools.KvpString.Resolve(ArgumentParameters, this.Description, out this.Description, disableinteractive: true); | |
2891 | + Tools.KvpString.Resolve(ScriptParameters, this.Name, out this.Name, disableinteractive: true); | |
2892 | + Tools.KvpString.Resolve(ScriptParameters, this.Description, out this.Description, disableinteractive: true); | |
2868 | 2893 | if (string.IsNullOrWhiteSpace(this.FilePath)) |
2869 | 2894 | { |
2870 | 2895 | ScriptText = GetValue(sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Values.DEFAULT); | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
... | ... | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; |
32 | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
33 | 33 | // by using the '*' as shown below: |
34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.31.0.0")] | |
36 | -[assembly: AssemblyFileVersion("1.31.0.0")] | |
35 | +[assembly: AssemblyVersion("1.31.1.0")] | |
36 | +[assembly: AssemblyFileVersion("1.31.1.0")] | ... | ... |