diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs index 2c9119d..7c9ad89 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs @@ -207,6 +207,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS public static class Function { public const string CMD_WEBAPPS = "-WEBAPPS"; + public const string CMD_SENDURL = "-SENDURL"; public static class Register { public const string KEY = "WAR"; } public static class ConfigureIIS { public const string KEY = "IIS"; } public static class Unregister { public const string KEY = "WAU"; } diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools - Http.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools - Http.cs index f560593..ab90753 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools - Http.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools - Http.cs @@ -30,29 +30,43 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS public static class HttpTools { public enum RequestType { GET,POST,} - public static ReturnInfoJSON GetReturninfoJSON(string url, RequestType mode = RequestType.GET, List dictparameterlist=null) + public static ReturnInfoJSON GetReturninfoJSON(string url, int timeoutinseconds,RequestType mode = RequestType.GET, List dictparameterlist=null) { string returninfojsonstring = ""; + timeoutinseconds = timeoutinseconds <= 0 ? 100: timeoutinseconds; try { - return mode == RequestType.GET? _GetReturninfoJSON(url,out returninfojsonstring) : _PostReturninfoJSON(url, out returninfojsonstring, dictparameterlist); + return mode == RequestType.GET? _GetReturninfoJSON(url, timeoutinseconds,out returninfojsonstring) : _PostReturninfoJSON(url, timeoutinseconds, out returninfojsonstring, dictparameterlist); } catch (Exception ex) { return new ReturnInfoJSON() { ReturnValue = -1, ReturnMessage = ex.Message + "\n" + returninfojsonstring, }; } } - private static ReturnInfoJSON _GetReturninfoJSON(string url, out string returninfojsonstring) + private static ReturnInfoJSON _GetReturninfoJSON(string url, int timeoutinseconds, out string returninfojsonstring) { - var returninfojsonstream = Task.Run(async () => await (new HttpClient()).GetStreamAsync(url)).GetAwaiter().GetResult(); + Stream returninfojsonstream; + using (var httpclient = new HttpClient()) + { + httpclient.Timeout = new TimeSpan(0, 0, timeoutinseconds); + returninfojsonstream = Task.Run(async () => await httpclient.GetStreamAsync(url)).GetAwaiter().GetResult(); + } + returninfojsonstring = GetStreamAsString(returninfojsonstream); ReturnInfoJSON returninfojson = (ReturnInfoJSON)JsonConvert.DeserializeObject(returninfojsonstring,typeof(ReturnInfoJSON)); //ReturnInfoJSON returninfojson = Task.Run(async () => await JsonSerializer.DeserializeAsync(returninfojsonstream)).GetAwaiter().GetResult(); return returninfojson; } - private static ReturnInfoJSON _PostReturninfoJSON(string url, out string returninfojsonstring, List dictparameterlist = null) + private static ReturnInfoJSON _PostReturninfoJSON(string url, int timeoutinseconds, out string returninfojsonstring, List dictparameterlist = null) { var jsonstring = JsonConvert.SerializeObject(dictparameterlist.Where(p => p.PassTo == Vrh.XmlProcessing.UrlElement.ParameterTypes.dict)); HttpContent requestcontent = new StringContent(jsonstring); - var returninfojsonhttpresponsemessage = Task.Run(async () => await (new HttpClient()).PostAsync(url, requestcontent)).GetAwaiter().GetResult(); + + HttpResponseMessage returninfojsonhttpresponsemessage; + using (var httpclient = new HttpClient()) + { + httpclient.Timeout = new TimeSpan(0, 0, timeoutinseconds); + returninfojsonhttpresponsemessage = Task.Run(async () => await httpclient.PostAsync(url, requestcontent)).GetAwaiter().GetResult(); + } + var returninfojsonstream = Task.Run(async () => await returninfojsonhttpresponsemessage.Content.ReadAsStreamAsync()).GetAwaiter().GetResult(); returninfojsonstring = GetStreamAsString(returninfojsonstream); ReturnInfoJSON returninfojson = (ReturnInfoJSON)JsonConvert.DeserializeObject(returninfojsonstring, typeof(ReturnInfoJSON)); diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs index e170eb1..64dfeb5 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs @@ -53,12 +53,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS } } - public static void StartAsSystem(bool silent) + public static void StartAsSystem(bool interactivemode=false) { - if (!silent) + if (interactivemode) { var ans = ColorConsole.ReadLine("NT AUTHORITY\\SYSTEM", prefix: "Start as ",f:ConsoleColor.Yellow, suffix: "?", bracket: "[]",validitylist:new List { "yes","no"},exitvalue:"EX",defaultvalue:"no"); - if (ans.ToLower() != "yes") { return; } + if (ans?.ToLower() != "yes") { return; } } string runasusername = System.Security.Principal.WindowsIdentity.GetCurrent().Name; if (runasusername=="NT AUTHORITY\\SYSTEM") { return; } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs index 0b70249..5e2a452 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs @@ -43,6 +43,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS .AddMenuItem(new Menu.Item(CLP.Module.MaintenanceToolManager.Functions.RegexTester.KEY, "Regex tester", RegexTester,new Menu.ExecutorParameter(cfg:config))) .AddMenuItem(new Menu.Item(CLP.Module.MaintenanceToolManager.Functions.TCPIPTester.KEY, "TcpIp Tester", TcpIpTester, new Menu.ExecutorParameter(cfg: config, null))) .AddMenuItem(new Menu.Item(CLP.Module.MaintenanceToolManager.Functions.Tool.KEY, "Tool sample", Tool2, new Menu.ExecutorParameter(cfg: config, null))) + .SetSelectionMode(Menu.SelectionMode.Single); foreach (var x in config.ExternalUtilityConfigList) { @@ -74,7 +75,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS #region RegexTester public static object StartAsSystem(object parameter, object o) { - OtherTools.StartAsSystem(true); + OtherTools.StartAsSystem(); return o; } private static object RegexTester(object parameter, object o) diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - ScheduledTaskManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - ScheduledTaskManager.cs index 6efb8ac..49f6c9d 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - ScheduledTaskManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - ScheduledTaskManager.cs @@ -283,7 +283,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ScheduledTaskManagerNS 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 " "; @@ -293,11 +292,16 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ScheduledTaskManagerNS 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.Write($"{st.Xml_Enable}", ConsoleColor.Yellow, prefix: "After install: Enable=", suffix: ","); + ColorConsole.Write($"{st.Xml_Run}", ConsoleColor.Yellow, prefix: "Run=", suffix: ". "); ColorConsole.WriteLine(" "); return " "; } + else if (lineix == 2) + { + ColorConsole.WriteLine($"{st.Xml_Commandname}", ConsoleColor.Yellow, prefix: "Command: "); + return " "; + } return null; } #endregion private method: DisplayTaskInfo diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs index 38c0a8a..50a56a9 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs @@ -88,6 +88,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS var config = (parameters as Menu.ExecutorParameter).GetConfig(); var args = (parameters as Menu.ExecutorParameter).Args; var selectedwaindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WebApplicationManager.Function.CMD_WEBAPPS); + var predefinedsendurlname = CommandLine.GetCommandLineArgument(args, CLP.Module.WebApplicationManager.Function.CMD_SENDURL); var menuwapps = DisplayWebApplicationMenu(config, "Select the web application(s) to manage!", silent: true); menuwapps.SetSelectionMode(Menu.SelectionMode.Single); Menu.Selection sr = menuwapps.Select(selectedwaindexes); @@ -104,7 +105,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS var therearepredefinedurls = selectedwebapplication.Xml_SendUrlList != null && selectedwebapplication.Xml_SendUrlList.Any(); string urlname; List sendurlnamelist=null; - if (therearepredefinedurls) + if (therearepredefinedurls && !string.IsNullOrWhiteSpace(predefinedsendurlname)) { urlname = predefinedsendurlname; } + else if (therearepredefinedurls) { ColorConsole.WriteLine("Enter the name of the url to send, or * to enter url manually:", ConsoleColor.Yellow); sendurlnamelist = selectedwebapplication.Xml_SendUrlList.Select(su => su.Name).ToList(); @@ -122,6 +124,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS string urltext; HttpTools.RequestType gp; + int to; List uplist=null; if (urlname.ToLower() == "*") { @@ -134,12 +137,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS if (string.IsNullOrWhiteSpace(urltext)) goto getsendurlnameurlinputcycle; ColorConsole.WriteLine("Enter request type (GET/POST):", ConsoleColor.Yellow); string gpstr = ColorConsole.ReadLine(); - gp = HttpTools.RequestType.GET; if (gpstr.ToLower() == "ex") return o; + gp = HttpTools.RequestType.GET; if (string.IsNullOrWhiteSpace(gpstr)) goto getsendurlnameurlinputcycle; else if (gpstr.ToUpper() == nameof(HttpTools.RequestType.GET)) { gp = HttpTools.RequestType.GET; } else if (gpstr.ToUpper() == nameof(HttpTools.RequestType.POST)) { gp = HttpTools.RequestType.POST; } + ColorConsole.WriteLine("Enter timeout (0 for default):", ConsoleColor.Yellow); + string tostring = ColorConsole.ReadLine(); + if (tostring.ToLower() == "ex") return o; + to = 0; + if (string.IsNullOrWhiteSpace(tostring)) goto getsendurlnameurlinputcycle; + else if (!int.TryParse(tostring,out to)) { } } else if (sendurlnamelist!=null && !sendurlnamelist.Contains(urlname)) { ColorConsole.WriteLine("Invalid selection!", ConsoleColor.Red); return o; } else @@ -149,12 +158,17 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS urltext = urlobject.GetUrl(); uplist = urlobject.UrlParameters.Where(p => p.PassTo == Vrh.XmlProcessing.UrlElement.ParameterTypes.dict).ToList(); gp = sendurlobject.ForcePOST || uplist.Any() ? HttpTools.RequestType.POST : HttpTools.RequestType.GET; + to = sendurlobject.TimeoutInSeconds; } - ToolsNS.HttpTools.ReturnInfoJSON returninfojson = HttpTools.GetReturninfoJSON(urltext, gp); + repeatsameurl: + ToolsNS.HttpTools.ReturnInfoJSON returninfojson = HttpTools.GetReturninfoJSON(urltext, to,gp); ColorConsole.WriteLine("ReturnValue:", ConsoleColor.Yellow, suffix: returninfojson.ReturnValue.ToString()); ColorConsole.WriteLine("ReturnMessage:", ConsoleColor.Yellow, suffix: returninfojson.ReturnMessage); ColorConsole.WriteLine(); + ColorConsole.WriteLine("Repeat the same url?", ConsoleColor.Gray, suffix: "Yes/No/y/n"); + var repeat = ColorConsole.ReadLine().ToLower(); + if (repeat == "yes" || repeat == "y") goto repeatsameurl; return o; } @@ -1287,6 +1301,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS public Vrh.XmlProcessing.UrlElement UrlElement; public bool ForcePOST = false; public string Name; + public int TimeoutInSeconds = 0; public bool IsOK { get @@ -1314,7 +1329,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS public SendUrl(XElement sendurlxmlelement) { Name = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.Name), sendurlxmlelement, ""); - ForcePOST = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.ForcePost), sendurlxmlelement, XmlStructure.WebApplication.SendUrl.Attributes.ForcePost.Values.DEFAULT); + ForcePOST = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.forcepost), sendurlxmlelement, XmlStructure.WebApplication.SendUrl.Attributes.forcepost.Values.DEFAULT); + TimeoutInSeconds = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.timeoutinseconds), sendurlxmlelement, XmlStructure.WebApplication.SendUrl.Attributes.timeoutinseconds.Values.DEFAULT); Vrh.XmlProcessing.UrlElement xxxx = new Vrh.XmlProcessing.UrlElement(sendurlxmlelement); UrlElement = new Vrh.XmlProcessing.UrlElement(); UrlElement.Url = GetValue(sendurlxmlelement, ""); @@ -1382,7 +1398,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS public static class Attributes { public static class Name { } - public static class ForcePost { public static class Values { public static bool DEFAULT = false; } } + public static class forcepost { public static class Values { public static bool DEFAULT = false; } } + public static class timeoutinseconds { public static class Values { public static int DEFAULT = 0; } } public static class protocol { } public static class hostname { } public static class appname { } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Program.cs b/Vrh.Log4Pro.MaintenanceConsole/Program.cs index 0d8be91..cd60efb 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Program.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Program.cs @@ -37,19 +37,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole { static void Main(string[] args) { - //Tests.T3(); - //return; - - var startassystemstr = CommandLine.GetCommandLineArgument(args, CLP.CMD_STARTASSYSTEM); - var startassystem = startassystemstr!=null && startassystemstr.ToLower() == "yes"; - - OtherTools.StartAsAdmin(); - OtherTools.StartAsSystem(silent:startassystem); - var forcedmodulekey = CommandLine.GetCommandLineArgument(args, CLP.CMD_MODULE); var commandmode = !string.IsNullOrEmpty(forcedmodulekey); var silentmode = commandmode && !string.IsNullOrEmpty(CommandLine.GetCommandLineArgument(args, CLP.CMD_SILENT, switchtype: true)); ColorConsole.SilentMode=silentmode; + + if (ColorConsole.SilentMode) { Thread.Sleep(20000); } // ez azért van, hogy ha a schedulerben elindítjuk az ütemmezett taskot, akkor rá tudjunk kapcsolódni a debuggerrel + + var startassystemstr = CommandLine.GetCommandLineArgument(args, CLP.CMD_STARTASSYSTEM); + var startassystem = startassystemstr != null && startassystemstr.ToLower() == "yes"; + OtherTools.StartAsAdmin(); + OtherTools.StartAsSystem(!startassystem); + Menu.SetCommandMode(commandmode); var appconfigpath = CommandLine.GetCommandLineArgument(args, CLP.CMD_APPCONFIG); diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index 9b54848..3f7de57 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.16.1.0")] -[assembly: AssemblyFileVersion("1.16.1.0")] +[assembly: AssemblyVersion("1.16.3.0")] +[assembly: AssemblyFileVersion("1.16.3.0")] -- libgit2 0.21.2