TelcomModemImeiRecordProcedure.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. if (UpdateData.SystemID.ModelName.GetTelecomCnt() == 0)
  47. {
  48. LogWriter.Log("TelcomModem not supported, skip procedure");
  49. return true;
  50. }
  51. var imei = await GetTelcomModemImei();
  52. LogWriter.Report(LogEvent.TelcomModemImei, imei);
  53. return !string.IsNullOrEmpty(imei);
  54. }
  55. internal async Task<string> GetTelcomModemImei()
  56. {
  57. try
  58. {
  59. var result = await EvApi.GetTelcomModemImei();
  60. LogWriter.Log($"GetResponse:{result.Response}", isDebugLog: true);
  61. if (string.IsNullOrEmpty(result.Result))
  62. {
  63. Error = ErrorType.TelcomModemImeiNotFound;
  64. }
  65. return result.Result;
  66. }
  67. catch (Exception e)
  68. {
  69. Error = ErrorType.TelcomModemImeiNotFound;
  70. LogWriter.Log("Get TelcomModem IMEI Failed");
  71. LogWriter.Log(e.Message, isDebugLog: true);
  72. return "";
  73. }
  74. }
  75. }
  76. }