12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using AwInitilizer.Procedure.VersionLog;
- using AwInitilizer.ProcedureLog;
- using CsuWebApiLib;
- using Newtonsoft.Json;
- using PhihongEv.Lib;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace AwInitilizer.Procedure.MacAddressLog
- {
- public class MacAddressLogProcedure : ProcedureBase
- {
- public MacAddressLogProcedure() : base()
- {
- Name = "MacAddress Logger";
- Content = "Record MacAddress";
- LogWriter = new ProcedureLog.LogWriter<MacAddressLogProcedure, LogEvent>(this);
- }
- public enum ErrorType
- {
- None,
- ReadNetworkFail,
- }
- public enum LogEvent
- {
- }
- public ErrorType Error { get; set; } = ErrorType.None;
- private ProcedureLog.LogWriter<MacAddressLogProcedure, LogEvent> LogWriter;
- internal override async Task<bool> Run()
- {
- var getNetwork = await EvHttpClient.GetQueryActionOpt3String();
- if (getNetwork is null)
- {
- Error = ErrorType.ReadNetworkFail;
- return false;
- }
- LogWriter.Log(getNetwork.Msg, isDebugLog: true);
- if (!getNetwork.IsSuccess)
- {
- Error = ErrorType.ReadNetworkFail;
- return false;
- }
- var getNetworkPairs = JsonConvert.DeserializeObject<Dictionary<string, object>>(getNetwork.Msg);
- if (UpdateData.SystemID.ModelName.GetWiFiCnt() != 0)
- {
- string wifiMacAddressKey = "WifiMacAddress";
- string wifiMacAddress = GetValueFromGetNetwork(wifiMacAddressKey, getNetworkPairs);
- LogWriter.Report(wifiMacAddressKey, wifiMacAddress);
- }
- var ethernetCnt = UpdateData.SystemID.ModelName.GetEthernetCnt();
- for (int ethernetIndex = 0; ethernetIndex < ethernetCnt; ethernetIndex++)
- {
- string ethernetMacAddressKey = $"Eth{ethernetIndex}MacAddress";
- string wifiMacAddress = GetValueFromGetNetwork(ethernetMacAddressKey, getNetworkPairs);
- LogWriter.Report(ethernetMacAddressKey, wifiMacAddress);
- }
- return true;
- }
- private string GetValueFromGetNetwork(string key, Dictionary<string, object> getNetwork)
- {
- if (getNetwork is null ||
- !getNetwork.ContainsKey(key) ||
- !(getNetwork[key] is string val))
- {
- return null;
- }
- return val;
- }
- }
- }
|