MacAddressLogProcedure.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using AwInitilizer.Procedure.VersionLog;
  2. using AwInitilizer.ProcedureLog;
  3. using CsuWebApiLib;
  4. using Newtonsoft.Json;
  5. using PhihongEv.Lib;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace AwInitilizer.Procedure.MacAddressLog
  12. {
  13. public class MacAddressLogProcedure : ProcedureBase
  14. {
  15. public MacAddressLogProcedure() : base()
  16. {
  17. Name = "MacAddress Logger";
  18. Content = "Record MacAddress";
  19. LogWriter = new ProcedureLog.LogWriter<MacAddressLogProcedure, LogEvent>(this);
  20. }
  21. public enum ErrorType
  22. {
  23. None,
  24. ReadNetworkFail,
  25. }
  26. public enum LogEvent
  27. {
  28. }
  29. public ErrorType Error { get; set; } = ErrorType.None;
  30. private ProcedureLog.LogWriter<MacAddressLogProcedure, LogEvent> LogWriter;
  31. internal override async Task<bool> Run()
  32. {
  33. var getNetwork = await EvHttpClient.GetQueryActionOpt3String();
  34. if (getNetwork is null)
  35. {
  36. Error = ErrorType.ReadNetworkFail;
  37. return false;
  38. }
  39. LogWriter.Log(getNetwork.Msg, isDebugLog: true);
  40. if (!getNetwork.IsSuccess)
  41. {
  42. Error = ErrorType.ReadNetworkFail;
  43. return false;
  44. }
  45. var getNetworkPairs = JsonConvert.DeserializeObject<Dictionary<string, object>>(getNetwork.Msg);
  46. if (UpdateData.SystemID.ModelName.GetWiFiCnt() != 0)
  47. {
  48. string wifiMacAddressKey = "WifiMacAddress";
  49. string wifiMacAddress = GetValueFromGetNetwork(wifiMacAddressKey, getNetworkPairs);
  50. LogWriter.Report(wifiMacAddressKey, wifiMacAddress);
  51. }
  52. var ethernetCnt = UpdateData.SystemID.ModelName.GetEthernetCnt();
  53. for (int ethernetIndex = 0; ethernetIndex < ethernetCnt; ethernetIndex++)
  54. {
  55. string ethernetMacAddressKey = $"Eth{ethernetIndex}MacAddress";
  56. string wifiMacAddress = GetValueFromGetNetwork(ethernetMacAddressKey, getNetworkPairs);
  57. LogWriter.Report(ethernetMacAddressKey, wifiMacAddress);
  58. }
  59. return true;
  60. }
  61. private string GetValueFromGetNetwork(string key, Dictionary<string, object> getNetwork)
  62. {
  63. if (getNetwork is null ||
  64. !getNetwork.ContainsKey(key) ||
  65. !(getNetwork[key] is string val))
  66. {
  67. return null;
  68. }
  69. return val;
  70. }
  71. }
  72. }