TelcomModemImeiRecordProcedure.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. var imei = await GetTelcomModemImei();
  54. LogWriter.Report(LogEvent.TelcomModemImei, imei);
  55. return !string.IsNullOrEmpty(imei);
  56. }
  57. internal async Task<string> GetTelcomModemImei()
  58. {
  59. try
  60. {
  61. var result = await EvApi.GetTelcomModemImei();
  62. LogWriter.Log($"GetResponse:{result.Response}", isDebugLog: true);
  63. if (string.IsNullOrEmpty(result.Result))
  64. {
  65. Error = ErrorType.TelcomModemImeiNotFound;
  66. }
  67. return result.Result;
  68. }
  69. catch (Exception e)
  70. {
  71. Error = ErrorType.TelcomModemImeiNotFound;
  72. LogWriter.Log("Get TelcomModem IMEI Failed");
  73. LogWriter.Log(e.Message, isDebugLog: true);
  74. return "";
  75. }
  76. }
  77. }
  78. }