Commit 270019f650128eed7cdecb590c553b016d36dfb4
1 parent
e312d490
v1.11.0
- SQLDBManager-ben a DB-khez rendelt script-ek végrehajtása
Showing
6 changed files
with
185 additions
and
57 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
@@ -134,7 +134,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS | @@ -134,7 +134,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS | ||
134 | /// <param name="exitvalue"></param> | 134 | /// <param name="exitvalue"></param> |
135 | /// <param name="required"></param> | 135 | /// <param name="required"></param> |
136 | /// <returns></returns> | 136 | /// <returns></returns> |
137 | - public static string ReadLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "", string suffix = "", List<string> validitylist = null, string exitvalue = "EX", string defaultvalue = null, bool required = false) | 137 | + public static string ReadLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null |
138 | + , string prefix = "", string suffix = "", List<string> validitylist = null, string exitvalue = "EX", string defaultvalue = null, bool required = false) | ||
138 | { | 139 | { |
139 | string input; | 140 | string input; |
140 | while (true) | 141 | while (true) |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
@@ -301,6 +301,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS | @@ -301,6 +301,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS | ||
301 | } | 301 | } |
302 | public static class RelocatePhysicalFiles { public const string KEY = "COP"; } | 302 | public static class RelocatePhysicalFiles { public const string KEY = "COP"; } |
303 | public static class ShrinkDB { public const string KEY = "SHR"; } | 303 | public static class ShrinkDB { public const string KEY = "SHR"; } |
304 | + public static class ExecuteScript{ public const string KEY = "EXE"; } | ||
304 | } | 305 | } |
305 | } | 306 | } |
306 | 307 |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs
@@ -302,6 +302,48 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | @@ -302,6 +302,48 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | ||
302 | if (list32.Count() > 0) { if (list64.Count() > 0) { os = "64bit"; } else { os = "32bit"; } } | 302 | if (list32.Count() > 0) { if (list64.Count() > 0) { os = "64bit"; } else { os = "32bit"; } } |
303 | return os; | 303 | return os; |
304 | } | 304 | } |
305 | + public static bool ResolveArguments(string parameterkvpstring, string stringwithparameters, out string resolvedtext, bool interactive = true) | ||
306 | + { | ||
307 | + var argumentparametersdictionary = parameterkvpstring.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries) | ||
308 | + .Select(kvp => CreateKVP(kvp)) | ||
309 | + .Where(kvp => kvp.Key != null) | ||
310 | + .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); | ||
311 | + Dictionary<string, string> resolveddictionary = new Dictionary<string, string>(); | ||
312 | + resolvedtext = stringwithparameters; | ||
313 | + foreach (var kvp in argumentparametersdictionary) | ||
314 | + { | ||
315 | + if (kvp.Value.StartsWith("?") && interactive) | ||
316 | + { | ||
317 | + string prompt = $"Enter value for {kvp.Key}:"; | ||
318 | + string kvpdefaultvalue = null; | ||
319 | + if (kvp.Value.Length > 1) | ||
320 | + { | ||
321 | + prompt = kvp.Value.Substring(1).Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0]; | ||
322 | + if (kvp.Value.Substring(1).IndexOf('?') != -1) kvpdefaultvalue = kvp.Value.Substring(1).Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[1]; | ||
323 | + } | ||
324 | + string value = ColorConsole.ReadLine(prompt, ConsoleColor.Yellow, defaultvalue: kvpdefaultvalue); | ||
325 | + if (value.ToLower() == "ex") { return false; } | ||
326 | + resolveddictionary.Add(kvp.Key, value); | ||
327 | + } | ||
328 | + else if (kvp.Value.StartsWith("?") && !interactive) resolveddictionary.Add(kvp.Key, $"{{{kvp.Key}}}"); | ||
329 | + else { resolveddictionary.Add(kvp.Key, kvp.Value); } | ||
330 | + } | ||
331 | + resolvedtext = VRH.Common.StringConstructor.ResolveConstructorR(resolveddictionary, stringwithparameters, "{}@@"); | ||
332 | + return true; | ||
333 | + } | ||
334 | + private static KeyValuePair<string, string> CreateKVP(string kvpstring) | ||
335 | + { | ||
336 | + string kvpk = null; | ||
337 | + string kvpv = null; | ||
338 | + try | ||
339 | + { | ||
340 | + kvpk = kvpstring.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries)[0]; if (string.IsNullOrWhiteSpace(kvpk)) { kvpk = null; } | ||
341 | + kvpv = kvpstring.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries)[1]; | ||
342 | + KeyValuePair<string, string> r = new KeyValuePair<string, string>(kvpk, kvpv); | ||
343 | + return r; | ||
344 | + } | ||
345 | + catch { return new KeyValuePair<string, string>(kvpk, null); } | ||
346 | + } | ||
305 | } | 347 | } |
306 | 348 | ||
307 | class ComputerInfo | 349 | class ComputerInfo |
@@ -451,5 +493,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | @@ -451,5 +493,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | ||
451 | return rexmsg.Replace("\n\n","\n"); | 493 | return rexmsg.Replace("\n\n","\n"); |
452 | } | 494 | } |
453 | } | 495 | } |
496 | + | ||
454 | #endregion ExceptionExtension class | 497 | #endregion ExceptionExtension class |
455 | } | 498 | } |
Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs
@@ -63,7 +63,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS | @@ -63,7 +63,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS | ||
63 | ExternalProcess.StartInfo.FileName = config.Exe; | 63 | ExternalProcess.StartInfo.FileName = config.Exe; |
64 | ExternalProcess.StartInfo.WindowStyle = config.ProcessWindowsStyle; | 64 | ExternalProcess.StartInfo.WindowStyle = config.ProcessWindowsStyle; |
65 | 65 | ||
66 | - ExternalProcess.StartInfo.Arguments = config.ResolveArguments(); | 66 | + if (!Tools.ResolveArguments(config.ArgumentParameters, config.Arguments, out string resolvedtext)) { return o; }; |
67 | + ExternalProcess.StartInfo.Arguments = resolvedtext; | ||
67 | ExternalProcess.Start(); | 68 | ExternalProcess.Start(); |
68 | int waitingtime = config.WaitForExit ? -1 : 0; | 69 | int waitingtime = config.WaitForExit ? -1 : 0; |
69 | ExternalProcess.WaitForExit(waitingtime); | 70 | ExternalProcess.WaitForExit(waitingtime); |
@@ -382,16 +383,15 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS | @@ -382,16 +383,15 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS | ||
382 | { | 383 | { |
383 | public ExternalUtilityConfig(XElement x) | 384 | public ExternalUtilityConfig(XElement x) |
384 | { | 385 | { |
385 | - ArgumentParametersDictionary = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.ArgumentParameters), x, XmlStructure.ExternalUtility.Attributes.ArgumentParameters.Values.DEFAULT).Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries) | ||
386 | - .Select(kvp => CreateKVP(kvp)) | ||
387 | - .Where(kvp => kvp.Key != null) | ||
388 | - .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); | 386 | + ArgumentParameters = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.ArgumentParameters), x, XmlStructure.ExternalUtility.Attributes.ArgumentParameters.Values.DEFAULT); |
389 | 387 | ||
390 | - Key = VRH.Common.StringConstructor.ResolveConstructorR(ArgumentParametersDictionary, GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Key), x, ""), "{}@@"); | ||
391 | - Description = VRH.Common.StringConstructor.ResolveConstructorR(ArgumentParametersDictionary, GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Description), x, Exe), "{}@@"); | 388 | + Exe = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Exe), x, ""); |
389 | + this.Key = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Key), x, ""); | ||
390 | + this.Description = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Description), x, Exe); | ||
391 | + Tools.ResolveArguments(ArgumentParameters, this.Key,out this.Key,interactive:false); | ||
392 | + Tools.ResolveArguments(ArgumentParameters, this.Description, out this.Description, interactive: false); | ||
392 | Arguments = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Arguments), x, XmlStructure.ExternalUtility.Attributes.Arguments.Values.DEFAULT); | 393 | Arguments = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Arguments), x, XmlStructure.ExternalUtility.Attributes.Arguments.Values.DEFAULT); |
393 | 394 | ||
394 | - Exe = GetValue(nameof(XmlStructure.ExternalUtility.Attributes.Exe), x, ""); | ||
395 | ProcessWindowsStyle = GetValue<ProcessWindowStyle>(nameof(XmlStructure.ExternalUtility.Attributes.WindowStyle), x, XmlStructure.ExternalUtility.Attributes.WindowStyle.Values.DEFAULT); | 395 | ProcessWindowsStyle = GetValue<ProcessWindowStyle>(nameof(XmlStructure.ExternalUtility.Attributes.WindowStyle), x, XmlStructure.ExternalUtility.Attributes.WindowStyle.Values.DEFAULT); |
396 | WaitForExit= GetValue(nameof(XmlStructure.ExternalUtility.Attributes.WaitForExit), x, XmlStructure.ExternalUtility.Attributes.WaitForExit.Values.DEFAULT); | 396 | WaitForExit= GetValue(nameof(XmlStructure.ExternalUtility.Attributes.WaitForExit), x, XmlStructure.ExternalUtility.Attributes.WaitForExit.Values.DEFAULT); |
397 | Valid = !string.IsNullOrWhiteSpace(Key) && !string.IsNullOrWhiteSpace(Exe) && !string.IsNullOrWhiteSpace(Description); | 397 | Valid = !string.IsNullOrWhiteSpace(Key) && !string.IsNullOrWhiteSpace(Exe) && !string.IsNullOrWhiteSpace(Description); |
@@ -399,43 +399,11 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS | @@ -399,43 +399,11 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS | ||
399 | public string Key = XmlStructure.ExternalUtility.Attributes.Key.Values.DEFAULT; | 399 | public string Key = XmlStructure.ExternalUtility.Attributes.Key.Values.DEFAULT; |
400 | public string Description = XmlStructure.ExternalUtility.Attributes.Description.Values.DEFAULT; | 400 | public string Description = XmlStructure.ExternalUtility.Attributes.Description.Values.DEFAULT; |
401 | public string Arguments = XmlStructure.ExternalUtility.Attributes.Arguments.Values.DEFAULT; | 401 | public string Arguments = XmlStructure.ExternalUtility.Attributes.Arguments.Values.DEFAULT; |
402 | - public Dictionary<string,string> ArgumentParametersDictionary = null; | 402 | + public string ArgumentParameters = XmlStructure.ExternalUtility.Attributes.ArgumentParameters.Values.DEFAULT; |
403 | public string Exe = XmlStructure.ExternalUtility.Attributes.Exe.Values.DEFAULT; | 403 | public string Exe = XmlStructure.ExternalUtility.Attributes.Exe.Values.DEFAULT; |
404 | public ProcessWindowStyle ProcessWindowsStyle = XmlStructure.ExternalUtility.Attributes.WindowStyle.Values.DEFAULT; | 404 | public ProcessWindowStyle ProcessWindowsStyle = XmlStructure.ExternalUtility.Attributes.WindowStyle.Values.DEFAULT; |
405 | public bool WaitForExit=XmlStructure.ExternalUtility.Attributes.WaitForExit.Values.DEFAULT; | 405 | public bool WaitForExit=XmlStructure.ExternalUtility.Attributes.WaitForExit.Values.DEFAULT; |
406 | public bool Valid; | 406 | public bool Valid; |
407 | - | ||
408 | - private static KeyValuePair<string, string> CreateKVP(string kvpstring) | ||
409 | - { | ||
410 | - string kvpk = null; | ||
411 | - string kvpv = null; | ||
412 | - try | ||
413 | - { | ||
414 | - kvpk = kvpstring.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries)[0]; if (string.IsNullOrWhiteSpace(kvpk)) { kvpk = null; } | ||
415 | - kvpv = kvpstring.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries)[1]; | ||
416 | - KeyValuePair<string, string> r = new KeyValuePair<string, string>(kvpk, kvpv); | ||
417 | - return r; | ||
418 | - } | ||
419 | - catch { return new KeyValuePair<string, string>(kvpk, null); } | ||
420 | - } | ||
421 | - public string ResolveArguments() | ||
422 | - { | ||
423 | - var resolveddictionary = new Dictionary<string, string>(); | ||
424 | - foreach (var kvp in ArgumentParametersDictionary) | ||
425 | - { | ||
426 | - if (!kvp.Value.StartsWith("?")) { resolveddictionary.Add(kvp.Key, kvp.Value); } | ||
427 | - else | ||
428 | - { | ||
429 | - string prompt; | ||
430 | - if (kvp.Value.Length == 1) { prompt = $"Enter value for {kvp.Key}:"; } | ||
431 | - else { prompt = kvp.Value.Substring(1); } | ||
432 | - string value = ColorConsole.ReadLine(prompt, ConsoleColor.Yellow); | ||
433 | - if (value.ToLower() == "ex") { Valid = false; return null; } | ||
434 | - resolveddictionary.Add(kvp.Key, value); | ||
435 | - } | ||
436 | - } | ||
437 | - return VRH.Common.StringConstructor.ResolveConstructorR(resolveddictionary, Arguments, "{}@@"); | ||
438 | - } | ||
439 | } | 407 | } |
440 | public XElement RegexpTesterConfig; | 408 | public XElement RegexpTesterConfig; |
441 | public XElement PingerConfigXml; | 409 | public XElement PingerConfigXml; |
Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
@@ -49,6 +49,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -49,6 +49,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
49 | .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.RestoreDataBase.KEY, "Restore database backup", RestoreDataBase, ep)) | 49 | .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.RestoreDataBase.KEY, "Restore database backup", RestoreDataBase, ep)) |
50 | .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.RelocatePhysicalFiles.KEY, "Copy database and or relocate its physical files", RelocatePhysicalFiles, ep)) | 50 | .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.RelocatePhysicalFiles.KEY, "Copy database and or relocate its physical files", RelocatePhysicalFiles, ep)) |
51 | .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.ShrinkDB.KEY, "Shrink database", ShrinkDB, ep)) | 51 | .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.ShrinkDB.KEY, "Shrink database", ShrinkDB, ep)) |
52 | + .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.ExecuteScript.KEY, "Execute script", ExecuteScript, ep)) | ||
52 | .SetSelectionMode(Menu.SelectionMode.Single) | 53 | .SetSelectionMode(Menu.SelectionMode.Single) |
53 | .SetMenuHeaderDisplayer(DataBaseListDisplayer); | 54 | .SetMenuHeaderDisplayer(DataBaseListDisplayer); |
54 | menufunctions.ExecuteMenu(functionkey); | 55 | menufunctions.ExecuteMenu(functionkey); |
@@ -215,6 +216,56 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -215,6 +216,56 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
215 | } | 216 | } |
216 | return o; | 217 | return o; |
217 | } | 218 | } |
219 | + private static object ExecuteScript(object parameter, object o) | ||
220 | + { | ||
221 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); | ||
222 | + var args = (parameter as Menu.ExecutorParameter).Args; | ||
223 | + | ||
224 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | ||
225 | + | ||
226 | + var menufolders = DisplaySQLDataBaseMenu(config, $"Select the SQL database(s) to manage with function '{nameof(ExecuteScript)}'!", silent: true); | ||
227 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | ||
228 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | ||
229 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | ||
230 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | ||
231 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | ||
232 | + else { } | ||
233 | + foreach (var p in sr.SelectedParameterList) | ||
234 | + { | ||
235 | + SQLDataBase sqld = p.Parameters as SQLDataBase; | ||
236 | + try | ||
237 | + { | ||
238 | + if (sqld.Xml_SQLScriptList.Count==0) | ||
239 | + { | ||
240 | + ColorConsole.WriteLine($"There are no scripts for database. Name:{sqld.DBName}, server: {sqld.DataSource}", ConsoleColor.Red); | ||
241 | + } | ||
242 | + else | ||
243 | + { | ||
244 | + ColorConsole.WriteLine(); | ||
245 | + ColorConsole.WriteLine($"Select the scripts for database. Name:{sqld.DBName}, server: {sqld.DataSource}", ConsoleColor.Yellow); | ||
246 | + var vlist = new List<string>(); | ||
247 | + foreach (var s in sqld.Xml_SQLScriptList) | ||
248 | + { | ||
249 | + ColorConsole.Write(s.Key, ConsoleColor.Yellow, bracket: "[]",suffix:" ",prefix: " "); | ||
250 | + ColorConsole.Write($"{s.Description} ({s.Name})", ConsoleColor.Yellow, prefix: "Script:"); | ||
251 | + ColorConsole.WriteLine(); | ||
252 | + vlist.Add(s.Key); | ||
253 | + } | ||
254 | + var scriptkey = ColorConsole.ReadLine("Select the script! [empty]=next DB, [*]=all, [EX]=exit.", ConsoleColor.Yellow, prefix:" ", suffix: " --> ", validitylist: vlist); | ||
255 | + if (string.IsNullOrWhiteSpace(scriptkey)) { continue; } | ||
256 | + if (scriptkey.ToLower()=="ex") { return o; } | ||
257 | + SQLDataBase.SQLScript ss = sqld.Xml_SQLScriptList.FirstOrDefault(s=>s.Key==scriptkey); | ||
258 | + if (!Tools.ResolveArguments(ss.ArgumentParameters, ss.ScriptText,out string ssScriptText)) { return o; } | ||
259 | + ColorConsole.WriteLine(ssScriptText); | ||
260 | + //SQLDataBaseManagerCore.ExecuteSQLScript(sqld.SQLCS, ssScriptText, ss.CommandTimeout, null); | ||
261 | + ColorConsole.WriteLine($"Script executed. Name:{sqld.DBName}, script name: {ss.Name}", ConsoleColor.Green); | ||
262 | + } | ||
263 | + } | ||
264 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | ||
265 | + } | ||
266 | + return o; | ||
267 | + } | ||
268 | + | ||
218 | private static object ShrinkDB(object parameter, object o) | 269 | private static object ShrinkDB(object parameter, object o) |
219 | { | 270 | { |
220 | var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); | 271 | var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); |
@@ -303,13 +354,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -303,13 +354,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
303 | #region private methods | 354 | #region private methods |
304 | #region private DisplaySQLDataBaseMenu | 355 | #region private DisplaySQLDataBaseMenu |
305 | private static void DataBaseListDisplayer() { DisplaySQLDataBaseMenu(); } | 356 | private static void DataBaseListDisplayer() { DisplaySQLDataBaseMenu(); } |
306 | - private static Menu DisplaySQLDataBaseMenu(SQLDataBaseManagerXmlProcessor config = null, string prompt = null, bool silent = false) | 357 | + private static Menu DisplaySQLDataBaseMenu(SQLDataBaseManagerXmlProcessor config = null, string prompt = null, bool silent = false, Menu.SelectionMode selectionmode = Menu.SelectionMode.Multi) |
307 | { | 358 | { |
308 | if (config == null) { config = new SQLDataBaseManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); } | 359 | if (config == null) { config = new SQLDataBaseManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); } |
309 | List<SQLDataBase> schtskdefList = config.GetDefinitionList(); | 360 | List<SQLDataBase> schtskdefList = config.GetDefinitionList(); |
310 | var menufct = new Menu("SQL Databases", prompt) | 361 | var menufct = new Menu("SQL Databases", prompt) |
311 | .SetMenuItemDisplayer(DisplayDataBaseInfo) | 362 | .SetMenuItemDisplayer(DisplayDataBaseInfo) |
312 | - .SetSelectionMode(Menu.SelectionMode.Multi); | 363 | + .SetSelectionMode(selectionmode); |
313 | menufct.ClearMenuItemList(); | 364 | menufct.ClearMenuItemList(); |
314 | foreach (var schtskdef in schtskdefList) | 365 | foreach (var schtskdef in schtskdefList) |
315 | { | 366 | { |
@@ -363,6 +414,15 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -363,6 +414,15 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
363 | ColorConsole.WriteLine(" "); | 414 | ColorConsole.WriteLine(" "); |
364 | return " "; | 415 | return " "; |
365 | } | 416 | } |
417 | + else if (5 <= lineix && lineix <= 5 + st.Xml_SQLScriptList.Count) | ||
418 | + { | ||
419 | + if (st.Xml_SQLScriptList.Count == 0) { return null; } | ||
420 | + if (st.Xml_SQLScriptList.Count-1 < lineix-5) { return null; } | ||
421 | + var s = st.Xml_SQLScriptList.ToArray()[lineix-5]; | ||
422 | + ColorConsole.Write(s.Key, ConsoleColor.Yellow, bracket: "[]", suffix: " ", prefix: " Script: "); | ||
423 | + ColorConsole.WriteLine($"{s.Description} ({s.Name})", ConsoleColor.Yellow); | ||
424 | + return " "; | ||
425 | + } | ||
366 | return null; | 426 | return null; |
367 | } | 427 | } |
368 | #endregion private method: DisplayDataBaseInfo | 428 | #endregion private method: DisplayDataBaseInfo |
@@ -723,11 +783,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -723,11 +783,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
723 | else { return new ReturnInfoJSON() { ReturnValue = 0, ReturnMessage = null, }; } | 783 | else { return new ReturnInfoJSON() { ReturnValue = 0, ReturnMessage = null, }; } |
724 | } | 784 | } |
725 | 785 | ||
726 | - | ||
727 | - | ||
728 | - | ||
729 | - | ||
730 | - | 786 | + /// <summary> |
787 | + /// Egy SQL batch végrehajtása | ||
788 | + /// </summary> | ||
789 | + /// <param name="sqlc"></param> | ||
790 | + /// <param name="sqlbatchtxt"></param> | ||
791 | + /// <param name="commandtimeout"></param> | ||
792 | + /// <returns></returns> | ||
731 | private static System.Data.DataSet ExecuteSQLScriptBatch(Microsoft.Data.SqlClient.SqlConnection sqlc, string sqlbatchtxt, int commandtimeout) | 793 | private static System.Data.DataSet ExecuteSQLScriptBatch(Microsoft.Data.SqlClient.SqlConnection sqlc, string sqlbatchtxt, int commandtimeout) |
732 | { | 794 | { |
733 | var sqlcommand = sqlc.CreateCommand(); | 795 | var sqlcommand = sqlc.CreateCommand(); |
@@ -1064,7 +1126,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -1064,7 +1126,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
1064 | public SQLDataBaseManagerXmlProcessor(string xmlcs, string basefolder, string lcid) : base(xmlcs, basefolder, lcid, null) | 1126 | public SQLDataBaseManagerXmlProcessor(string xmlcs, string basefolder, string lcid) : base(xmlcs, basefolder, lcid, null) |
1065 | { | 1127 | { |
1066 | _sqldatabaselist = new List<SQLDataBase>(); | 1128 | _sqldatabaselist = new List<SQLDataBase>(); |
1067 | - var schtskxmllist = GetAllXElements(nameof(SQLDataBase.XmlStructure.SQLDataBase)); | ||
1068 | var common = new SQLDataBase() | 1129 | var common = new SQLDataBase() |
1069 | { | 1130 | { |
1070 | Xml_CreateZip = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.CreateZip), this.RootElement, SQLDataBase.XmlStructure.Attributes.CreateZip.Values.DEFAULT), | 1131 | Xml_CreateZip = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.CreateZip), this.RootElement, SQLDataBase.XmlStructure.Attributes.CreateZip.Values.DEFAULT), |
@@ -1072,11 +1133,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -1072,11 +1133,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
1072 | Xml_RestoreFileNameMask = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.RestoreFileNameMask), this.RootElement, SQLDataBase.XmlStructure.Attributes.RestoreFileNameMask.Values.DEFAULT), | 1133 | Xml_RestoreFileNameMask = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.RestoreFileNameMask), this.RootElement, SQLDataBase.XmlStructure.Attributes.RestoreFileNameMask.Values.DEFAULT), |
1073 | Xml_BackupTargetDirectoryPath = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.BackupTargetDirectoryPath), this.RootElement, SQLDataBase.XmlStructure.Attributes.BackupTargetDirectoryPath.Values.DEFAULT), | 1134 | Xml_BackupTargetDirectoryPath = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.BackupTargetDirectoryPath), this.RootElement, SQLDataBase.XmlStructure.Attributes.BackupTargetDirectoryPath.Values.DEFAULT), |
1074 | Xml_PhysicalFilesDirectoryPath = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.PhysicalFilesDirectoryPath), this.RootElement, SQLDataBase.XmlStructure.Attributes.PhysicalFilesDirectoryPath.Values.DEFAULT), | 1135 | Xml_PhysicalFilesDirectoryPath = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.PhysicalFilesDirectoryPath), this.RootElement, SQLDataBase.XmlStructure.Attributes.PhysicalFilesDirectoryPath.Values.DEFAULT), |
1075 | - | 1136 | + Xml_ScriptCommandTimeout = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.ScriptCommandTimeout), this.RootElement, SQLDataBase.XmlStructure.Attributes.ScriptCommandTimeout.Values.DEFAULT), |
1076 | }; | 1137 | }; |
1077 | - if (schtskxmllist != null && schtskxmllist.Any()) | 1138 | + var sqldatabasexmllist = GetAllXElements(nameof(SQLDataBase.XmlStructure.SQLDataBase)); |
1139 | + if (sqldatabasexmllist != null && sqldatabasexmllist.Any()) | ||
1078 | { | 1140 | { |
1079 | - foreach (var schtskxml in schtskxmllist) { var st = new SQLDataBase(schtskxml,common); if (st.Valid) { _sqldatabaselist.Add(st); } } | 1141 | + foreach (var sqldatabasexml in sqldatabasexmllist) { var st = new SQLDataBase(sqldatabasexml,common); if (st.Valid) { _sqldatabaselist.Add(st); } } |
1080 | } | 1142 | } |
1081 | } | 1143 | } |
1082 | #endregion constructor | 1144 | #endregion constructor |
@@ -1099,7 +1161,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -1099,7 +1161,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
1099 | public string Xml_BackupTargetDirectoryPath; | 1161 | public string Xml_BackupTargetDirectoryPath; |
1100 | public string Xml_SQLConnectionString; | 1162 | public string Xml_SQLConnectionString; |
1101 | public string Xml_PhysicalFilesDirectoryPath; | 1163 | public string Xml_PhysicalFilesDirectoryPath; |
1164 | + public int Xml_ScriptCommandTimeout; | ||
1102 | public List<SQLData> Xml_SQLDataList; | 1165 | public List<SQLData> Xml_SQLDataList; |
1166 | + public List<SQLScript> Xml_SQLScriptList; | ||
1103 | 1167 | ||
1104 | public string DBName; | 1168 | public string DBName; |
1105 | public string DataSource; | 1169 | public string DataSource; |
@@ -1128,11 +1192,19 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -1128,11 +1192,19 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
1128 | Xml_BackupTargetDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.BackupTargetDirectoryPath), sqldatabasexml, common.Xml_BackupTargetDirectoryPath); | 1192 | Xml_BackupTargetDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.BackupTargetDirectoryPath), sqldatabasexml, common.Xml_BackupTargetDirectoryPath); |
1129 | Xml_SQLConnectionString = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.SQLConnectionString), sqldatabasexml, XmlStructure.SQLDataBase.Attributes.SQLConnectionString.Values.DEFAULT); | 1193 | Xml_SQLConnectionString = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.SQLConnectionString), sqldatabasexml, XmlStructure.SQLDataBase.Attributes.SQLConnectionString.Values.DEFAULT); |
1130 | 1194 | ||
1131 | - var sqldataXmlList = GetAllXElements(sqldatabasexml, nameof(XmlStructure.SQLDataBase.SQLData)); | ||
1132 | Xml_CreateZip = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.CreateZip), sqldatabasexml, common.Xml_CreateZip); | 1195 | Xml_CreateZip = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.CreateZip), sqldatabasexml, common.Xml_CreateZip); |
1133 | Xml_PhysicalFilesDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.PhysicalFilesDirectoryPath), sqldatabasexml, common.Xml_PhysicalFilesDirectoryPath); | 1196 | Xml_PhysicalFilesDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.PhysicalFilesDirectoryPath), sqldatabasexml, common.Xml_PhysicalFilesDirectoryPath); |
1197 | + | ||
1198 | + Xml_ScriptCommandTimeout = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.ScriptCommandTimeout), sqldatabasexml, common.Xml_ScriptCommandTimeout); | ||
1199 | + | ||
1134 | Xml_SQLDataList = new List<SQLData>(); | 1200 | Xml_SQLDataList = new List<SQLData>(); |
1201 | + var sqldataXmlList = GetAllXElements(sqldatabasexml, nameof(XmlStructure.SQLDataBase.SQLData)); | ||
1135 | if (sqldataXmlList!=null) { foreach (var sqldataXml in sqldataXmlList) { Xml_SQLDataList.Add(new SQLData(sqldataXml)); } } | 1202 | if (sqldataXmlList!=null) { foreach (var sqldataXml in sqldataXmlList) { Xml_SQLDataList.Add(new SQLData(sqldataXml)); } } |
1203 | + | ||
1204 | + Xml_SQLScriptList = new List<SQLScript>(); | ||
1205 | + var sqlscriptsXml = GetXElement(sqldatabasexml, nameof(XmlStructure.SQLDataBase.Scripts)); | ||
1206 | + var sqlscriptXmlList = GetAllXElements(sqlscriptsXml, nameof(XmlStructure.SQLDataBase.Scripts.Script)); | ||
1207 | + if (sqlscriptXmlList != null) { int scriptindex = 1; foreach (var sqlscriptXml in sqlscriptXmlList) { Xml_SQLScriptList.Add(new SQLScript(sqlscriptXml, Xml_ScriptCommandTimeout,scriptindex++)); } } | ||
1136 | } | 1208 | } |
1137 | #endregion xml constructor | 1209 | #endregion xml constructor |
1138 | #region cloner constructor | 1210 | #region cloner constructor |
@@ -1147,7 +1219,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -1147,7 +1219,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
1147 | Xml_BackupTargetDirectoryPath = sqld.Xml_BackupTargetDirectoryPath; | 1219 | Xml_BackupTargetDirectoryPath = sqld.Xml_BackupTargetDirectoryPath; |
1148 | Xml_SQLConnectionString = sqld.Xml_SQLConnectionString; | 1220 | Xml_SQLConnectionString = sqld.Xml_SQLConnectionString; |
1149 | Xml_PhysicalFilesDirectoryPath = sqld.Xml_PhysicalFilesDirectoryPath; | 1221 | Xml_PhysicalFilesDirectoryPath = sqld.Xml_PhysicalFilesDirectoryPath; |
1150 | - Xml_SQLDataList = sqld.Xml_SQLDataList.Select(x => x).ToList(); | 1222 | + Xml_SQLDataList = sqld.Xml_SQLDataList.Select(x => new SQLData(x)).ToList(); |
1223 | + Xml_SQLScriptList = sqld.Xml_SQLScriptList.Select(x => new SQLScript(x)).ToList(); | ||
1151 | } | 1224 | } |
1152 | #endregion cloner constructor | 1225 | #endregion cloner constructor |
1153 | #region XmlStructure | 1226 | #region XmlStructure |
@@ -1159,6 +1232,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -1159,6 +1232,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
1159 | public static class RestoreFileNameMask { public static class Values { public const string DEFAULT = ""; } } | 1232 | public static class RestoreFileNameMask { public static class Values { public const string DEFAULT = ""; } } |
1160 | public static class BackupTargetDirectoryPath { public static class Values { public const string DEFAULT = ""; } } | 1233 | public static class BackupTargetDirectoryPath { public static class Values { public const string DEFAULT = ""; } } |
1161 | public static class PhysicalFilesDirectoryPath { public static class Values { public const string DEFAULT = ""; } } | 1234 | public static class PhysicalFilesDirectoryPath { public static class Values { public const string DEFAULT = ""; } } |
1235 | + public static class ScriptCommandTimeout { public static class Values { public const int DEFAULT = 10000; } } | ||
1162 | 1236 | ||
1163 | 1237 | ||
1164 | public static class CreateZip{ public static class Values { public const bool DEFAULT = true; } } | 1238 | public static class CreateZip{ public static class Values { public const bool DEFAULT = true; } } |
@@ -1175,6 +1249,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -1175,6 +1249,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
1175 | public static class BackupTargetDirectoryPath { } | 1249 | public static class BackupTargetDirectoryPath { } |
1176 | public static class CreateZip { } | 1250 | public static class CreateZip { } |
1177 | public static class PhysicalFilesDirectoryPath { } | 1251 | public static class PhysicalFilesDirectoryPath { } |
1252 | + public static class ScriptCommandTimeout { public static class Values { public const int DEFAULT = 10000; } } | ||
1178 | } | 1253 | } |
1179 | public static class SQLData | 1254 | public static class SQLData |
1180 | { | 1255 | { |
@@ -1184,9 +1259,49 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -1184,9 +1259,49 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
1184 | public static class Group { public static class Values { public const string DEFAULT = ""; } } | 1259 | public static class Group { public static class Values { public const string DEFAULT = ""; } } |
1185 | } | 1260 | } |
1186 | } | 1261 | } |
1262 | + public static class Scripts | ||
1263 | + { | ||
1264 | + public static class Script | ||
1265 | + { | ||
1266 | + public static class Values { public const string DEFAULT = ""; } | ||
1267 | + public static class Attributes | ||
1268 | + { | ||
1269 | + public static class Name { public static class Values { public const string DEFAULT = ""; } } | ||
1270 | + public static class Description { public static class Values { public const string DEFAULT = ""; } } | ||
1271 | + public static class ScriptCommandTimeout { public static class Values { public const int DEFAULT = 10000; } } | ||
1272 | + public static class Parameters { public static class Values { public const string DEFAULT = ""; } } | ||
1273 | + } | ||
1274 | + } | ||
1275 | + } | ||
1187 | } | 1276 | } |
1188 | } | 1277 | } |
1189 | #endregion XmlStructure | 1278 | #endregion XmlStructure |
1279 | + #region SQLScript class | ||
1280 | + public class SQLScript : XmlLinqBase | ||
1281 | + { | ||
1282 | + public string Key = ""; | ||
1283 | + public string Name = ""; | ||
1284 | + public string Description = ""; | ||
1285 | + public string ScriptText = ""; | ||
1286 | + public int CommandTimeout = 10000; | ||
1287 | + public string ArgumentParameters; | ||
1288 | + | ||
1289 | + public SQLScript() { } | ||
1290 | + public SQLScript(SQLScript sqls) { Name = sqls.Name; Description = sqls.Description; ScriptText= sqls.ScriptText; } | ||
1291 | + public SQLScript(XElement sqlscriptXml, int defaultcommandtimeout, int index) | ||
1292 | + { | ||
1293 | + ArgumentParameters = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Parameters), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Parameters.Values.DEFAULT); | ||
1294 | + | ||
1295 | + Key = $"S{index}"; | ||
1296 | + Name = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Name), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Name.Values.DEFAULT); | ||
1297 | + Description= GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Description), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Description.Values.DEFAULT); | ||
1298 | + Tools.ResolveArguments(ArgumentParameters, this.Name, out this.Name, interactive: false); | ||
1299 | + Tools.ResolveArguments(ArgumentParameters, this.Description, out this.Description, interactive: false); | ||
1300 | + ScriptText = GetValue(sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Values.DEFAULT); | ||
1301 | + CommandTimeout = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.ScriptCommandTimeout), sqlscriptXml, defaultcommandtimeout); | ||
1302 | + } | ||
1303 | + } | ||
1304 | + #endregion SQLScript class | ||
1190 | #region SQLData class | 1305 | #region SQLData class |
1191 | public class SQLData : XmlLinqBase | 1306 | public class SQLData : XmlLinqBase |
1192 | { | 1307 | { |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices; | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; | ||
32 | // You can specify all the values or you can default the Build and Revision Numbers | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
33 | // by using the '*' as shown below: | 33 | // by using the '*' as shown below: |
34 | // [assembly: AssemblyVersion("1.0.*")] | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.10.2.0")] | ||
36 | -[assembly: AssemblyFileVersion("1.10.2.0")] | 35 | +[assembly: AssemblyVersion("1.11.0.0")] |
36 | +[assembly: AssemblyFileVersion("1.11.0.0")] |