TelcomModemImeiRecordProcedure.cs 2.6 KB

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