ServiceState.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Specialized;
  4. using System.Text;
  5. using System.ConsoleApp;
  6. using System.ConsoleApp.Commands;
  7. using Keln.Progress;
  8. namespace Keln.Commands.Service {
  9. public class ServiceState : BaseCommand {
  10. [ConsoleCommand("servicestate")]
  11. [ConsoleCommand("ss")]
  12. public static bool execute(string line, string cmd, NameValueCollection arguments) {
  13. switch(arguments["general"].ToLower().Trim()) {
  14. case "deviceemotion":
  15. case "de":
  16. writeProcessInfo("deviceemotion");
  17. break;
  18. case "speech":
  19. case "say":
  20. writeProcessInfo("speech");
  21. break;
  22. case "sozoti":
  23. case "sozi":
  24. writeProcessInfo("sozoti");
  25. break;
  26. case "sambale":
  27. case "learning":
  28. writeProcessInfo("sambale");
  29. break;
  30. case "intensi":
  31. case "intent":
  32. writeProcessInfo("intensi");
  33. break;
  34. case "gregorcalendus":
  35. case "gregor":
  36. case "calender":
  37. case "calendus":
  38. writeProcessInfo("gregor");
  39. break;
  40. case "":
  41. case "?":
  42. BeginWrite();
  43. WriteLine(new NameValueCollection() {
  44. { "deviceemotion", "" },
  45. { "speech", "" },
  46. { "sozoti", "" },
  47. { "sambale", "" },
  48. { "intensi", "" },
  49. { "gregorcalendus", "" }
  50. });
  51. EndWrite();
  52. break;
  53. }
  54. return false;
  55. }
  56. protected static void writeProcessInfo(ProcessInfo pi) {
  57. BeginWrite();
  58. WriteLine( new NameValueCollection() {
  59. { "Name", pi.ProcessName },
  60. { "ExitCode", pi.ExitCode.ToString() },
  61. { "State", pi.State.ToString() },
  62. { "StartTime", pi.StartTime.ToString("dddd, dd MMMM yyyy HH:mm:ss") },
  63. { "Total Processor Time", pi.TotalProcessorTime.ToString("dddd, dd MMMM yyyy HH:mm:ss") },
  64. { "User Processor Time", pi.UserProcessorTime.ToString("dddd, dd MMMM yyyy HH:mm:ss") },
  65. { "Peak Paged Memory Size", pi.PeakPagedMemorySize64.ToString("N") },
  66. { "Paged Memory Size", pi.PagedMemorySize64.ToString("N") },
  67. { "Paged System Memory Size", pi.PagedSystemMemorySize64.ToString("N") },
  68. { "V-Memory Size", pi.VirtualMemorySize64.ToString("N") },
  69. { "Peak V-Memory Size", pi.PeakVirtualMemorySize64.ToString("N") },
  70. { "Private Memory Size", pi.PrivateMemorySize64.ToString("N") }
  71. });
  72. EndWrite();
  73. }
  74. protected static void writeProcessInfo(string pi) {
  75. BeginWrite();
  76. if(Program.processes.ContainsKey(pi)) {
  77. writeProcessInfo(Program.processes[pi]);
  78. } else {
  79. WriteLine("Process not found: '" + pi + "'");
  80. WriteLine("Processes in list: ");
  81. foreach(string key in Program.processes.Keys) {
  82. Write("> ", ConsoleColor.Blue);
  83. WriteLine(key);
  84. }
  85. }
  86. EndWrite();
  87. }
  88. }
  89. }