TelcomModemImeiRecordProcedure.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using AwInitilizer.Assist;
  2. using CsuWebApiLib;
  3. using PhihongEv.Lib;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.Specialized;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using System.Threading.Tasks;
  12. namespace AwInitilizer.Procedure.TelcomModemImeiRecord
  13. {
  14. public enum ErrorType
  15. {
  16. None,
  17. TelcomModemImeiNotFound,
  18. }
  19. public enum LogEvent
  20. {
  21. TelcomModemImei
  22. }
  23. public class TelcomModemImeiRecordProcedure : ProcedureBase
  24. {
  25. private readonly static Dictionary<LogEvent, string> ReportDict = new Dictionary<LogEvent, string>()
  26. {
  27. { LogEvent.TelcomModemImei, "TelcomModemImei" }
  28. };
  29. private readonly static Dictionary<LogEvent, string> LogDict = new Dictionary<LogEvent, string>()
  30. {
  31. { LogEvent.TelcomModemImei, "Get TelcomModem IMEI : {0}" }
  32. };
  33. public TelcomModemImeiRecordProcedure() : base()
  34. {
  35. Name = "TelcomModem IMEI record";
  36. Content = "read and upload TelcomModem IMEI";
  37. LogWriter = new ProcedureLog.LogWriter<TelcomModemImeiRecordProcedure, LogEvent>(this)
  38. {
  39. ReportPair = ReportDict,
  40. LogPair = LogDict
  41. };
  42. }
  43. public ErrorType Error { get; set; } = ErrorType.None;
  44. private ProcedureLog.LogWriter<TelcomModemImeiRecordProcedure, LogEvent> LogWriter;
  45. internal override async Task<bool> Run()
  46. {
  47. //if (!UpdateData.SystemID.ModelName.Network.Description.Contains("4G"))
  48. if (UpdateData.SystemID.ModelName.GetTelecomCnt() == 0)
  49. {
  50. LogWriter.Log("TelcomModem not supported, skip procedure");
  51. return true;
  52. }
  53. int retryCnt = 0;
  54. string imei;
  55. do
  56. {
  57. imei = await GetTelcomModemImei();
  58. LogWriter.Report(LogEvent.TelcomModemImei, imei);
  59. if (!string.IsNullOrEmpty(imei) || retryCnt > 5)
  60. {
  61. break;
  62. }
  63. retryCnt++;
  64. await Task.Delay(TimeSpan.FromMinutes(2));
  65. }
  66. while (true);
  67. return !string.IsNullOrEmpty(imei);
  68. }
  69. internal async Task<string> GetTelcomModemImei()
  70. {
  71. try
  72. {
  73. var result = await EvApi.GetTelcomModemImei();
  74. LogWriter.Log($"GetResponse:{result.Response}", isDebugLog: true);
  75. if (string.IsNullOrEmpty(result.Result))
  76. {
  77. Error = ErrorType.TelcomModemImeiNotFound;
  78. }
  79. return result.Result;
  80. }
  81. catch (Exception e)
  82. {
  83. Error = ErrorType.TelcomModemImeiNotFound;
  84. LogWriter.Log("Get TelcomModem IMEI Failed");
  85. LogWriter.Log(e.Message, isDebugLog: true);
  86. return "";
  87. }
  88. }
  89. }
  90. }