123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using AwInitilizer.Assist;
- using CsuWebApiLib;
- using PhihongEv.Lib;
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace AwInitilizer.Procedure.TelcomModemImeiRecord
- {
- public enum ErrorType
- {
- None,
- TelcomModemImeiNotFound,
- }
- public enum LogEvent
- {
- TelcomModemImei
- }
- public class TelcomModemImeiRecordProcedure : ProcedureBase
- {
- private readonly static Dictionary<LogEvent, string> ReportDict = new Dictionary<LogEvent, string>()
- {
- { LogEvent.TelcomModemImei, "TelcomModemImei" }
- };
-
- private readonly static Dictionary<LogEvent, string> LogDict = new Dictionary<LogEvent, string>()
- {
- { LogEvent.TelcomModemImei, "Get TelcomModem IMEI : {0}" }
- };
- public TelcomModemImeiRecordProcedure() : base()
- {
- Name = "TelcomModem IMEI record";
- Content = "read and upload TelcomModem IMEI";
- LogWriter = new ProcedureLog.LogWriter<TelcomModemImeiRecordProcedure, LogEvent>(this)
- {
- ReportPair = ReportDict,
- LogPair = LogDict
- };
- }
- public ErrorType Error { get; set; } = ErrorType.None;
- private ProcedureLog.LogWriter<TelcomModemImeiRecordProcedure, LogEvent> LogWriter;
- internal override async Task<bool> Run()
- {
- //if (!UpdateData.SystemID.ModelName.Network.Description.Contains("4G"))
- if (UpdateData.SystemID.ModelName.GetTelecomCnt() == 0)
- {
- LogWriter.Log("TelcomModem not supported, skip procedure");
- return true;
- }
- int retryCnt = 0;
- string imei;
- do
- {
- imei = await GetTelcomModemImei();
- LogWriter.Report(LogEvent.TelcomModemImei, imei);
- if (!string.IsNullOrEmpty(imei) || retryCnt > 5)
- {
- break;
- }
- retryCnt++;
- await Task.Delay(TimeSpan.FromMinutes(2));
- }
- while (true);
- return !string.IsNullOrEmpty(imei);
- }
- internal async Task<string> GetTelcomModemImei()
- {
- try
- {
- var result = await EvApi.GetTelcomModemImei();
- LogWriter.Log($"GetResponse:{result.Response}", isDebugLog: true);
- if (string.IsNullOrEmpty(result.Result))
- {
- Error = ErrorType.TelcomModemImeiNotFound;
- }
- return result.Result;
- }
- catch (Exception e)
- {
- Error = ErrorType.TelcomModemImeiNotFound;
- LogWriter.Log("Get TelcomModem IMEI Failed");
- LogWriter.Log(e.Message, isDebugLog: true);
- return "";
- }
- }
- }
- }
|