From 37bf94ab2d820576a60b67904ab112779a12a4ec Mon Sep 17 00:00:00 2001 From: Schwirg László Date: Wed, 30 Dec 2020 21:05:56 +0100 Subject: [PATCH] command mode kialakítása és beillesztése - egyenlőre csak - a ScheduledTaskManager modulba --- Vrh.Log4Pro.MaintenanceConsole/App.config | 6 +++--- Vrh.Log4Pro.MaintenanceConsole/Config.xml | 10 ++++++++++ Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs | 28 ++++++++++++++-------------- Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------- Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Vrh.Log4Pro.MaintenanceConsole/Manager - FileCleanerManager.cs | 10 +++++----- Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs | 6 +++--- Vrh.Log4Pro.MaintenanceConsole/Manager - ScheduledTaskManager.cs | 577 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs | 86 +++++++++++++++++++++++++++++++++++++++++++------------------------------------------- Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs | 4 ++-- Vrh.Log4Pro.MaintenanceConsole/Program.cs | 33 ++++++++++++++++++++++++++++----- Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj | 19 +++++++++++-------- Vrh.Log4Pro.MaintenanceConsole/packages.config | 4 ++-- 14 files changed, 1033 insertions(+), 151 deletions(-) create mode 100644 Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs create mode 100644 Vrh.Log4Pro.MaintenanceConsole/Manager - ScheduledTaskManager.cs diff --git a/Vrh.Log4Pro.MaintenanceConsole/App.config b/Vrh.Log4Pro.MaintenanceConsole/App.config index e8d9451..dedbba6 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/App.config +++ b/Vrh.Log4Pro.MaintenanceConsole/App.config @@ -1,9 +1,9 @@  - -
- + +
+ diff --git a/Vrh.Log4Pro.MaintenanceConsole/Config.xml b/Vrh.Log4Pro.MaintenanceConsole/Config.xml index 0707af0..123bb84 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Config.xml +++ b/Vrh.Log4Pro.MaintenanceConsole/Config.xml @@ -187,4 +187,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs index 5a4a8fb..074c2f3 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs @@ -16,6 +16,36 @@ namespace Vrh.Log4Pro.MaintenanceConsole #region ColorConsole public static class ColorConsole { + private static bool silentMode = false; + private static string[] readlineList = null; + + /// Üzenet és utána Billentyűzet lenyomásra vár + /// + /// + /// + public static ConsoleKeyInfo PressAnykeyToContinue(string text = null) + { + ColorConsole.WriteLine(text ?? "Press any key to continue...", ConsoleColor.Yellow); return ColorConsole.ReadKey(); + } + + + /// + /// Beállítja a command mode-ot, ami azt jelenti, hogy nem ír semmit a konzolra, + /// és a readline egy előre feltöltött bufferból olvassa az inputokat + /// + /// + public static void SetSilentMode(bool silentmode=true) { silentMode = silentmode; } + /// + /// Feltölti a command mode readline bufferét egy string tömbbel; + /// minden ColorConsole.ReadLine a tömb pillanatnyi első elemét adja vissza, amjd törli azt a tömbből + /// + /// + public static void SetReadLineList(string[] readlinelist) { readlineList = readlinelist; } + /// + /// A megadott stringet szóközökkel ritkított formában adja vissza + /// + /// + /// public static string WideString(string txt) { if (txt == null) { return null; }; @@ -25,18 +55,116 @@ namespace Vrh.Log4Pro.MaintenanceConsole return widetxt.Substring(0, widetxt.Length - 1); } + /// + /// true, ha van lenyomott billentyű, illetve command mode-ban mindig false + /// + public static bool KeyAvailable { get { if (silentMode) { return false; } else { return Console.KeyAvailable; } } } + + + /// + /// Beállítja a console ablak méretét + /// + /// + /// + public static void SetWindowSize(int w, int h) { if (!silentMode) { Console.SetWindowSize(w, h); } } + + /// + /// 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(); } + } + + /// + /// 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) + { + case ConsoleKey.Enter: + default: + return new ConsoleKeyInfo(keyChar: '\r', key: ConsoleKey.Enter, shift: shift, alt: alt, control: control); + } + } + + /// + /// Beolvas egy sort a consolról, vagy commandmode-ban a bufferból + /// + /// + /// + /// + /// + /// + /// public static string ReadLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "") { - Write(text, f, b,bracket,prefix); - return Console.ReadLine(); + if (silentMode) + { + if (readlineList == null || readlineList.Length == 0) { return null; } + else + { + var nextreadline = readlineList[0]; + readlineList = readlineList.Skip(1).ToArray(); + return nextreadline; + } + } + else + { + Write(text, f, b, bracket, prefix); + return Console.ReadLine(); + } + } + + /// + /// beállítja a cursor pozíciót + /// + /// + /// + public static void SetCursorPosition(int remembercursorleft, int remembercursortop) + { + if (silentMode) { return; } + Console.SetCursorPosition(remembercursorleft, remembercursortop); } + + public static int CursorLeft { get { return Console.CursorLeft; } } + public static int CursorTop { get { return Console.CursorTop; } } + + public static void Clear() { Console.Clear(); } + + /// + /// Kiír egy karaktersorozatot színesben a konzolra soremeléssel; + /// command mode-ban nem csinál semmit + /// + /// + /// + /// + /// + /// + /// public static void WriteLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null,string prefix="", string suffix = "") { + if (silentMode) { return; } Write(text, f, b, bracket,prefix,suffix); Console.WriteLine(); } + /// + /// Kiír egy karaktersorozatot színesben a konzolra soremelés nélkül; + /// command mode-ban nem csinál semmit + /// + /// + /// + /// + /// + /// + /// public static void Write(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "",string suffix="") { + if (silentMode) { return; } if (!string.IsNullOrEmpty(prefix)) { Write(prefix); } if (!string.IsNullOrEmpty(bracket) && bracket.Length==1) { bracket = bracket + bracket; } if (!string.IsNullOrEmpty(bracket)) { Console.Write($"{bracket[0]}"); } diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs index b0d56ed..942b44d 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs @@ -135,8 +135,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole Test(44,"this \"is a\" test", new[] { "this", "is a", "test" }); Test(45,"\"C:\\Program Files\"", new[] { "C:\\Program Files" }); Test(46,"\"He whispered to her \\\"I love you\\\".\"", new[] { "He whispered to her \"I love you\"." }); - Console.WriteLine("Press a key to continue...."); - Console.ReadKey(); + ColorConsole.WriteLine("Press a key to continue...."); + ColorConsole.ReadKey(); } static void Test(int id,string cmd, string[] r) { @@ -149,28 +149,28 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (r.Length != sr.Length) { - Console.WriteLine($"ERROR:{id}"); - Console.WriteLine($" cmdline : {cmd}"); - Console.WriteLine($" splitted: {scmd}"); - Console.WriteLine($" expected: {sexp}"); + ColorConsole.WriteLine($"ERROR:{id}"); + ColorConsole.WriteLine($" cmdline : {cmd}"); + ColorConsole.WriteLine($" splitted: {scmd}"); + ColorConsole.WriteLine($" expected: {sexp}"); return; } for (int i = 0; i < r.Length; i++) if (r[i] != sr[i]) { - Console.WriteLine($"ERROR:{id}"); - Console.WriteLine($" cmdline : {cmd}"); - Console.WriteLine($" splitted: {scmd}"); - Console.WriteLine($" expected: {sexp}"); + ColorConsole.WriteLine($"ERROR:{id}"); + ColorConsole.WriteLine($" cmdline : {cmd}"); + ColorConsole.WriteLine($" splitted: {scmd}"); + ColorConsole.WriteLine($" expected: {sexp}"); return; } } catch (Exception ex) { - Console.WriteLine($"EXCEP:{id}"); - Console.WriteLine($" cmdline : {cmd}"); - Console.WriteLine($" splitted: {scmd}"); - Console.WriteLine($" expected: {sexp}"); + ColorConsole.WriteLine($"EXCEP:{id}"); + ColorConsole.WriteLine($" cmdline : {cmd}"); + ColorConsole.WriteLine($" splitted: {scmd}"); + ColorConsole.WriteLine($" expected: {sexp}"); return; } } diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs index acca9e2..a4854be 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs @@ -11,11 +11,12 @@ using System.Management; using System.Diagnostics; using Vrh.XmlProcessing; +using VRH.Common; using System.Xml.Linq; namespace Vrh.Log4Pro.MaintenanceConsole { - public class Menu + public class Menu { public delegate Object MenuItemExecutorFunc(Object p, Object o); public delegate Object MenuItemDisplayerFunc(Object p, int i); @@ -25,30 +26,71 @@ namespace Vrh.Log4Pro.MaintenanceConsole private string Title { get { return ColorConsole.WideString(title); } set { title = value; } } private MenuItemDisplayerFunc MenuItemDisplayer; private SelectionMode selectionMode = Menu.SelectionMode.Multi; + private static bool commandModeAllMenus = false; + private bool commandMode = false; private int HeaderWidth = 9; private string SelectionPrompt = "Make Your selection!"; #endregion private fields #region public properties public List MenuItemList { get; private set; } = new List(); - List MenuKeyList { get { return MenuItemList.Where(x=> !x.Separator).Select(x => x.Key).ToList(); } } + List MenuKeyList { get { return MenuItemList.Where(x => !x.Separator).Select(x => x.Key).ToList(); } } #endregion public properties #region public tools + + /// + /// Incorrect selection console üzenet megjelenítése + /// + /// + public static void IncorrectSelection(string partxt = "") + { + if (GetCommandModeAllMenus()) { return; } + + ColorConsole.WriteLine(); + ColorConsole.WriteLine($"Incorrect selection! {partxt} Make a new selection!", ConsoleColor.Red); + Menu.PressAnykeyToContinue(); + } + + /// + /// Üzenet és utána Billentyűzet lenyomásra vár + /// + /// + /// + public static ConsoleKeyInfo PressAnykeyToContinue(string text = null) + { + if (GetCommandModeAllMenus()) { return ColorConsole.GetConsoleKey(ConsoleKey.Enter); } + + ColorConsole.WriteLine(text ?? "Press any key to continue...", ConsoleColor.Yellow); return ColorConsole.ReadKey(); + } + + + public static void SetCommandModeAllMenus() { commandModeAllMenus = true; } + public Menu SetMenuItemDisplayer(MenuItemDisplayerFunc displayer) { MenuItemDisplayer = displayer; return this; } public Menu SetSelectionMode(SelectionMode sm) { selectionMode = sm; return this; } - public Menu SetHeaderWidth(int hw) { HeaderWidth= hw; return this; } - public Menu AddMenuItem(Item mi) - { + public Menu SetCommandMode(bool commandmode = false) { commandMode = true; return this; } + public static bool GetCommandModeAllMenus() { return commandModeAllMenus; } + public bool GetCommandMode() { return commandMode || commandModeAllMenus; } + public Menu SetHeaderWidth(int hw) { HeaderWidth = hw; return this; } + public Menu AddMenuItem(Item mi) + { MenuItemList.Add(mi); if (string.IsNullOrWhiteSpace(mi.Key)) { mi.Key = $"#$KEY{MenuItemList.IndexOf(mi)}"; } return this; } public void ClearMenuItemList() { MenuItemList.Clear(); } + public void ExecuteCmd(string[] args) + { + var module = CommandLine.GetCommandLineArgument(args, "-MODULE"); + var sr = new Menu.Selection(module, args); + ExecuteSelection(sr); + } + public void ExecuteMenu() { try @@ -61,65 +103,69 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (sr.Result == Menu.SelectionResult.Exit) { return; } else if (sr.Result == Menu.SelectionResult.None) { continue; } else if (sr.Result == Menu.SelectionResult.Error) { continue; } - Execute(sr.SelectedKeyList); + ExecuteSelection(sr.SelectedKeyList); } } - catch (Exception ex) - { - ColorConsole.WriteLine(ex.Message,ConsoleColor.Red); + catch (Exception ex) + { + ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); if (ex.InnerException != null) { ColorConsole.WriteLine(ex.InnerException.Message, ConsoleColor.Red); } - ColorConsole.WriteLine("Press any key to continue..."); + Menu.PressAnykeyToContinue(); } } public void DisplayTitle() { - Console.Clear(); + if (GetCommandMode()) { return; } + + ColorConsole.Clear(); ColorConsole.WriteLine(Title, ConsoleColor.White); ColorConsole.WriteLine(new string('-', Title.Length)); } public void DisplayItems(int columns = 1, int columnlength = 0) { + if (GetCommandMode()) { return; } + int columncounter = 0; ColorConsole.WriteLine(); var i = 1; - Console.SetCursorPosition(0, Console.CursorTop); - foreach (var menuitem in MenuItemList) + ColorConsole.SetCursorPosition(0, ColorConsole.CursorTop); + foreach (var menuitem in MenuItemList) { if (menuitem.Separator && columns == 1) { - Console.SetCursorPosition(columnlength * columncounter + HeaderWidth, Console.CursorTop); + ColorConsole.SetCursorPosition(columnlength * columncounter + HeaderWidth, ColorConsole.CursorTop); var seplen = menuitem.SeparatorLength; - if (menuitem.SeparatorLength==0) + if (menuitem.SeparatorLength == 0) { - foreach (var mi in MenuItemList.Where(x=>!x.Separator)) { if (mi.Text.Length > seplen) { seplen = mi.Text.Length; } } + foreach (var mi in MenuItemList.Where(x => !x.Separator)) { if (mi.Text.Length > seplen) { seplen = mi.Text.Length; } } } ColorConsole.WriteLine(new string(menuitem.SeparatorChar, seplen)); continue; } ColorConsole.Write($"["); ColorConsole.Write($"{i}"); - if (!string.IsNullOrEmpty(menuitem.Key) && !menuitem.Key.StartsWith("#$KEY")) + if (!string.IsNullOrEmpty(menuitem.Key) && !menuitem.Key.StartsWith("#$KEY")) { ColorConsole.Write($":"); ColorConsole.Write(menuitem.Key, ConsoleColor.Yellow); } ColorConsole.Write($"]"); - Console.SetCursorPosition(columnlength * columncounter+HeaderWidth, Console.CursorTop); + ColorConsole.SetCursorPosition(columnlength * columncounter + HeaderWidth, ColorConsole.CursorTop); if (!string.IsNullOrEmpty(menuitem.Text)) { - ColorConsole.Write(menuitem.Text); + ColorConsole.Write(menuitem.Text); } if (columns == 1) { if (!string.IsNullOrEmpty(menuitem.Text)) { ColorConsole.WriteLine(); } - if (MenuItemDisplayer != null) + if (MenuItemDisplayer != null) { - for (var li = 0; li < 100; li++) - { - if (li>0) { ColorConsole.Write(new string(' ',HeaderWidth)); } + for (var li = 0; li < 100; li++) + { + if (li > 0) { ColorConsole.Write(new string(' ', HeaderWidth)); } var str = (string)MenuItemDisplayer(menuitem.Parameters, li); - if (string.IsNullOrEmpty(str)) { Console.SetCursorPosition(0, Console.CursorTop); } + if (string.IsNullOrEmpty(str)) { ColorConsole.SetCursorPosition(0, ColorConsole.CursorTop); } if (str == null) { break; } } } @@ -130,49 +176,63 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (columncounter == columns) { ColorConsole.WriteLine(); columncounter = 0; } else { - Console.SetCursorPosition(columnlength * columncounter - 2, Console.CursorTop); + ColorConsole.SetCursorPosition(columnlength * columncounter - 2, ColorConsole.CursorTop); ColorConsole.Write(" "); } } i++; } if (columns != 1) { ColorConsole.WriteLine(); } - if (selectionMode==SelectionMode.Multi) + if (selectionMode == SelectionMode.Multi) { - ColorConsole.Write("*", ConsoleColor.Red,bracket:"()");ColorConsole.WriteLine(" All"); + ColorConsole.Write("*", ConsoleColor.Red, bracket: "()"); ColorConsole.WriteLine(" All"); } - ColorConsole.Write("EX", ConsoleColor.Red,bracket:"()");ColorConsole.WriteLine(" Exit"); + ColorConsole.Write("EX", ConsoleColor.Red, bracket: "()"); ColorConsole.WriteLine(" Exit"); } public class Selection { + public Selection() { } + public Selection(string selectedkey,object parameter) + { + Result = SelectionResult.Ok; + SelectedKeyList = new List() { { selectedkey } }; + SelectedParameterList = new List() { { parameter } }; + } public List SelectedKeyList = null; public SelectionResult Result; public List SelectedParameterList; } public enum SelectionResult { Exit, None, Error, Ok, } public enum SelectionMode { Single, Multi, } - public Selection Select() + public Selection Select(string forcedselectionkeylist=null) { - List selectionKeyList=null; - List selectionParList = null; - var result = new Selection(); + List selectionKeyList; + List selectionParList; string selectionliststr; - ColorConsole.Write(SelectionPrompt,ConsoleColor.Yellow); - ColorConsole.Write(" --> ", ConsoleColor.White); - var remembercursorleft = Console.CursorLeft; - var remembercursortop = Console.CursorTop; - if (selectionMode == SelectionMode.Multi) + var result = new Selection(); + if (GetCommandMode()) { - ColorConsole.WriteLine(); - ColorConsole.WriteLine("Multiple selections are separated with comma(,), enter asterisk(*) to select all)!"); + selectionliststr = forcedselectionkeylist??"EX"; } - var remembercursorleft2 = Console.CursorLeft; - var remembercursortop2 = Console.CursorTop; - Console.SetCursorPosition(remembercursorleft, remembercursortop); - selectionliststr = Console.ReadLine().ToUpper(); - if (selectionMode == SelectionMode.Multi) + else { - Console.SetCursorPosition(remembercursorleft2, remembercursortop2); + ColorConsole.Write(SelectionPrompt, ConsoleColor.Yellow); + ColorConsole.Write(" --> ", ConsoleColor.White); + var remembercursorleft = ColorConsole.CursorLeft; + var remembercursortop = ColorConsole.CursorTop; + if (selectionMode == SelectionMode.Multi) + { + ColorConsole.WriteLine(); + ColorConsole.WriteLine("Multiple selections are separated with comma(,), enter asterisk(*) to select all!"); + } + var remembercursorleft2 = ColorConsole.CursorLeft; + var remembercursortop2 = ColorConsole.CursorTop; + ColorConsole.SetCursorPosition(remembercursorleft, remembercursortop); + selectionliststr = ColorConsole.ReadLine().ToUpper(); + if (selectionMode == SelectionMode.Multi) + { + ColorConsole.SetCursorPosition(remembercursorleft2, remembercursortop2); + } } if (selectionliststr == "EX") { @@ -186,37 +246,37 @@ namespace Vrh.Log4Pro.MaintenanceConsole result.SelectedKeyList = null; return result; } - else if (selectionMode == SelectionMode.Multi && selectionliststr == "*") + else if (selectionMode == SelectionMode.Multi && selectionliststr == "*") { selectionKeyList = new List(); selectionParList = new List(); var i = 1; - foreach (var mi in MenuItemList) - { + foreach (var mi in MenuItemList) + { selectionKeyList.Add(mi.Key); selectionParList.Add(mi.Parameters); } result.Result = SelectionResult.Ok; result.SelectedKeyList = selectionKeyList; - result.SelectedParameterList= selectionParList; - return result; + result.SelectedParameterList = selectionParList; + return result; } selectionKeyList = new List(); selectionParList = new List(); foreach (var selection in selectionliststr.Split(',').ToList()) { string _selection = selection; - object _parameters=null; + object _parameters = null; if (!MenuKeyList.Contains(_selection)) { if (!int.TryParse(_selection, out int indexselection) || indexselection < 1 || indexselection > MenuItemList.Count()) { - IncorrectSelection($"Selected item {_selection} is not valid!"); + Menu.IncorrectSelection($"Selected item {_selection} is not valid!"); result.Result = SelectionResult.Error; result.SelectedKeyList = null; return result; } - _selection = GetItemKey(indexselection-1); + _selection = GetItemKey(indexselection - 1); _parameters = GetItem(indexselection - 1).Parameters; } selectionKeyList.Add(_selection); @@ -227,15 +287,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole result.SelectedParameterList = selectionParList; return result; } - public static void IncorrectSelection(string partxt="") - { - ColorConsole.WriteLine(); - ColorConsole.WriteLine($"Incorrect selection! {partxt} Make a new selection!",ConsoleColor.Red); - Console.WriteLine("Press a key to continue..."); - Console.ReadKey(); - } - - public void Execute(List selectedkeylist) + public void ExecuteSelection(List selectedkeylist) { object o = null; foreach (var mi in MenuItemList) @@ -245,7 +297,20 @@ namespace Vrh.Log4Pro.MaintenanceConsole o = mi.Executor(mi.Parameters, o); } } - ColorConsole.WriteLine("Press any key to continue...", ConsoleColor.Yellow); Console.ReadKey(); + Menu.PressAnykeyToContinue(); + } + + public void ExecuteSelection(Menu.Selection sr) + { + object o = null; + foreach (var mi in MenuItemList) + { + if (sr.SelectedKeyList.Contains(mi.Key)) + { + o = mi.Executor(sr.SelectedParameterList.ElementAt(sr.SelectedKeyList.IndexOf(mi.Key)), o); + } + } + Menu.PressAnykeyToContinue(); } public MenuItemExecutorFunc GetExecutor(string key) { @@ -278,7 +343,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole { return MenuKeyList.ElementAt(ix); } - public void SetParameters(Menu.Selection r, object p=null) + public void SetExecutorParameters(Menu.Selection r, object p=null) { foreach (var mi in this.MenuItemList) { diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs new file mode 100644 index 0000000..44dc1bc --- /dev/null +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs @@ -0,0 +1,76 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Security.Principal; +using System.Text; +using System.Threading.Tasks; +using System.Threading; + +using Microsoft.Web.Administration; +using System.Management; +using System.Diagnostics; + +using Vrh.XmlProcessing; +using System.Xml.Linq; + +namespace Vrh.Log4Pro.MaintenanceConsole +{ + public static class Tools + { + public static bool IsElevated + { + get + { + return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator); + } + } + public static string ExecuteAndGetStdIo(string exepath, string args) + { + StringBuilder outputBuilder = new StringBuilder(); + StringBuilder erroroutputBuilder = new StringBuilder(); + ProcessStartInfo startInfo = new ProcessStartInfo() { }; + using (Process exeProcess = new Process()) + { + startInfo.CreateNoWindow = true; + startInfo.WindowStyle = ProcessWindowStyle.Hidden; + startInfo.RedirectStandardOutput = true; + startInfo.RedirectStandardError= true; + startInfo.RedirectStandardInput = true; + startInfo.UseShellExecute = false; + startInfo.FileName = exepath; + startInfo.Verb= "runas"; + startInfo.Arguments = args; + + exeProcess.StartInfo = startInfo; + // enable raising events because Process does not raise events by default + exeProcess.EnableRaisingEvents = true; + exeProcess.OutputDataReceived += new DataReceivedEventHandler + ( + delegate (object sender, DataReceivedEventArgs e) + { + // append the new data to the data already read-in + outputBuilder.Append(e.Data + "\r\n"); + } + ); + exeProcess.ErrorDataReceived += new DataReceivedEventHandler + ( + delegate (object sender, DataReceivedEventArgs e) + { + // append the new data to the data already read-in + erroroutputBuilder.Append(e.Data + "\r\n"); + } + ); + // start the process + // then begin asynchronously reading the output + // then wait for the process to exit + // then cancel asynchronously reading the output + exeProcess.Start(); + exeProcess.BeginOutputReadLine(); + exeProcess.WaitForExit(); + exeProcess.CancelOutputRead(); + return outputBuilder.ToString(); + } + } + } +} diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - FileCleanerManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - FileCleanerManager.cs index 02424d0..d0fa20a 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - FileCleanerManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - FileCleanerManager.cs @@ -42,8 +42,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (sr.Result == Menu.SelectionResult.Exit) { break; } else if (sr.Result == Menu.SelectionResult.None) { continue; } else if (sr.Result == Menu.SelectionResult.Error) { continue; } - menufunctions.SetParameters(sr,config); - menufunctions.Execute(sr.SelectedKeyList); + menufunctions.SetExecutorParameters(sr,config); + menufunctions.ExecuteSelection(sr.SelectedKeyList); } return null; } @@ -309,7 +309,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole #endregion GetDefinitionList } #endregion FileCleanerManagerCoreXmlProcessor class - #region WindowsService class + + #region FolderToClean class public class FolderToClean : XmlLinqBase { #region fields @@ -499,6 +500,5 @@ namespace Vrh.Log4Pro.MaintenanceConsole } #endregion XmlStructure } - #endregion WindowsService class - + #endregion FolderToClean class } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs index d1eab7d..ddd96c0 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs @@ -43,8 +43,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (sr.Result == Menu.SelectionResult.Exit) { break; } else if (sr.Result == Menu.SelectionResult.None) { continue; } else if (sr.Result == Menu.SelectionResult.Error) { continue; } - menufunctions.SetParameters(sr,config); - menufunctions.Execute(sr.SelectedKeyList); + menufunctions.SetExecutorParameters(sr,config); + menufunctions.ExecuteSelection(sr.SelectedKeyList); } return null; } @@ -80,7 +80,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole ColorConsole.WriteLine(regexmatch.Groups[groupname].Value, ConsoleColor.Yellow); } } - ColorConsole.ReadLine($"Press any key to continue..."); + ColorConsole.PressAnykeyToContinue(); } return o; } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - ScheduledTaskManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - ScheduledTaskManager.cs new file mode 100644 index 0000000..ae874c7 --- /dev/null +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - ScheduledTaskManager.cs @@ -0,0 +1,577 @@ +using System; +using System.IO; +using System.Configuration.Install; +using System.Collections.Generic; +using System.Linq; +using System.ServiceProcess; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +using Microsoft.Web.Administration; +using System.Management; +using System.Diagnostics; + +using Vrh.XmlProcessing; +using VRH.Common; +using System.Xml.Linq; +using System.Text.RegularExpressions; + +namespace Vrh.Log4Pro.MaintenanceConsole +{ + #region ScheduledTaskManager class + public static class ScheduledTaskmanagerManager + { + private const string XMLCONNECTIONSTRING = "file=Config.Xml;element=ScheduledTasks;"; + + #region Execute + public static object Execute(object o1 = null, object o2 = null) + { + var args = o1 as string[]; + var module = CommandLine.GetCommandLineArgument(args, "-MODULE"); + var functionkey = CommandLine.GetCommandLineArgument(args, "-FUNCTION"); + + string xmlcs = XMLCONNECTIONSTRING; + var config = new ScheduledTaskManagerCoreXmlProcessor(xmlcs, "", "hu-HU"); + var menufunctions = new Menu("Manage Scheduled tasks", "Select the management function!") + .AddMenuItem(new Menu.Item("INS", "Install scheduled task", Install)) + .AddMenuItem(new Menu.Item("UIN", "Uninstall scheduled task", Uninstall)) + .AddMenuItem(new Menu.Item("RUN", "Start scheduled task", Run)) + .AddMenuItem(new Menu.Item("END", "Stop scheduled task", End)) + .AddMenuItem(new Menu.Item("ENA", "Enable scheduled task", Enable)) + .AddMenuItem(new Menu.Item("DIS", "Disable scheduled task", Disable)) + .AddMenuItem(new Menu.Item("CHP", "Change scheduled task priority", ChangePriority)) + .SetSelectionMode(Menu.SelectionMode.Single); + + while (true) + { + Menu.Selection sr; + + menufunctions.DisplayTitle(); + DisplayTasks(config); + menufunctions.DisplayItems(); + sr = menufunctions.Select(functionkey); + if (sr.Result == Menu.SelectionResult.Exit) { break; } + else if (sr.Result == Menu.SelectionResult.None) { continue; } + else if (sr.Result == Menu.SelectionResult.Error) { continue; } + menufunctions.SetExecutorParameters(sr, new ScheduledTaskExecutorParameter (config,args)); + menufunctions.ExecuteSelection(sr.SelectedKeyList); + if (menufunctions.GetCommandMode()) { break; } + } + return o2; + } + #endregion Execute + #region ScheduledTaskFunctionExecutorParameter + public class ScheduledTaskExecutorParameter + { + public ScheduledTaskExecutorParameter(ScheduledTaskManagerCoreXmlProcessor cfg, string[] args) { Config = cfg;Args = args; } + public ScheduledTaskManagerCoreXmlProcessor Config; + public string[] Args; + } + #endregion ScheduledTaskFunctionExecutorParameter + #region First level Executors with UI + private static object ChangePriority(object parameter, object o) + { + var config = (parameter as ScheduledTaskExecutorParameter).Config; + var args = (parameter as ScheduledTaskExecutorParameter).Args; + + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, "-TASKS"); + + var menufolders = DisplayTasks(config, $"Select the scheduled task(s) to manage with function '{nameof(ChangePriority)}'!"); + + Menu.Selection sr = menufolders.Select(selectedtaskindexes); + if (sr.Result == Menu.SelectionResult.Exit) { return o; } + else if (sr.Result == Menu.SelectionResult.None) { return o; } + else if (sr.Result == Menu.SelectionResult.Error) { return o; } + else if (sr.Result == Menu.SelectionResult.Ok) { } + else { } + foreach (var p in sr.SelectedParameterList) + { + ScheduledTask st = p as ScheduledTask; + try + { + ScheduledTaskManagerCore.SetPriority(st.Xml_Name,st.Xml_Priority); + ColorConsole.WriteLine($"Priority changed for scheduled task. Name:{st.Xml_Name}", ConsoleColor.Green); + } + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } + } + return o; + } + private static object Disable(object parameter, object o) + { + var config = (parameter as ScheduledTaskExecutorParameter).Config; + var args = (parameter as ScheduledTaskExecutorParameter).Args; + + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, "-TASKS"); + + var menufolders = DisplayTasks(config, $"Select the scheduled task(s) to manage with function '{nameof(Disable)}'!"); + + Menu.Selection sr = menufolders.Select(selectedtaskindexes); + if (sr.Result == Menu.SelectionResult.Exit) { return o; } + else if (sr.Result == Menu.SelectionResult.None) { return o; } + else if (sr.Result == Menu.SelectionResult.Error) { return o; } + else if (sr.Result == Menu.SelectionResult.Ok) { } + else { } + foreach (var p in sr.SelectedParameterList) + { + ScheduledTask st = p as ScheduledTask; + try + { + ScheduledTaskManagerCore.DisableTask(st.Xml_Name); + ColorConsole.WriteLine($"Scheduled task disabled. Name:{st.Xml_Name}", ConsoleColor.Green); + } + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } + } + return o; + } + private static object Enable(object parameter, object o) + { + var config = (parameter as ScheduledTaskExecutorParameter).Config; + var args = (parameter as ScheduledTaskExecutorParameter).Args; + + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, "-TASKS"); + + var menufolders = DisplayTasks(config, $"Select the scheduled task(s) to manage with function '{nameof(Enable)}'!"); + + Menu.Selection sr = menufolders.Select(selectedtaskindexes); + if (sr.Result == Menu.SelectionResult.Exit) { return o; } + else if (sr.Result == Menu.SelectionResult.None) { return o; } + else if (sr.Result == Menu.SelectionResult.Error) { return o; } + else if (sr.Result == Menu.SelectionResult.Ok) { } + else { } + foreach (var p in sr.SelectedParameterList) + { + ScheduledTask st = p as ScheduledTask; + try + { + ScheduledTaskManagerCore.EnableTask(st.Xml_Name); + ColorConsole.WriteLine($"Scheduled task enabled. Name:{st.Xml_Name}", ConsoleColor.Green); + } + catch (Exception ex){ ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } + } + return o; + } + private static object End(object parameter, object o) + { + var config = (parameter as ScheduledTaskExecutorParameter).Config; + var args = (parameter as ScheduledTaskExecutorParameter).Args; + + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, "-TASKS"); + + var menufolders = DisplayTasks(config, $"Select the scheduled task(s) to manage with function '{nameof(End)}'!"); + + Menu.Selection sr = menufolders.Select(selectedtaskindexes); + if (sr.Result == Menu.SelectionResult.Exit) { return o; } + else if (sr.Result == Menu.SelectionResult.None) { return o; } + else if (sr.Result == Menu.SelectionResult.Error) { return o; } + else if (sr.Result == Menu.SelectionResult.Ok) { } + else { } + foreach (var p in sr.SelectedParameterList) + { + ScheduledTask st = p as ScheduledTask; + try + { + ScheduledTaskManagerCore.EndTask(st.Xml_Name); + ColorConsole.WriteLine($"Scheduled task stopped. Name:{st.Xml_Name}", ConsoleColor.Green); + } + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } + } + return o; + } + private static object Run(object parameter, object o) + { + var config = (parameter as ScheduledTaskExecutorParameter).Config; + var args = (parameter as ScheduledTaskExecutorParameter).Args; + + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, "-TASKS"); + + var menufolders = DisplayTasks(config, $"Select the scheduled task(s) to manage with function '{nameof(Run)}'!"); + + Menu.Selection sr = menufolders.Select(selectedtaskindexes); + if (sr.Result == Menu.SelectionResult.Exit) { return o; } + else if (sr.Result == Menu.SelectionResult.None) { return o; } + else if (sr.Result == Menu.SelectionResult.Error) { return o; } + else if (sr.Result == Menu.SelectionResult.Ok) { } + else { } + foreach (var p in sr.SelectedParameterList) + { + ScheduledTask st = p as ScheduledTask; + try + { + ScheduledTaskManagerCore.RunTask(st.Xml_Name); + ColorConsole.WriteLine($"Scheduled task started. Name:{st.Xml_Name}", ConsoleColor.Green); + } + catch (Exception ex) + { + ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); + } + } + return o; + } + private static object Uninstall(object parameter, object o) + { + var config = (parameter as ScheduledTaskExecutorParameter).Config; + var args = (parameter as ScheduledTaskExecutorParameter).Args; + + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, "-TASKS"); + + var menufolders = DisplayTasks(config, $"Select the scheduled task(s) to manage with function '{nameof(Uninstall)}'!"); + + Menu.Selection sr = menufolders.Select(selectedtaskindexes); + if (sr.Result == Menu.SelectionResult.Exit) { return o; } + else if (sr.Result == Menu.SelectionResult.None) { return o; } + else if (sr.Result == Menu.SelectionResult.Error) { return o; } + else if (sr.Result == Menu.SelectionResult.Ok) { } + else { } + foreach (var p in sr.SelectedParameterList) + { + ScheduledTask st = p as ScheduledTask; + try + { + ScheduledTaskManagerCore.EndTask(st.Xml_Name); + ScheduledTaskManagerCore.DeleteTask(st.Xml_Name); + ColorConsole.WriteLine($"Scheduled task uninstalled. Name:{st.Xml_Name}", ConsoleColor.Green); + } + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } + } + return o; + } + private static object Install(object parameter, object o) + { + var config = (parameter as ScheduledTaskExecutorParameter).Config; + var args = (parameter as ScheduledTaskExecutorParameter).Args; + + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, "-TASKS"); + + var menufolders = DisplayTasks(config, $"Select the scheduled task(s) to manage with function '{nameof(Install)}'!"); + + Menu.Selection sr = menufolders.Select(selectedtaskindexes); + if (sr.Result == Menu.SelectionResult.Exit) { return o; } + else if (sr.Result == Menu.SelectionResult.None) { return o; } + else if (sr.Result == Menu.SelectionResult.Error) { return o; } + else if (sr.Result == Menu.SelectionResult.Ok) { } + else { } + foreach (var p in sr.SelectedParameterList) + { + ScheduledTask st = p as ScheduledTask; + try + { + ScheduledTaskManagerCore.EndTask(st.Xml_Name); + ScheduledTaskManagerCore.DeleteTask(st.Xml_Name); + ScheduledTaskManagerCore.CreateTask(st); + ColorConsole.WriteLine($"Scheduled task installed. Name:{st.Xml_Name}", ConsoleColor.Green); + } + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } + } + return o; + } + #endregion First level Executors with UI + + #region private methods + #region private DisplayTasks + private static Menu DisplayTasks(ScheduledTaskManagerCoreXmlProcessor config,string prompt = null) + { + List schtskdefList = config.GetDefinitionList(); + var menufct = new Menu("Scheduled tasks",prompt) + .SetMenuItemDisplayer(DisplayTaskInfo) + .SetSelectionMode(Menu.SelectionMode.Multi) + .SetHeaderWidth(4); + menufct.ClearMenuItemList(); + foreach (var schtskdef in schtskdefList) + { + var st = CollectTaskInfo(schtskdef); + menufct.AddMenuItem(new Menu.Item(null, null, null, st)); + } + menufct.DisplayItems(1); + return menufct; + } + #endregion private DisplayTasks + #region private method: DisplayTaskInfo + private static object DisplayTaskInfo(object obj, int lineix) + { + ScheduledTask st = obj as ScheduledTask; + if (lineix == 0) + { + ColorConsole.Write($"{st.Xml_Name}", ConsoleColor.Black, ConsoleColor.White); + var statuscolor = st.Status == "Uninstalled" ? ConsoleColor.Red : ConsoleColor.Green; + ColorConsole.Write(st.Status, statuscolor, bracket: "[]", prefix: " ", suffix: ". "); + if (st.Status != "Uninstalled" && st.Status != "Disabled") + { + ColorConsole.Write(st.PriorityText(st.Priority), statuscolor, prefix: "Effective priority ", suffix: ". "); + ColorConsole.Write($"{st.Xml_Commandname}", ConsoleColor.Yellow, prefix: "Command: "); + } + ColorConsole.WriteLine(); + return " "; + } + else if (lineix == 1) + { + ColorConsole.Write($"{st.Xml_Schedule}",ConsoleColor.Yellow,prefix:"Scheduled ",suffix:" "); + ColorConsole.Write($"{st.Xml_StartTime}", ConsoleColor.Yellow, prefix: "at ", suffix: ", "); + ColorConsole.Write(st.PriorityText(st.Xml_Priority), ConsoleColor.Yellow, prefix: "with priority ", suffix: ". "); + ColorConsole.Write($"{st.Xml_Enable}", ConsoleColor.Yellow, prefix: "After install ", suffix: " "); + ColorConsole.Write($"{st.Xml_Run}", ConsoleColor.Yellow, prefix: "and run ", suffix: ". "); + ColorConsole.WriteLine(" "); + return " "; + } + return null; + } + #endregion private method: DisplayTaskInfo + #region private CollectTaskInfo + private static ScheduledTask CollectTaskInfo(ScheduledTask schtsk) + { + string status = Tools.ExecuteAndGetStdIo("schtasks.exe", $"/Query /FO TABLE /TN {schtsk.Xml_Name}"); + + try + { + var statuslines = status.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); + var statussplitted = statuslines[3] + .Split(new string[] { " ", "+" }, StringSplitOptions.RemoveEmptyEntries); + if (statussplitted[1]=="N/A") + { + schtsk.NextRun = ""; + schtsk.Priority = -1; + schtsk.Status = statussplitted[2]; + } + else + { + var nextrunTS = statussplitted[1] + " " + statussplitted[2]; + var statusinfo = statussplitted[3]; + if (statusinfo == "AM" || statusinfo == "PM") + { + statusinfo = statussplitted[4]; + nextrunTS += statusinfo; + } + schtsk.Status = statusinfo; + schtsk.NextRun += nextrunTS; + schtsk.Priority = ScheduledTaskManagerCore.GetPriority(schtsk.Xml_Name); + } + } + catch + { + schtsk.Status = "Uninstalled"; + schtsk.NextRun = ""; + schtsk.Priority = -1; + } + return schtsk; + } + #endregion private CollectTaskInfo + #endregion private methods + } + #endregion ScheduledTaskManager class + + #region class ScheduledTaskManagerCore + public static class ScheduledTaskManagerCore + { + public static int GetPriority(string taskname) + { + try + { + return int.Parse(ScheduledTaskManagerCore.GetXml(taskname).Element(XName.Get("Settings")).Element(XName.Get("Priority")).Value); + } + catch + { + return ScheduledTask.XmlStructure.ScheduledTask.Attributes.Priority.Values.DEFAULT; + } + } + public static void SetPriority(string taskname,int priority) + { + var schtskXml = ScheduledTaskManagerCore.GetXml(taskname); + schtskXml.Element(XName.Get("Settings")).Element(XName.Get("Priority")).Value= priority.ToString(); + ScheduledTaskManagerCore.SetXml(taskname, schtskXml); + } + public static XElement GetXml(string taskname) { return XElement.Parse(Tools.ExecuteAndGetStdIo("schtasks.exe", $"/Query /XML /TN {taskname}")); } + public static void SetXml(string taskname,XElement schtskXml) + { + EndTask(taskname); + DeleteTask(taskname); + CreateTask(taskname, schtskXml); + } + public static void EndTask(string taskname) { Tools.ExecuteAndGetStdIo("schtasks.exe", $"/End /TN {taskname}"); } + public static void RunTask(string taskname) { Tools.ExecuteAndGetStdIo("schtasks.exe", $"/Run /TN {taskname}"); } + public static void EnableTask(string taskname) + { + Tools.ExecuteAndGetStdIo("schtasks.exe", $"/Change /ENABLE /TN {taskname}"); + } + public static void DisableTask(string taskname) + { + EndTask(taskname); + Tools.ExecuteAndGetStdIo("schtasks.exe", $"/Change /DISABLE /TN {taskname}"); + } + public static void DeleteTask(string taskname) { Tools.ExecuteAndGetStdIo("schtasks.exe", $"/Delete /TN {taskname} /F"); } + public static void CreateTask(string taskname, XElement schtskXml) + { + var tmpfilename = $"TMP_{taskname}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xml"; + if (File.Exists(tmpfilename)) { File.Delete(tmpfilename); } + schtskXml.Save(tmpfilename); + Tools.ExecuteAndGetStdIo("schtasks.exe", $"/Create /XML {tmpfilename} /TN {taskname}"); + if (File.Exists(tmpfilename)) { File.Delete(tmpfilename); } + } + public static void CreateTask(ScheduledTask st) + { + string taskname = st.Xml_Name; + string tasktorunpars = st.Xml_Commandname; + + string schedulepars = ""; + if (st.Xml_Schedule==nameof(ScheduledTask.XmlStructure.ScheduledTask.Attributes.Schedule.Values.MONTHLY)) { schedulepars += "/SC MONTHLY /D 1"; } + else if (st.Xml_Schedule == nameof(ScheduledTask.XmlStructure.ScheduledTask.Attributes.Schedule.Values.WEEKLY)) { schedulepars += "/SC WEEKLY /D MON"; } + else if (st.Xml_Schedule == nameof(ScheduledTask.XmlStructure.ScheduledTask.Attributes.Schedule.Values.DAILY)) { schedulepars += "/SC DAILY"; } + else if (st.Xml_Schedule == nameof(ScheduledTask.XmlStructure.ScheduledTask.Attributes.Schedule.Values.HOURLY)) { schedulepars += "/SC DAILY /RI 60 /DU 24:00 /K"; } + else if (st.Xml_Schedule == nameof(ScheduledTask.XmlStructure.ScheduledTask.Attributes.Schedule.Values.CONTINOUS)) { schedulepars += "/SC DAILY /RI 5 /DU 24:00 /K"; } + var sst = st.Xml_StartTime.ToString("HH:mm:ss"); + string starttimepars = $"/ST {sst}"; + string passwordpars = "/NP"; + string forcecreatepars = "/F"; + string prioritypars = "/RL HIGHEST"; + + var args = $"/Create /TR {tasktorunpars} {schedulepars} {starttimepars} {passwordpars} {forcecreatepars} {prioritypars} /TN {taskname}"; + var result = Tools.ExecuteAndGetStdIo("schtasks.exe", args); + + if (st.Xml_Enable) { EnableTask(taskname); } else { DisableTask(taskname); } + if (st.Xml_Run) { RunTask(taskname); } else { EndTask(taskname); } + } + } + #endregion class ScheduledTaskManagerCore + + #region ScheduledTaskManagerCoreXmlProcessor class + public class ScheduledTaskManagerCoreXmlProcessor : XmlParser + { + private List _scheduledtasklist; + #region constructor + public ScheduledTaskManagerCoreXmlProcessor(string xmlcs, string basefolder, string lcid) : base(xmlcs, basefolder, lcid, null) + { + _scheduledtasklist = new List(); + var schtskxmllist = GetAllXElements(nameof(ScheduledTask.XmlStructure.ScheduledTask)); + if (schtskxmllist != null && schtskxmllist.Any()) + { + foreach (var schtskxml in schtskxmllist) { var st = new ScheduledTask(schtskxml); if (st.Valid) { _scheduledtasklist.Add(st); } } + } + } + #endregion constructor + #region GetDefinitionList + public List GetDefinitionList() { return _scheduledtasklist; } + #endregion GetDefinitionList + } + #endregion ScheduledTaskManagerCoreXmlProcessor class + + #region ScheduledTask class + public class ScheduledTask : XmlLinqBase + { + #region fields + public bool Valid = true; + public string Xml_Name; + public int Xml_Priority; + public string Xml_Schedule; + public DateTime Xml_StartTime; + public bool Xml_Enable = XmlStructure.ScheduledTask.Attributes.Enable.Values.DEFAULT; + public bool Xml_Run=XmlStructure.ScheduledTask.Attributes.Run.Values.DEFAULT; + public string Xml_Commandname; + + public string Status; + public string NextRun; + public int Priority; + #endregion fields + + #region basic constructor + public ScheduledTask() { } + #endregion basic constructor + #region xml constructor + public string PriorityText(int pri) + { + return + (pri == 0 ? "Realtime" + : pri == 1 ? "High" + : pri == 2 ? "High" + : pri == 3 ? "Normal" + : pri == 4 ? "Normal" + : pri == 5 ? "Normal" + : pri == 6 ? "Normal" + : pri == 7 ? "Low" + : pri == 8 ? "Low" + : pri == 9 ? "Idle" + : pri == 10 ? "Idle" + : "Idle")+$"({pri})"; + } + public ScheduledTask(XElement scheduledtaskxml) + { + Valid = true; + string ATTRIBUTEMANDATORY = nameof(XmlStructure.ScheduledTask) + " attribute is mandatory! Name: {0}"; + Xml_Name = scheduledtaskxml.Attribute(XName.Get(nameof(XmlStructure.ScheduledTask.Attributes.Name)))?.Value; + if (string.IsNullOrWhiteSpace(Xml_Name)) { throw new ApplicationException(string.Format(ATTRIBUTEMANDATORY, nameof(XmlStructure.ScheduledTask.Attributes.Name))); } + Xml_Priority = GetValue(nameof(XmlStructure.ScheduledTask.Attributes.Priority), scheduledtaskxml, XmlStructure.ScheduledTask.Attributes.Priority.Values.DEFAULT); + Xml_Schedule = GetValue(nameof(XmlStructure.ScheduledTask.Attributes.Schedule), scheduledtaskxml, XmlStructure.ScheduledTask.Attributes.Schedule.Values.DEFAULT); + Xml_StartTime = DateTime.Parse(GetValue(nameof(XmlStructure.ScheduledTask.Attributes.StartTime), scheduledtaskxml, XmlStructure.ScheduledTask.Attributes.StartTime.Values.DEFAULT)); + Xml_Enable = GetValue(nameof(XmlStructure.ScheduledTask.Attributes.Enable), scheduledtaskxml, XmlStructure.ScheduledTask.Attributes.Enable.Values.DEFAULT); + Xml_Run = GetValue(nameof(XmlStructure.ScheduledTask.Attributes.Run), scheduledtaskxml, XmlStructure.ScheduledTask.Attributes.Run.Values.DEFAULT); + Xml_Commandname = GetValue(nameof(XmlStructure.ScheduledTask.Attributes.Commandname), scheduledtaskxml, ""); + //var conditionxmlList = GetAllXElements(foldertocleanxml, nameof(XmlStructure.FolderToClean.Conditions), nameof(XmlStructure.FolderToClean.Conditions.Condition)); + } + #endregion xml constructor + #region cloner constructor + public ScheduledTask(ScheduledTask ftc) + { + Valid = ftc.Valid; + Xml_Name = ftc.Xml_Name; + Xml_Priority = ftc.Xml_Priority; + Xml_Schedule = ftc.Xml_Schedule; + Xml_StartTime = ftc.Xml_StartTime; + Xml_Enable = ftc.Xml_Enable; + Xml_Run = ftc.Xml_Run; + Xml_Commandname = ftc.Xml_Commandname; + } + #endregion cloner constructor + #region XmlStructure + public static class XmlStructure + { + public static class ScheduledTask + { + public static class Attributes + { + public static class Name { } + public static class StartTime + { + public static class Values + { + public const string DEFAULT = "04:00"; + } + } + public static class Priority + { + public static class Values + { + public const int DEFAULT = 7; + } + } + public static class Schedule + { + public static class Values + { + public static class WEEKLY { } + public static class MONTHLY { } + public static class DAILY { } + public static class HOURLY { } + public static class CONTINOUS { } + public const string DEFAULT = nameof(DAILY); + } + } + public static class Enable + { + public static class Values + { + public const bool DEFAULT = true; + } + } + public static class Run + { + public static class Values + { + public const bool DEFAULT = false; + } + } + public static class Commandname { } + } + } + } + #endregion XmlStructure + } + #endregion ScheduledTask class +} diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs index 85105ca..b5cff1b 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs @@ -76,7 +76,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole else if (sr.Result == Menu.SelectionResult.Error) { continue; } else if (sr.Result == Menu.SelectionResult.Ok) { } else { } - menuapplications.Execute(sr.SelectedKeyList); + menuapplications.ExecuteSelection(sr.SelectedKeyList); } return null; } @@ -149,14 +149,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole WebApplication d = dobj as WebApplication; using (ServerManager sm = new ServerManager()) { - try { WebApplicationManagerCore.GetPool(sm, d.Xml_PoolName)?.Stop(); } catch { Console.WriteLine($"Pool {d.Xml_PoolName} already stopped."); } - try { WebApplicationManagerCore.GetSite(sm, d.Xml_SiteName)?.Stop(); } catch { Console.WriteLine($"Site {d.Xml_SiteName} already stopped."); } + try { WebApplicationManagerCore.GetPool(sm, d.Xml_PoolName)?.Stop(); } catch { ColorConsole.WriteLine($"Pool {d.Xml_PoolName} already stopped."); } + try { WebApplicationManagerCore.GetSite(sm, d.Xml_SiteName)?.Stop(); } catch { ColorConsole.WriteLine($"Site {d.Xml_SiteName} already stopped."); } SiteStart(d, parameters); PoolStart(d, parameters); PoolRecycle(d, parameters); - Console.WriteLine($"Pool {d.Xml_PoolName} and site {d.Xml_SiteName} restarted."); + ColorConsole.WriteLine($"Pool {d.Xml_PoolName} and site {d.Xml_SiteName} restarted."); return parameters; } } @@ -173,14 +173,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (p != null && p.State == ObjectState.Stopped) { p.Start(); success = true; break; } else { - Console.WriteLine($"Trying to start pool {d.Xml_PoolName} ... Press key 'X' to exit..."); - if (Console.KeyAvailable) { if (Console.ReadKey().KeyChar.ToString().ToUpper() == "X") { break; } } + ColorConsole.WriteLine($"Trying to start pool {d.Xml_PoolName} ... Press key 'X' to exit..."); + if (ColorConsole.KeyAvailable) { if (ColorConsole.ReadKey().KeyChar.ToString().ToUpper() == "X") { break; } } Thread.Sleep(1000); } } var successstr = success ? "started" : "NOT started"; - Console.WriteLine($"{d.Xml_PoolName} {successstr}."); + ColorConsole.WriteLine($"{d.Xml_PoolName} {successstr}."); return parameters; } } @@ -196,13 +196,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (p != null && p.State == ObjectState.Started) { p.Recycle(); success = true; break; } else { - Console.WriteLine($"Trying to recycle pool {d.Xml_PoolName} ... Press key 'X' to exit..."); - if (Console.KeyAvailable) { if (Console.ReadKey().KeyChar.ToString().ToUpper() == "X") { break; } } + ColorConsole.WriteLine($"Trying to recycle pool {d.Xml_PoolName} ... Press key 'X' to exit..."); + if (ColorConsole.KeyAvailable) { if (ColorConsole.ReadKey().KeyChar.ToString().ToUpper() == "X") { break; } } Thread.Sleep(1000); } } var successstr = success ? "recycled" : "NOT recycled"; - Console.WriteLine($"{d.Xml_PoolName} {successstr}."); + ColorConsole.WriteLine($"{d.Xml_PoolName} {successstr}."); return parameters; } } @@ -218,14 +218,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (p != null && p.State == ObjectState.Started) { p.Stop(); success = true; break; } else { - Console.WriteLine($"Trying to stop pool {d.Xml_PoolName} ... Press key 'X' to exit..."); - if (Console.KeyAvailable) { if (Console.ReadKey().KeyChar.ToString().ToUpper() == "X") { break; } } + ColorConsole.WriteLine($"Trying to stop pool {d.Xml_PoolName} ... Press key 'X' to exit..."); + if (ColorConsole.KeyAvailable) { if (ColorConsole.ReadKey().KeyChar.ToString().ToUpper() == "X") { break; } } Thread.Sleep(1000); } } var successstr = success ? "stopped" : "NOT stopped"; - Console.WriteLine($"{d.Xml_PoolName} {successstr}."); + ColorConsole.WriteLine($"{d.Xml_PoolName} {successstr}."); return parameters; } } @@ -241,13 +241,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (s != null && s.State == ObjectState.Stopped) { s.Start(); success = true; break; } else { - Console.WriteLine($"Trying to start site {d.Xml_SiteName} ... Press key 'X' to exit..."); - if (Console.KeyAvailable) { if (Console.ReadKey().KeyChar.ToString().ToUpper() == "X") { break; } } + ColorConsole.WriteLine($"Trying to start site {d.Xml_SiteName} ... Press key 'X' to exit..."); + if (ColorConsole.KeyAvailable) { if (ColorConsole.ReadKey().KeyChar.ToString().ToUpper() == "X") { break; } } Thread.Sleep(1000); } } var successstr = success ? "started" : "NOT started"; - Console.WriteLine($"{d.Xml_SiteName} {successstr}."); + ColorConsole.WriteLine($"{d.Xml_SiteName} {successstr}."); return parameters; } } @@ -263,13 +263,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (s != null && s.State == ObjectState.Started) { s.Stop(); success = true; break; } else { - Console.WriteLine($"Trying to stop site {d.Xml_SiteName} ... Press key 'X' to exit..."); - if (Console.KeyAvailable) { if (Console.ReadKey().KeyChar.ToString().ToUpper() == "X") { break; } } + ColorConsole.WriteLine($"Trying to stop site {d.Xml_SiteName} ... Press key 'X' to exit..."); + if (ColorConsole.KeyAvailable) { if (ColorConsole.ReadKey().KeyChar.ToString().ToUpper() == "X") { break; } } Thread.Sleep(1000); } } var successstr = success ? "stopped" : "NOT stopped"; - Console.WriteLine($"{d.Xml_SiteName} {successstr}."); + ColorConsole.WriteLine($"{d.Xml_SiteName} {successstr}."); return parameters; } } @@ -277,14 +277,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole { WebApplication d = dobj as WebApplication; WebApplicationManagerCore.RegisterWebApplication(d.Xml_SiteName, d.Xml_PoolName, d.Xml_AppName, d.Xml_AppPhysicalPath, d.Xml_SitePhysicalPath, 8080, d.Xml_RecreatePool, d.Xml_RecreateSite, d.Xml_RecreateApp, d.Xml_PoolPipeLineMode); - Console.WriteLine($"{d.Xml_AppName} is registered in site {d.Xml_SiteName} using pool {d.Xml_PoolName}."); + ColorConsole.WriteLine($"{d.Xml_AppName} is registered in site {d.Xml_SiteName} using pool {d.Xml_PoolName}."); return parameters; } private static object Unregister(object dobj, object parameters) { WebApplication d = dobj as WebApplication; WebApplicationManagerCore.UnRegisterWebApplication(d.Xml_AppName, d.Xml_PoolName, d.Xml_SiteName, d.Xml_ForceRemovePool, d.Xml_ForceRemoveSite); - Console.WriteLine($"{d.Xml_AppName} is unregistered from site {d.Xml_SiteName} and from pool {d.Xml_PoolName}."); + ColorConsole.WriteLine($"{d.Xml_AppName} is unregistered from site {d.Xml_SiteName} and from pool {d.Xml_PoolName}."); return parameters; } private static object SetImpersonateIdentity(object dobj, object parameters) @@ -304,22 +304,22 @@ namespace Vrh.Log4Pro.MaintenanceConsole while(true) { - Console.WriteLine($"Current user info: {olduserinfo}"); - Console.WriteLine("Set impersonate-on status (true/false), then [Enter], EX=exit."); - impersonate = Console.ReadLine().ToUpper(); + ColorConsole.WriteLine($"Current user info: {olduserinfo}"); + ColorConsole.WriteLine("Set impersonate-on status (true/false), then [Enter], EX=exit."); + impersonate = ColorConsole.ReadLine().ToUpper(); if (impersonate == "EX") { return null; } else if (impersonate == "FALSE") { break; } else if (impersonate == "TRUE") { - Console.WriteLine("Enter username, then [Enter]."); + ColorConsole.WriteLine("Enter username, then [Enter]."); var un = !string.IsNullOrWhiteSpace(d.Xml_PoolUsername) ? $"empty={d.Xml_PoolUsername }," : ""; - Console.WriteLine($"{un}EX=exit"); - username = Console.ReadLine().ToUpper(); + ColorConsole.WriteLine($"{un}EX=exit"); + username = ColorConsole.ReadLine().ToUpper(); if (impersonate == "EX") { return null; } - Console.WriteLine("Enter password, then [Enter]"); + ColorConsole.WriteLine("Enter password, then [Enter]"); var pw = !string.IsNullOrWhiteSpace(d.Xml_PoolPassword) ? $"empty={d.Xml_PoolPassword}," : ""; - Console.WriteLine($"{pw}EX=exit"); - password = Console.ReadLine().ToUpper(); + ColorConsole.WriteLine($"{pw}EX=exit"); + password = ColorConsole.ReadLine().ToUpper(); if (impersonate == "EX") { return null; } break; //bool valid = System.Web.ApplicationSerices.AuthenticationService.ValidateUser(username, password, mull); @@ -333,8 +333,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole parameters = new Dictionary { { "impersonate", impersonate }, { "username", username }, { "password", password }, }; } WebApplicationManagerCore.SetImpersonateIdentity(d.Xml_IdentityConfigFile, impersonate, username, password); - Console.WriteLine($"Impersonate identity changed for webapp {d.Xml_AppName}."); - Console.WriteLine($"From '{olduserinfo}' to '{WebApplicationManagerCore.GetImpersonateIdentityInfo(d.Xml_IdentityConfigFile)}'"); + ColorConsole.WriteLine($"Impersonate identity changed for webapp {d.Xml_AppName}."); + ColorConsole.WriteLine($"From '{olduserinfo}' to '{WebApplicationManagerCore.GetImpersonateIdentityInfo(d.Xml_IdentityConfigFile)}'"); return parameters; } @@ -351,16 +351,16 @@ namespace Vrh.Log4Pro.MaintenanceConsole } else { - Console.WriteLine($"Current user info: {olduserinfo}"); - Console.WriteLine("Enter username, then [Enter]."); - Console.WriteLine("Special usernames are: (Empty=API) "); - Console.WriteLine($" (API) {nameof(ProcessModelIdentityType.ApplicationPoolIdentity)}"); - Console.WriteLine($" (LSE) {nameof(ProcessModelIdentityType.LocalService)}"); - Console.WriteLine($" (LSY) {nameof(ProcessModelIdentityType.LocalSystem)}"); - Console.WriteLine($" (NSE) {nameof(ProcessModelIdentityType.NetworkService)}"); + ColorConsole.WriteLine($"Current user info: {olduserinfo}"); + ColorConsole.WriteLine("Enter username, then [Enter]."); + ColorConsole.WriteLine("Special usernames are: (Empty=API) "); + ColorConsole.WriteLine($" (API) {nameof(ProcessModelIdentityType.ApplicationPoolIdentity)}"); + ColorConsole.WriteLine($" (LSE) {nameof(ProcessModelIdentityType.LocalService)}"); + ColorConsole.WriteLine($" (LSY) {nameof(ProcessModelIdentityType.LocalSystem)}"); + ColorConsole.WriteLine($" (NSE) {nameof(ProcessModelIdentityType.NetworkService)}"); ColorConsole.WriteLine(); ColorConsole.Write(" (EX) ", ConsoleColor.Red); ColorConsole.WriteLine("Exit"); - username = Console.ReadLine().ToUpper(); + username = ColorConsole.ReadLine().ToUpper(); if (username == "EX") { return null; } if (string.IsNullOrEmpty(username)) { username = nameof(ProcessModelIdentityType.ApplicationPoolIdentity); }; if (username == "API" || username == nameof(ProcessModelIdentityType.ApplicationPoolIdentity)) { username = nameof(ProcessModelIdentityType.ApplicationPoolIdentity); } @@ -369,14 +369,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole else if (username == "NSE" || username == nameof(ProcessModelIdentityType.NetworkService)) { username = nameof(ProcessModelIdentityType.NetworkService); } else { - Console.WriteLine("Enter password, then [Enter]"); - password = Console.ReadLine().ToUpper(); + ColorConsole.WriteLine("Enter password, then [Enter]"); + password = ColorConsole.ReadLine().ToUpper(); //bool valid = System.Web.ApplicationSerices.AuthenticationService.ValidateUser(username, password, mull); } parameters = new Dictionary { { "username", username }, { "password", password }, }; } WebApplicationManagerCore.SetPoolUserAccount(d.Xml_AppName, d.Xml_SiteName, username, password); - Console.WriteLine($"Pool user changed from {olduserinfo} to {WebApplicationManagerCore.GetUserInfo(d.Xml_PoolName)} for pool {d.Xml_PoolName}."); + ColorConsole.WriteLine($"Pool user changed from {olduserinfo} to {WebApplicationManagerCore.GetUserInfo(d.Xml_PoolName)} for pool {d.Xml_PoolName}."); return parameters; } #endregion diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs index 43c86c2..8bf36c4 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs @@ -48,8 +48,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole if (sr.Result == Menu.SelectionResult.Exit) { break; } else if (sr.Result == Menu.SelectionResult.None) { continue; } else if (sr.Result == Menu.SelectionResult.Error) { continue; } - menufunctions.SetParameters(sr,config); - menufunctions.Execute(sr.SelectedKeyList); + menufunctions.SetExecutorParameters(sr,config); + menufunctions.ExecuteSelection(sr.SelectedKeyList); } return null; } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Program.cs b/Vrh.Log4Pro.MaintenanceConsole/Program.cs index 5e4b0bc..a7143ea 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Program.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Program.cs @@ -9,6 +9,7 @@ using System.Management; using System.Diagnostics; using Vrh.XmlProcessing; +using VRH.Common; using System.Xml.Linq; namespace Vrh.Log4Pro.MaintenanceConsole @@ -17,11 +18,21 @@ namespace Vrh.Log4Pro.MaintenanceConsole { static void Main(string[] args) { - try { Console.SetWindowSize(120, 64); } + ColorConsole.ReadLine("Press a key to start..."); + var appconfigpath = CommandLine.GetCommandLineArgument(args, "-APPCONFIG"); + CommandLine.SetAppConfigFile(appconfigpath); + + try { ColorConsole.SetWindowSize(120, 64); } catch (Exception ex) { - ColorConsole.WriteLine("Change the size of the console fonts smaller!"); - Console.ReadKey(); + ColorConsole.WriteLine("Change the size of the console fonts smaller!"); + ColorConsole.ReadKey(); + return; + } + if (!Tools.IsElevated) + { + ColorConsole.WriteLine("Run as administartor!"); + ColorConsole.ReadKey(); return; } @@ -29,12 +40,24 @@ namespace Vrh.Log4Pro.MaintenanceConsole .AddMenuItem(new Menu.Item("WAM", "Web Application Manager", WebApplicationManager.Execute)) .AddMenuItem(new Menu.Item("WSM", "Windows Service Manager", WindowsServiceManager.Execute)) .AddMenuItem(new Menu.Item("FCL", "File Cleaner Manager", FileCleanerManager.Execute)) + .AddMenuItem(new Menu.Item("SCH", "Scheduled Task Manager", ScheduledTaskmanagerManager.Execute)) .AddMenuItem(new Menu.ItemSeparator('-')) .AddMenuItem(new Menu.Item("TOL", "Maintenance tools", MaintenanceToolManager.Execute)) .SetSelectionMode(Menu.SelectionMode.Single); - mm.ExecuteMenu(); - ColorConsole.WriteLine("Press any key to exit..."); Console.ReadKey(); + var commandmode = !string.IsNullOrEmpty(CommandLine.GetCommandLineArgument(args, "-MODULE")); + if (commandmode) + { + var silentmode = !string.IsNullOrEmpty(CommandLine.GetCommandLineArgument(args, "-SILENT", switchtype: true)); + ColorConsole.SetSilentMode(silentmode); + Menu.SetCommandModeAllMenus(); + mm.ExecuteCmd(args); + } + else + { + mm.ExecuteMenu(); + ColorConsole.PressAnykeyToContinue(); + } } } } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj b/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj index e35d36c..105c84b 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj +++ b/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj @@ -1,6 +1,6 @@  - + Debug @@ -37,10 +37,10 @@ - ..\packages\EntityFramework.6.4.0\lib\net45\EntityFramework.dll + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll - ..\packages\EntityFramework.6.4.0\lib\net45\EntityFramework.SqlServer.dll + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll ..\packages\Microsoft.Web.Administration.11.1.0\lib\netstandard1.5\Microsoft.Web.Administration.dll @@ -145,8 +145,8 @@ - - ..\packages\VRH.Common.2.19.0\lib\net45\VRH.Common.dll + + ..\packages\VRH.Common.2.19.1\lib\net45\VRH.Common.dll ..\packages\Vrh.XmlProcessing.1.23.0\lib\net45\Vrh.XmlProcessing.dll @@ -156,6 +156,8 @@ + + @@ -179,13 +181,14 @@ Always + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - + \ No newline at end of file diff --git a/Vrh.Log4Pro.MaintenanceConsole/packages.config b/Vrh.Log4Pro.MaintenanceConsole/packages.config index 3432258..452ae56 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/packages.config +++ b/Vrh.Log4Pro.MaintenanceConsole/packages.config @@ -1,6 +1,6 @@  - + @@ -55,6 +55,6 @@ - + \ No newline at end of file -- libgit2 0.21.2