VersionLogProcedure.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using AwInitilizer.Assist;
  2. using CsuWebApiLib;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.Specialized;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace AwInitilizer.Procedure.VersionLog
  13. {
  14. public class VersionLogProcedure : ProcedureBase
  15. {
  16. private static readonly string SoftwareVersionHeader = "FullsetTestingVersion";
  17. private static readonly List<string> excludeHeaderList = new List<string>()
  18. {
  19. "FactoryConfiguration",
  20. "DDFactoryConfiguration0",
  21. "DDFactoryConfiguration1",
  22. "DDFactoryConfiguration2",
  23. "FactoryConfiguration",
  24. "AuxPower5V",
  25. "AuxPower12V",
  26. "AuxPower24V",
  27. "AuxPower48V",
  28. "CsuHwRev",
  29. "FirmwareUpdate",
  30. "FanModuleHwRev",
  31. "RelayModuleHwRev"
  32. };
  33. private static readonly Dictionary<string, string> MesReportNamePair = new Dictionary<string, string>
  34. {
  35. { "CsuBootLoadFwRev","CSU Bootloader" },
  36. { "CsuKernelFwRev","CSU Kernel" },
  37. { "CsuRootFsFwRev","CSU Rootfs" },
  38. { "CsuPrimFwRev","Primary MCU" },
  39. { "FanModuleFwRev","FAN Module" },
  40. { "LedModuleFwRev","LED Module" },
  41. { "LcmFwRev","LCM UI" },
  42. { "RelayModuleFwRev","Relay Module" },
  43. { "PsuPrimFwRev","PSU Primary" },
  44. { "PsuSecFwRev","PSU Secondary" },
  45. { "TelcomModemFwRev","Telecom Module" },
  46. { "AuxPwrFwRev","Aux Power" },
  47. { "FourthGenModuleVersion","Fourth Gen Module" },
  48. { "Connector1FwRev","Connector 1" },
  49. { "Connector2FwRev","Connector 2" },
  50. };
  51. public enum ErrorType
  52. {
  53. None,
  54. ReadVersionFail,
  55. }
  56. public enum LogEvent
  57. {
  58. }
  59. public ErrorType Error { get; set; } = ErrorType.None;
  60. private ProcedureLog.LogWriter<VersionLogProcedure, LogEvent> LogWriter;
  61. public VersionLogProcedure() : base()
  62. {
  63. Name = "Version Logger";
  64. Content = "Report version back to MES";
  65. LogWriter = new ProcedureLog.LogWriter<VersionLogProcedure, LogEvent>(this);
  66. }
  67. internal override async Task<bool> Run()
  68. {
  69. var versionPair = await GetVersion();
  70. if (versionPair == null)
  71. {
  72. Error = ErrorType.ReadVersionFail;
  73. return false;
  74. }
  75. foreach (var infoPair in versionPair)
  76. {
  77. if (string.IsNullOrEmpty(infoPair.Value))
  78. {
  79. continue;
  80. }
  81. if (!excludeHeaderList.Contains(infoPair.Key))
  82. {
  83. var mesKey = GetMesReportKey(infoPair.Key);
  84. LogWriter.Report(mesKey, infoPair.Value);
  85. //LogPair.Add(infoPair.Key, infoPair.Value);
  86. }
  87. }
  88. var assembly = System.Reflection.Assembly.GetExecutingAssembly();
  89. var version = assembly.GetName().Version.ToString();
  90. var gitVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion;
  91. var logVersion = string.Format("{0}-{1}", version, gitVersion);
  92. LogWriter.Report(SoftwareVersionHeader, logVersion);
  93. return true;
  94. }
  95. private string GetMesReportKey(string readVersion)
  96. {
  97. if(MesReportNamePair.ContainsKey(readVersion))
  98. {
  99. return MesReportNamePair[readVersion];
  100. }
  101. return readVersion;
  102. }
  103. internal async Task<Dictionary<string, string>> GetVersion()
  104. {
  105. try
  106. {
  107. var result = await EvApi.GetVersion();
  108. LogWriter.Log($"get version response:{result.Response}\n", isDebugLog: true);
  109. return result.Result;
  110. }
  111. catch (Exception e)
  112. {
  113. LogWriter.Log("Get Version Failed", isError: true);
  114. LogWriter.Log(e.Message, isDebugLog: true);
  115. //Logger.Print("Get Version Failed", isError: true);
  116. //Logger.Print(e.Message + "", isError: true);
  117. //InfoLog += "Get Version Failed\n";
  118. //InfoLog += e.Message;
  119. //InfoLog += "\n";
  120. return null;
  121. }
  122. }
  123. }
  124. }