Commit 71ae70b0fb82b309744825d19d633c4f635bc011
1 parent
56460ca9
v1.22.3.0
Showing
3 changed files
with
66 additions
and
14 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs
... | ... | @@ -305,13 +305,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
305 | 305 | ColorConsole.Write($", User:"); |
306 | 306 | ColorConsole.Write($"{ws.StartName}", ConsoleColor.White); |
307 | 307 | ColorConsole.WriteLine(); |
308 | - return ws.DisplayName+ws.Description; | |
308 | + return ws.DisplayName + ws.Description; | |
309 | 309 | } |
310 | 310 | else if (lineix == 1) |
311 | 311 | { |
312 | 312 | ColorConsole.Write($"Win service:"); |
313 | 313 | ColorConsole.Write($"{ws.Name}", ConsoleColor.Cyan); |
314 | - var fc2 = | |
314 | + var fc2 = | |
315 | 315 | ws.Status.Contains(nameof(WindowsService.WmiServiceStatus.OK)) ? ConsoleColor.Green |
316 | 316 | : ws.Status.Contains(nameof(WindowsService.WmiServiceStatus.Unknown)) ? ConsoleColor.Red |
317 | 317 | : ws.Status.Contains(nameof(WindowsService.WmiServiceStatus.Error)) ? ConsoleColor.Red |
... | ... | @@ -323,12 +323,15 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
323 | 323 | : ws.State.Contains(nameof(WindowsService.WmiServiceState.Unknown)) ? ConsoleColor.Red |
324 | 324 | : ws.State.Contains(nameof(WindowsService.WmiServiceState.Unregistered)) ? ConsoleColor.Red |
325 | 325 | : ConsoleColor.Yellow; |
326 | + var wsstatetext = | |
327 | + ws.State.Contains(nameof(WindowsService.WmiServiceState.Running)) ? ws.State | |
328 | + : ws.State.Contains(nameof(WindowsService.WmiServiceState.Unknown)) ? ws.State | |
329 | + : ws.State.Contains(nameof(WindowsService.WmiServiceState.Unregistered)) ? ws.State | |
330 | + : ws.State; | |
326 | 331 | ColorConsole.Write($" / "); |
327 | - ColorConsole.Write($"{ws.State}", fc0); | |
332 | + ColorConsole.Write($"{wsstatetext}", fc0); | |
328 | 333 | ColorConsole.Write($")"); |
329 | - ColorConsole.Write($", StartMode:"); | |
330 | - ColorConsole.Write($"{ws.StartMode}", ConsoleColor.Cyan); | |
331 | - if(ws.Status==nameof(WindowsService.WmiServiceStatus.OK) && ws.State != nameof(WindowsService.WmiServiceState.Stopped) && ws.State != nameof(WindowsService.WmiServiceState.Unknown)) | |
334 | + if (ws.Status == nameof(WindowsService.WmiServiceStatus.OK) && ws.State != nameof(WindowsService.WmiServiceState.Stopped) && ws.State != nameof(WindowsService.WmiServiceState.Unknown)) | |
332 | 335 | { |
333 | 336 | ColorConsole.Write($", Priority:"); |
334 | 337 | ColorConsole.Write($"{ws.PriorityClass}", ConsoleColor.White); |
... | ... | @@ -340,23 +343,55 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
340 | 343 | } |
341 | 344 | else if (lineix == 2) |
342 | 345 | { |
346 | + ColorConsole.Write($"Service StartMode:"); | |
347 | + ColorConsole.Write($"{ws.StartMode}", ConsoleColor.Cyan); | |
348 | + if (ws.State.Contains(nameof(WindowsService.WmiServiceState.Running))) | |
349 | + { | |
350 | + var uptime = (DateTime.Now - ws.ProcessLastStartTime); | |
351 | + var uptimetext = "" | |
352 | + + (Math.Truncate(uptime.TotalDays) == 0 ? "" : (string.Format("{0:%d}", uptime) + " days ")) | |
353 | + + (Math.Truncate(uptime.TotalHours) == 0 ? "" : (string.Format("{0:%h}", uptime) + " hours ")) | |
354 | + + (Math.Truncate(uptime.TotalMinutes) == 0 ? "" : (string.Format("{0:%m}", uptime) + " minutes")); | |
355 | + var uptimecolor = uptime.TotalHours > 72 ? ConsoleColor.Green : uptime.TotalHours > 24 ? ConsoleColor.White : uptime.TotalHours > 12 ? ConsoleColor.Yellow : ConsoleColor.Red; | |
356 | + ColorConsole.Write($", last started at:"); | |
357 | + ColorConsole.Write($"{ws.ProcessLastStartTime}", uptimecolor); | |
358 | + ColorConsole.Write($", up time since then:"); | |
359 | + ColorConsole.Write(uptimetext, uptimecolor); | |
360 | + } | |
361 | + else if (ws.ProcessLastExitTime.HasValue) | |
362 | + { | |
363 | + var downtime = (DateTime.Now - ws.ProcessLastExitTime.Value); | |
364 | + var downtimetext = "" | |
365 | + + (Math.Truncate(downtime.TotalDays) == 0 ? "" : (string.Format("{0:%d}", downtime) + " days ")) | |
366 | + + (Math.Truncate(downtime.TotalHours) == 0 ? "" : (string.Format("{0:%h}", downtime) + " hours ")) | |
367 | + + (Math.Truncate(downtime.TotalMinutes) == 0 ? "" : (string.Format("{0:%m}", downtime) + " minutes")); | |
368 | + ColorConsole.Write($", last exited at:"); | |
369 | + ColorConsole.Write($"{ws.ProcessLastExitTime}", ConsoleColor.Red); | |
370 | + ColorConsole.Write($", down time since then:"); | |
371 | + ColorConsole.Write(downtimetext, ConsoleColor.Red); | |
372 | + } | |
373 | + ColorConsole.WriteLine(); | |
374 | + return " "; | |
375 | + } | |
376 | + else if (lineix == 3) | |
377 | + { | |
343 | 378 | if (string.IsNullOrEmpty(ws.PathName)) { return ""; } |
344 | 379 | var cmdarray = CommandLineParser.SplitArgs(ws.PathName).ToArray(); |
345 | 380 | ColorConsole.Write($"Start command:"); |
346 | 381 | ColorConsole.WriteLine($"{cmdarray[0]}", ConsoleColor.White); |
347 | 382 | return ws.PathName; |
348 | 383 | } |
349 | - else if (lineix == 3) | |
384 | + else if (lineix == 4) | |
350 | 385 | { |
351 | 386 | if (string.IsNullOrEmpty(ws.PathName)) { return ""; } |
352 | 387 | var cmdparams = CommandLineParser.SplitArgs(ws.PathName).Skip(1).ToArray(); |
353 | - if (cmdparams.Length==0) { return ""; } | |
354 | - var cmdparamsstr = string.Join("][", cmdparams); | |
388 | + if (cmdparams.Length == 0) { return ""; } | |
389 | + var cmdparamsstr = "["+string.Join("][", cmdparams)+"]"; | |
355 | 390 | ColorConsole.Write($"Start arguments:"); |
356 | - ColorConsole.WriteLine($"[{cmdparamsstr}]", ConsoleColor.White); | |
391 | + ColorConsole.WriteLine(cmdparamsstr, ConsoleColor.White); | |
357 | 392 | return cmdparamsstr; |
358 | 393 | } |
359 | - else if (lineix == 4) | |
394 | + else if (lineix == 5) | |
360 | 395 | { |
361 | 396 | ColorConsole.WriteLine(); |
362 | 397 | return " "; |
... | ... | @@ -711,6 +746,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
711 | 746 | |
712 | 747 | } |
713 | 748 | #endregion WindowsServiceManagerCore class |
749 | + | |
714 | 750 | #region WindowsServiceManagerXmlProcessor class |
715 | 751 | public class WindowsServiceManagerXmlProcessor : XmlParser |
716 | 752 | { |
... | ... | @@ -786,6 +822,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
786 | 822 | public List<string> ThisDependsOn; |
787 | 823 | public List<string> ServicesDependOnThis; |
788 | 824 | public int ProcessId; |
825 | + public DateTime ProcessLastStartTime; | |
826 | + public DateTime? ProcessLastExitTime; | |
789 | 827 | public ServiceStartMode StartMode; |
790 | 828 | public string State; |
791 | 829 | public string Status; |
... | ... | @@ -907,7 +945,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
907 | 945 | if (this.State != nameof(WmiServiceState.Stopped)) |
908 | 946 | { |
909 | 947 | this.ProcessId = Convert.ToInt32(wmiService[nameof(WindowsService.ProcessId)]); |
910 | - this.PriorityClass = Process.GetProcessById(this.ProcessId).PriorityClass.ToString(); | |
948 | + var thisprocess = Process.GetProcessById(this.ProcessId); | |
949 | + this.ProcessLastStartTime = thisprocess.StartTime; | |
950 | + this.ProcessLastExitTime = thisprocess.HasExited?thisprocess.ExitTime:(DateTime?)null; | |
951 | + this.PriorityClass = thisprocess.PriorityClass.ToString(); | |
911 | 952 | } |
912 | 953 | } |
913 | 954 | } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Program.cs
... | ... | @@ -39,6 +39,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole |
39 | 39 | { |
40 | 40 | static void Main(string[] args) |
41 | 41 | { |
42 | + //TESTS.TimeSpanFormatTest(); | |
42 | 43 | //TESTS.MSMQTest(); |
43 | 44 | //return; |
44 | 45 | var forcedmodulekey = CommandLine.GetCommandLineArgument(args, CLP.CMD_MODULE); |
... | ... | @@ -94,6 +95,16 @@ namespace Vrh.Log4Pro.MaintenanceConsole |
94 | 95 | } |
95 | 96 | public static class TESTS |
96 | 97 | { |
98 | + public static void TimeSpanFormatTest() | |
99 | + { | |
100 | + var uptime = new TimeSpan(3, 4, 15, 33); | |
101 | + var uptimetext0 = uptime.ToString("%d") + " days "; | |
102 | + var uptimetext1 = string.Format("{0:%d}", uptime) + " days "; | |
103 | + var uptimetext2 = string.Format("{0:%h}", uptime) + " hours"; | |
104 | + var uptimetext3 = string.Format("{0:%m}", uptime) + " minutes"; | |
105 | + Console.WriteLine(uptimetext1+uptimetext2+ uptimetext3); | |
106 | + Console.ReadKey(); | |
107 | + } | |
97 | 108 | public static void GetWorkingProcesses() |
98 | 109 | { |
99 | 110 | using (ServerManager manager = new ServerManager()) | ... | ... |
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.22.2.0")] | |
36 | -[assembly: AssemblyFileVersion("1.22.2.0")] | |
35 | +[assembly: AssemblyVersion("1.22.3.0")] | |
36 | +[assembly: AssemblyFileVersion("1.22.3.0")] | ... | ... |