You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.8 KiB

  1. namespace JeepConsole
  2. {
  3. using OT.COM.SignalerMessage;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using Microsoft.Extensions.Configuration;
  8. using log4net;
  9. using System.Reflection;
  10. using log4net.Config;
  11. using System.Text;
  12. internal static class Program
  13. {
  14. private readonly static ILog _log = LogManager.GetLogger(typeof(Program));
  15. [STAThread]
  16. private static void Main()
  17. {
  18. LoadLog4netConfig();
  19. System.Threading.Mutex mu = new System.Threading.Mutex(true, string.Format("Global\\{0}", typeof(Program).GUID), out bool IsAppRunning);
  20. if (!IsAppRunning)
  21. {
  22. _log.Error("Leave Program without doing anything(Mutex)");
  23. mu.Dispose();
  24. Environment.Exit(1);
  25. }
  26. try
  27. {
  28. #if DEBUG
  29. string sSettingFile = "appsettings.Development.json";
  30. #else
  31. string sSettingFile = "appsettings.json" ;
  32. #endif
  33. string[] saCmd = System.Environment.GetCommandLineArgs();
  34. _log.Info(saCmd);
  35. StringBuilder sb = new StringBuilder("AP Start! ");
  36. int nIndex = 0;
  37. foreach (string sCmd in saCmd)
  38. {
  39. sb.Append($"Para[{nIndex++}] = '{sCmd}'");
  40. }
  41. _log.Info(sb.ToString());
  42. _log.Info($"Current directory: {Directory.GetCurrentDirectory()}");
  43. IConfigurationRoot configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
  44. .AddJsonFile(sSettingFile, optional: true, reloadOnChange: true).Build();
  45. IEnumerable<IConfigurationSection> ics = configuration.GetSection("appSettings").GetChildren();
  46. Dictionary<string, string> dicSetting = new Dictionary<string, string>();
  47. foreach (IConfigurationSection ic in ics)
  48. {
  49. dicSetting.Add(ic.Key, ic.Value);
  50. }
  51. if (saCmd.Length == 4 && saCmd[1] == "CMD")
  52. {
  53. string sURL = $"{dicSetting["apiserver"]}/Cmd";
  54. _log.Info($"URL = {sURL} ");
  55. SendWebApiRequest swr = new SendWebApiRequest();
  56. CRequestMessage crm = new CRequestMessage()
  57. {
  58. module = saCmd[2],
  59. method = saCmd[3]
  60. };
  61. CReqestPack crqp = new CReqestPack
  62. {
  63. Reqs = new List<CReqestItem>()
  64. {
  65. new CReqestItem(){ Req = crm }
  66. }
  67. };
  68. string sRes = swr.RunEncryptRequest(sURL, crqp, out string o_sRes);
  69. if (sRes != null)
  70. {
  71. _log.Error($"Result = {sRes}");
  72. }
  73. else
  74. {
  75. _log.Info($"Response = {o_sRes}");
  76. }
  77. }
  78. else
  79. {
  80. _log.Info($"NO SUPPORT COMMAND. Ex JeepConsole.exe CMD RPT.ReportSchedule Run");
  81. }
  82. }
  83. catch
  84. {
  85. string sMsg = $"{nameof(Main)} unknwon exception.";
  86. System.Diagnostics.Debug.Write(sMsg);
  87. _log.Error(sMsg);
  88. }
  89. _log.Info("AP Close! ");
  90. }
  91. private static void LoadLog4netConfig()
  92. {
  93. var repository = LogManager.CreateRepository(
  94. Assembly.GetEntryAssembly(),
  95. typeof(log4net.Repository.Hierarchy.Hierarchy)
  96. );
  97. XmlConfigurator.Configure(repository, new FileInfo("Log4Net.config"));
  98. }
  99. }
  100. }