Commit c4219940de46aba246e2ae6c194d41a8033f3ba3
1 parent
009667da
WebApplicationManager / SendUrl megvalósítása command módra
Showing
8 changed files
with
65 additions
and
29 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
| ... | ... | @@ -207,6 +207,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS |
| 207 | 207 | public static class Function |
| 208 | 208 | { |
| 209 | 209 | public const string CMD_WEBAPPS = "-WEBAPPS"; |
| 210 | + public const string CMD_SENDURL = "-SENDURL"; | |
| 210 | 211 | public static class Register { public const string KEY = "WAR"; } |
| 211 | 212 | public static class ConfigureIIS { public const string KEY = "IIS"; } |
| 212 | 213 | public static class Unregister { public const string KEY = "WAU"; } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools - Http.cs
| ... | ... | @@ -30,29 +30,43 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
| 30 | 30 | public static class HttpTools |
| 31 | 31 | { |
| 32 | 32 | public enum RequestType { GET,POST,} |
| 33 | - public static ReturnInfoJSON GetReturninfoJSON(string url, RequestType mode = RequestType.GET, List<Vrh.XmlProcessing.UrlElement.UrlParameter> dictparameterlist=null) | |
| 33 | + public static ReturnInfoJSON GetReturninfoJSON(string url, int timeoutinseconds,RequestType mode = RequestType.GET, List<Vrh.XmlProcessing.UrlElement.UrlParameter> dictparameterlist=null) | |
| 34 | 34 | { |
| 35 | 35 | string returninfojsonstring = ""; |
| 36 | + timeoutinseconds = timeoutinseconds <= 0 ? 100: timeoutinseconds; | |
| 36 | 37 | try |
| 37 | 38 | { |
| 38 | - return mode == RequestType.GET? _GetReturninfoJSON(url,out returninfojsonstring) : _PostReturninfoJSON(url, out returninfojsonstring, dictparameterlist); | |
| 39 | + return mode == RequestType.GET? _GetReturninfoJSON(url, timeoutinseconds,out returninfojsonstring) : _PostReturninfoJSON(url, timeoutinseconds, out returninfojsonstring, dictparameterlist); | |
| 39 | 40 | } |
| 40 | 41 | catch (Exception ex) { return new ReturnInfoJSON() { ReturnValue = -1, ReturnMessage = ex.Message + "\n" + returninfojsonstring, }; } |
| 41 | 42 | } |
| 42 | 43 | |
| 43 | - private static ReturnInfoJSON _GetReturninfoJSON(string url, out string returninfojsonstring) | |
| 44 | + private static ReturnInfoJSON _GetReturninfoJSON(string url, int timeoutinseconds, out string returninfojsonstring) | |
| 44 | 45 | { |
| 45 | - var returninfojsonstream = Task.Run(async () => await (new HttpClient()).GetStreamAsync(url)).GetAwaiter().GetResult(); | |
| 46 | + Stream returninfojsonstream; | |
| 47 | + using (var httpclient = new HttpClient()) | |
| 48 | + { | |
| 49 | + httpclient.Timeout = new TimeSpan(0, 0, timeoutinseconds); | |
| 50 | + returninfojsonstream = Task.Run(async () => await httpclient.GetStreamAsync(url)).GetAwaiter().GetResult(); | |
| 51 | + } | |
| 52 | + | |
| 46 | 53 | returninfojsonstring = GetStreamAsString(returninfojsonstream); |
| 47 | 54 | ReturnInfoJSON returninfojson = (ReturnInfoJSON)JsonConvert.DeserializeObject(returninfojsonstring,typeof(ReturnInfoJSON)); |
| 48 | 55 | //ReturnInfoJSON returninfojson = Task.Run(async () => await JsonSerializer.DeserializeAsync<ReturnInfoJSON>(returninfojsonstream)).GetAwaiter().GetResult(); |
| 49 | 56 | return returninfojson; |
| 50 | 57 | } |
| 51 | - private static ReturnInfoJSON _PostReturninfoJSON(string url, out string returninfojsonstring, List<Vrh.XmlProcessing.UrlElement.UrlParameter> dictparameterlist = null) | |
| 58 | + private static ReturnInfoJSON _PostReturninfoJSON(string url, int timeoutinseconds, out string returninfojsonstring, List<Vrh.XmlProcessing.UrlElement.UrlParameter> dictparameterlist = null) | |
| 52 | 59 | { |
| 53 | 60 | var jsonstring = JsonConvert.SerializeObject(dictparameterlist.Where(p => p.PassTo == Vrh.XmlProcessing.UrlElement.ParameterTypes.dict)); |
| 54 | 61 | HttpContent requestcontent = new StringContent(jsonstring); |
| 55 | - var returninfojsonhttpresponsemessage = Task.Run(async () => await (new HttpClient()).PostAsync(url, requestcontent)).GetAwaiter().GetResult(); | |
| 62 | + | |
| 63 | + HttpResponseMessage returninfojsonhttpresponsemessage; | |
| 64 | + using (var httpclient = new HttpClient()) | |
| 65 | + { | |
| 66 | + httpclient.Timeout = new TimeSpan(0, 0, timeoutinseconds); | |
| 67 | + returninfojsonhttpresponsemessage = Task.Run(async () => await httpclient.PostAsync(url, requestcontent)).GetAwaiter().GetResult(); | |
| 68 | + } | |
| 69 | + | |
| 56 | 70 | var returninfojsonstream = Task.Run(async () => await returninfojsonhttpresponsemessage.Content.ReadAsStreamAsync()).GetAwaiter().GetResult(); |
| 57 | 71 | returninfojsonstring = GetStreamAsString(returninfojsonstream); |
| 58 | 72 | ReturnInfoJSON returninfojson = (ReturnInfoJSON)JsonConvert.DeserializeObject(returninfojsonstring, typeof(ReturnInfoJSON)); | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs
| ... | ... | @@ -53,12 +53,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public static void StartAsSystem(bool silent) | |
| 56 | + public static void StartAsSystem(bool interactivemode=false) | |
| 57 | 57 | { |
| 58 | - if (!silent) | |
| 58 | + if (interactivemode) | |
| 59 | 59 | { |
| 60 | 60 | var ans = ColorConsole.ReadLine("NT AUTHORITY\\SYSTEM", prefix: "Start as ",f:ConsoleColor.Yellow, suffix: "?", bracket: "[]",validitylist:new List<string> { "yes","no"},exitvalue:"EX",defaultvalue:"no"); |
| 61 | - if (ans.ToLower() != "yes") { return; } | |
| 61 | + if (ans?.ToLower() != "yes") { return; } | |
| 62 | 62 | } |
| 63 | 63 | string runasusername = System.Security.Principal.WindowsIdentity.GetCurrent().Name; |
| 64 | 64 | if (runasusername=="NT AUTHORITY\\SYSTEM") { return; } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs
| ... | ... | @@ -43,6 +43,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS |
| 43 | 43 | .AddMenuItem(new Menu.Item(CLP.Module.MaintenanceToolManager.Functions.RegexTester.KEY, "Regex tester", RegexTester,new Menu.ExecutorParameter(cfg:config))) |
| 44 | 44 | .AddMenuItem(new Menu.Item(CLP.Module.MaintenanceToolManager.Functions.TCPIPTester.KEY, "TcpIp Tester", TcpIpTester, new Menu.ExecutorParameter(cfg: config, null))) |
| 45 | 45 | .AddMenuItem(new Menu.Item(CLP.Module.MaintenanceToolManager.Functions.Tool.KEY, "Tool sample", Tool2, new Menu.ExecutorParameter(cfg: config, null))) |
| 46 | + | |
| 46 | 47 | .SetSelectionMode(Menu.SelectionMode.Single); |
| 47 | 48 | foreach (var x in config.ExternalUtilityConfigList) |
| 48 | 49 | { |
| ... | ... | @@ -74,7 +75,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS |
| 74 | 75 | #region RegexTester |
| 75 | 76 | public static object StartAsSystem(object parameter, object o) |
| 76 | 77 | { |
| 77 | - OtherTools.StartAsSystem(true); | |
| 78 | + OtherTools.StartAsSystem(); | |
| 78 | 79 | return o; |
| 79 | 80 | } |
| 80 | 81 | private static object RegexTester(object parameter, object o) | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - ScheduledTaskManager.cs
| ... | ... | @@ -283,7 +283,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ScheduledTaskManagerNS |
| 283 | 283 | if (st.Status != "Uninstalled" && st.Status != "Disabled") |
| 284 | 284 | { |
| 285 | 285 | ColorConsole.Write(st.PriorityText(st.Priority), statuscolor, prefix: "Effective priority ", suffix: ". "); |
| 286 | - ColorConsole.Write($"{st.Xml_Commandname}", ConsoleColor.Yellow, prefix: "Command: "); | |
| 287 | 286 | } |
| 288 | 287 | ColorConsole.WriteLine(); |
| 289 | 288 | return " "; |
| ... | ... | @@ -293,11 +292,16 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ScheduledTaskManagerNS |
| 293 | 292 | ColorConsole.Write($"{st.Xml_Schedule}",ConsoleColor.Yellow,prefix:"Scheduled ",suffix:" "); |
| 294 | 293 | ColorConsole.Write($"{st.Xml_StartTime}", ConsoleColor.Yellow, prefix: "at ", suffix: ", "); |
| 295 | 294 | ColorConsole.Write(st.PriorityText(st.Xml_Priority), ConsoleColor.Yellow, prefix: "with priority ", suffix: ". "); |
| 296 | - ColorConsole.Write($"{st.Xml_Enable}", ConsoleColor.Yellow, prefix: "After install ", suffix: " "); | |
| 297 | - ColorConsole.Write($"{st.Xml_Run}", ConsoleColor.Yellow, prefix: "and run ", suffix: ". "); | |
| 295 | + ColorConsole.Write($"{st.Xml_Enable}", ConsoleColor.Yellow, prefix: "After install: Enable=", suffix: ","); | |
| 296 | + ColorConsole.Write($"{st.Xml_Run}", ConsoleColor.Yellow, prefix: "Run=", suffix: ". "); | |
| 298 | 297 | ColorConsole.WriteLine(" "); |
| 299 | 298 | return " "; |
| 300 | 299 | } |
| 300 | + else if (lineix == 2) | |
| 301 | + { | |
| 302 | + ColorConsole.WriteLine($"{st.Xml_Commandname}", ConsoleColor.Yellow, prefix: "Command: "); | |
| 303 | + return " "; | |
| 304 | + } | |
| 301 | 305 | return null; |
| 302 | 306 | } |
| 303 | 307 | #endregion private method: DisplayTaskInfo | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs
| ... | ... | @@ -88,6 +88,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS |
| 88 | 88 | var config = (parameters as Menu.ExecutorParameter).GetConfig<WebApplicationManagerXmlProcessor>(); |
| 89 | 89 | var args = (parameters as Menu.ExecutorParameter).Args; |
| 90 | 90 | var selectedwaindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WebApplicationManager.Function.CMD_WEBAPPS); |
| 91 | + var predefinedsendurlname = CommandLine.GetCommandLineArgument(args, CLP.Module.WebApplicationManager.Function.CMD_SENDURL); | |
| 91 | 92 | var menuwapps = DisplayWebApplicationMenu(config, "Select the web application(s) to manage!", silent: true); |
| 92 | 93 | menuwapps.SetSelectionMode(Menu.SelectionMode.Single); |
| 93 | 94 | Menu.Selection sr = menuwapps.Select(selectedwaindexes); |
| ... | ... | @@ -104,7 +105,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS |
| 104 | 105 | var therearepredefinedurls = selectedwebapplication.Xml_SendUrlList != null && selectedwebapplication.Xml_SendUrlList.Any(); |
| 105 | 106 | string urlname; |
| 106 | 107 | List<string> sendurlnamelist=null; |
| 107 | - if (therearepredefinedurls) | |
| 108 | + if (therearepredefinedurls && !string.IsNullOrWhiteSpace(predefinedsendurlname)) { urlname = predefinedsendurlname; } | |
| 109 | + else if (therearepredefinedurls) | |
| 108 | 110 | { |
| 109 | 111 | ColorConsole.WriteLine("Enter the name of the url to send, or * to enter url manually:", ConsoleColor.Yellow); |
| 110 | 112 | sendurlnamelist = selectedwebapplication.Xml_SendUrlList.Select(su => su.Name).ToList(); |
| ... | ... | @@ -122,6 +124,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS |
| 122 | 124 | |
| 123 | 125 | string urltext; |
| 124 | 126 | HttpTools.RequestType gp; |
| 127 | + int to; | |
| 125 | 128 | List<Vrh.XmlProcessing.UrlElement.UrlParameter> uplist=null; |
| 126 | 129 | if (urlname.ToLower() == "*") |
| 127 | 130 | { |
| ... | ... | @@ -134,12 +137,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS |
| 134 | 137 | if (string.IsNullOrWhiteSpace(urltext)) goto getsendurlnameurlinputcycle; |
| 135 | 138 | ColorConsole.WriteLine("Enter request type (GET/POST):", ConsoleColor.Yellow); |
| 136 | 139 | string gpstr = ColorConsole.ReadLine(); |
| 137 | - gp = HttpTools.RequestType.GET; | |
| 138 | 140 | if (gpstr.ToLower() == "ex") return o; |
| 141 | + gp = HttpTools.RequestType.GET; | |
| 139 | 142 | if (string.IsNullOrWhiteSpace(gpstr)) goto getsendurlnameurlinputcycle; |
| 140 | 143 | else if (gpstr.ToUpper() == nameof(HttpTools.RequestType.GET)) { gp = HttpTools.RequestType.GET; } |
| 141 | 144 | else if (gpstr.ToUpper() == nameof(HttpTools.RequestType.POST)) { gp = HttpTools.RequestType.POST; } |
| 142 | 145 | |
| 146 | + ColorConsole.WriteLine("Enter timeout (0 for default):", ConsoleColor.Yellow); | |
| 147 | + string tostring = ColorConsole.ReadLine(); | |
| 148 | + if (tostring.ToLower() == "ex") return o; | |
| 149 | + to = 0; | |
| 150 | + if (string.IsNullOrWhiteSpace(tostring)) goto getsendurlnameurlinputcycle; | |
| 151 | + else if (!int.TryParse(tostring,out to)) { } | |
| 143 | 152 | } |
| 144 | 153 | else if (sendurlnamelist!=null && !sendurlnamelist.Contains(urlname)) { ColorConsole.WriteLine("Invalid selection!", ConsoleColor.Red); return o; } |
| 145 | 154 | else |
| ... | ... | @@ -149,12 +158,17 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS |
| 149 | 158 | urltext = urlobject.GetUrl(); |
| 150 | 159 | uplist = urlobject.UrlParameters.Where(p => p.PassTo == Vrh.XmlProcessing.UrlElement.ParameterTypes.dict).ToList(); |
| 151 | 160 | gp = sendurlobject.ForcePOST || uplist.Any() ? HttpTools.RequestType.POST : HttpTools.RequestType.GET; |
| 161 | + to = sendurlobject.TimeoutInSeconds; | |
| 152 | 162 | } |
| 153 | 163 | |
| 154 | - ToolsNS.HttpTools.ReturnInfoJSON returninfojson = HttpTools.GetReturninfoJSON(urltext, gp); | |
| 164 | + repeatsameurl: | |
| 165 | + ToolsNS.HttpTools.ReturnInfoJSON returninfojson = HttpTools.GetReturninfoJSON(urltext, to,gp); | |
| 155 | 166 | ColorConsole.WriteLine("ReturnValue:", ConsoleColor.Yellow, suffix: returninfojson.ReturnValue.ToString()); |
| 156 | 167 | ColorConsole.WriteLine("ReturnMessage:", ConsoleColor.Yellow, suffix: returninfojson.ReturnMessage); |
| 157 | 168 | ColorConsole.WriteLine(); |
| 169 | + ColorConsole.WriteLine("Repeat the same url?", ConsoleColor.Gray, suffix: "Yes/No/y/n"); | |
| 170 | + var repeat = ColorConsole.ReadLine().ToLower(); | |
| 171 | + if (repeat == "yes" || repeat == "y") goto repeatsameurl; | |
| 158 | 172 | |
| 159 | 173 | return o; |
| 160 | 174 | } |
| ... | ... | @@ -1287,6 +1301,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS |
| 1287 | 1301 | public Vrh.XmlProcessing.UrlElement UrlElement; |
| 1288 | 1302 | public bool ForcePOST = false; |
| 1289 | 1303 | public string Name; |
| 1304 | + public int TimeoutInSeconds = 0; | |
| 1290 | 1305 | public bool IsOK |
| 1291 | 1306 | { |
| 1292 | 1307 | get |
| ... | ... | @@ -1314,7 +1329,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS |
| 1314 | 1329 | public SendUrl(XElement sendurlxmlelement) |
| 1315 | 1330 | { |
| 1316 | 1331 | Name = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.Name), sendurlxmlelement, ""); |
| 1317 | - ForcePOST = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.ForcePost), sendurlxmlelement, XmlStructure.WebApplication.SendUrl.Attributes.ForcePost.Values.DEFAULT); | |
| 1332 | + ForcePOST = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.forcepost), sendurlxmlelement, XmlStructure.WebApplication.SendUrl.Attributes.forcepost.Values.DEFAULT); | |
| 1333 | + TimeoutInSeconds = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.timeoutinseconds), sendurlxmlelement, XmlStructure.WebApplication.SendUrl.Attributes.timeoutinseconds.Values.DEFAULT); | |
| 1318 | 1334 | Vrh.XmlProcessing.UrlElement xxxx = new Vrh.XmlProcessing.UrlElement(sendurlxmlelement); |
| 1319 | 1335 | UrlElement = new Vrh.XmlProcessing.UrlElement(); |
| 1320 | 1336 | UrlElement.Url = GetValue(sendurlxmlelement, ""); |
| ... | ... | @@ -1382,7 +1398,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS |
| 1382 | 1398 | public static class Attributes |
| 1383 | 1399 | { |
| 1384 | 1400 | public static class Name { } |
| 1385 | - public static class ForcePost { public static class Values { public static bool DEFAULT = false; } } | |
| 1401 | + public static class forcepost { public static class Values { public static bool DEFAULT = false; } } | |
| 1402 | + public static class timeoutinseconds { public static class Values { public static int DEFAULT = 0; } } | |
| 1386 | 1403 | public static class protocol { } |
| 1387 | 1404 | public static class hostname { } |
| 1388 | 1405 | public static class appname { } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Program.cs
| ... | ... | @@ -37,19 +37,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole |
| 37 | 37 | { |
| 38 | 38 | static void Main(string[] args) |
| 39 | 39 | { |
| 40 | - //Tests.T3(); | |
| 41 | - //return; | |
| 42 | - | |
| 43 | - var startassystemstr = CommandLine.GetCommandLineArgument(args, CLP.CMD_STARTASSYSTEM); | |
| 44 | - var startassystem = startassystemstr!=null && startassystemstr.ToLower() == "yes"; | |
| 45 | - | |
| 46 | - OtherTools.StartAsAdmin(); | |
| 47 | - OtherTools.StartAsSystem(silent:startassystem); | |
| 48 | - | |
| 49 | 40 | var forcedmodulekey = CommandLine.GetCommandLineArgument(args, CLP.CMD_MODULE); |
| 50 | 41 | var commandmode = !string.IsNullOrEmpty(forcedmodulekey); |
| 51 | 42 | var silentmode = commandmode && !string.IsNullOrEmpty(CommandLine.GetCommandLineArgument(args, CLP.CMD_SILENT, switchtype: true)); |
| 52 | 43 | ColorConsole.SilentMode=silentmode; |
| 44 | + | |
| 45 | + 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 | |
| 46 | + | |
| 47 | + var startassystemstr = CommandLine.GetCommandLineArgument(args, CLP.CMD_STARTASSYSTEM); | |
| 48 | + var startassystem = startassystemstr != null && startassystemstr.ToLower() == "yes"; | |
| 49 | + OtherTools.StartAsAdmin(); | |
| 50 | + OtherTools.StartAsSystem(!startassystem); | |
| 51 | + | |
| 53 | 52 | Menu.SetCommandMode(commandmode); |
| 54 | 53 | |
| 55 | 54 | var appconfigpath = CommandLine.GetCommandLineArgument(args, CLP.CMD_APPCONFIG); | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
| ... | ... | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; |
| 32 | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
| 33 | 33 | // by using the '*' as shown below: |
| 34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
| 35 | -[assembly: AssemblyVersion("1.16.1.0")] | |
| 36 | -[assembly: AssemblyFileVersion("1.16.1.0")] | |
| 35 | +[assembly: AssemblyVersion("1.16.3.0")] | |
| 36 | +[assembly: AssemblyFileVersion("1.16.3.0")] | ... | ... |