12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022 |
- using AwInitilizer.Model;
- using AwInitilizer.Procedure;
- using Microsoft.Win32;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Threading;
- namespace AwInitilizer
- {
- enum UpdateStatus
- {
- Idel,
- Updating,
- Sucess,
- Fail
- }
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window, Interface.IIogger
- {
- private string barCode = string.Empty;
- private DispatcherTimer CleanInputTimer;
- private DispatcherTimer LogoutTimer;
- private bool IsInitilizing = false;
- private SystemID inputSystemID;
- private string csuFilePath;
- private string mcuFilePath;
- private MainViewModel ViewModel => DataContext as MainViewModel;
- private UpdateStatus _UpdateStatus = UpdateStatus.Idel;
- private UpdateStatus UpdateStatus
- {
- get => _UpdateStatus;
- set => SetUpdateStatus(value);
- }
- public MainWindow()
- {
- InitializeComponent();
- ServicePointManager.ServerCertificateValidationCallback +=
- (sender, cert, chain, sslPolicyErrors) => true;
- System.Net.ServicePointManager.Expect100Continue = false;
- CleanInputTimer = new DispatcherTimer();
- CleanInputTimer.Interval = TimeSpan.FromSeconds(1);
- CleanInputTimer.Tick += CleanInputTimer_Tick;
- LogoutTimer = new DispatcherTimer();
- LogoutTimer.Interval = TimeSpan.FromMinutes(1);
- LogoutTimer.Tick += LogoutTimer_Tick;
- Loaded += MainWindow_Loaded;
- PreviewKeyDown += MainWindow_PreviewKeyDown;
- PreviewKeyUp += MainWindow_PreviewKeyUp;
- //this.DataContext = new MainViewModel();
- this.DataContext = new MainViewModel() {
- //SystemID = systemID,
- //ModelName = "AWLU770001W1P0",
- //SettingModelName = "AWLU770001W1P0",
- //SerialNumber = "D2045A001A0",
- ////FourGenModuleVersion = "EC25AFFAR07A08M4G",
- //IsSimInsert = false,
- ////ICCID = "12345678901234567890",
- ////IMSI = "123456789012345",
- ////CSUVersion = "V1.01.01.0601.00",
- ////MCUVersion = "D0.52.40.1770.P0",
- //IsInputCheckpassed = true,
- //FirmwareUpdateModels = new List<FirmwareUpdateModel>(),
- };
- this.DataContextChanged += MainWindow_DataContextChanged;
- LogoutTimer.Start();
- }
- protected override void OnClosing(CancelEventArgs e)
- {
- base.OnClosing(e);
- try
- {
- CleanInputTimer.Tick -= CleanInputTimer_Tick;
- CleanInputTimer.Stop();
- }
- catch
- {
- }
- try
- {
- LogoutTimer.Tick -= LogoutTimer_Tick;
- LogoutTimer.Stop();
- }
- catch
- {
- }
- }
- private void MainWindow_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- }
- private void CleanInputTimer_Tick(object sender, EventArgs e)
- {
- CleanInputTimer.Stop();
- Console.WriteLine(barCode);
- if (SystemID.TryParse(barCode, out SystemID systemID))
- {
- SystemIDScanReseived(systemID);
- }
- barCode = string.Empty;
- }
- bool shiftPressed = false;
- private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
- {
- ResetLogoutTimer();
- if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
- {
- shiftPressed = true;
- return;
- }
- else if(e.Key == Key.Capital)
- {
- shiftPressed = !shiftPressed;
- return;
- }
- else if (e.Key == Key.Enter)
- {
- e.Handled = true;
- return;
- }
- else
- {
- if (e.Key >= Key.D0 && e.Key <= Key.D9)
- {
- // Number keys pressed so need to so special processing
- // also check if shift pressed
- var input = e.Key.ToString();
- input = input.Remove(0, 1);
- barCode += input;
- }
- else if (e.Key == Key.OemMinus)
- {
- barCode += "-";
- }
- else if (e.Key == Key.Return)
- {
- return;
- }
- else
- {
- var input = e.Key.ToString();
- if (shiftPressed)
- input = input.ToUpper();
- barCode += input;
- }
- }
- CleanInputTimer.Stop();
- CleanInputTimer.Start();
- }
- private void SystemIDScanReseived(SystemID systemID)
- {
- ViewModel.IsInputCheckpassed = false;
- inputSystemID = systemID;
- var serialNumber = systemID.ToString();
- if (!DLL.SajetConnect.SajetTransSnCheck(ref serialNumber))
- {
- HintDialog.ShowMessage((string)Application.Current.FindResource("SnWoMisMatch"));
- return;
- }
- else
- {
- if (LoadConfigBySystemID(systemID))
- {
- UpdateStatus = UpdateStatus.Idel;
- }
- }
- }
- private void MainWindow_PreviewKeyUp(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
- {
- shiftPressed = false;
- }
- }
- private void MainWindow_Loaded(object sender, RoutedEventArgs e)
- {
- Loaded -= MainWindow_Loaded;
- UpdateStatus = UpdateStatus.Idel;
- //init intilize procedure list
- //procedures.Add(new BasicInfoUpdateProcedure());
- //procedures.Add(new FourGenModuleCheckProcedure());
- //procedures.Add(new CsuFirmwareUpdateProcedure());
- //procedures.Add(new McuFirmwareUpdateProcedure());
- //procedures.Add(new ButtonStatusCheckPorcedure());
- //procedures.Add(new RestarttoIdelProcedure());
- //ViewModel.UpdateProcedure.Add(new VersionLogProcedure());
- //uxProcedureDataGrid.ItemsSource = procedures;\
- // var test = new HintDialog();
- // test.ImgPath = "pack://application:,,,/AwInitilizer;component/Image/Blue.png";
- // test.Message = "BLUE BOTTON"
- //; test.ShowDialog();
- DisplayLogin();
- var tester = new ProcedureBase();
- _ = tester.ChekCsuBootCompelete();
- }
- private void StartInit_Click(object sender, RoutedEventArgs e)
- {
- //check again
- ViewModel.IsInputCheckpassed = false;
- inputSystemID = ViewModel.SystemID;
- var serialNumber = inputSystemID.ToString();
- if (!DLL.SajetConnect.SajetTransSnCheck(ref serialNumber))
- {
- HintDialog.ShowMessage((string)Application.Current.FindResource("SnWoMisMatch"));
- return;
- }
- ViewModel.IsInputCheckpassed = CheckInputData();
- if (ViewModel.IsInputCheckpassed)
- {
- ViewModel.IsUdatIng = true;
- UpdateStatus = UpdateStatus.Updating;
- _ = UpdateTask();
- }
- }
- //private void CSUFileSelect_Click(object sender, RoutedEventArgs e)
- //{
- // OpenFileDialog openFileDialog = new OpenFileDialog();
- // if (openFileDialog.ShowDialog() == true){
- // ViewModel.CSUFileName = openFileDialog.SafeFileName;
- // ViewModel.CSUFilePath = openFileDialog.FileName;
- // }
- //}
- //private void MCUFileSelect_Click(object sender, RoutedEventArgs e)
- //{
- // OpenFileDialog openFileDialog = new OpenFileDialog();
- // if (openFileDialog.ShowDialog() == true)
- // {
- // ViewModel.MCUFileName = openFileDialog.SafeFileName;
- // ViewModel.MCUFilePath = openFileDialog.FileName;
- // }
- //}
- #region
- private bool CheckInputData()
- {
- bool isAvaliable = true;
- string alertMsg = string.Empty;
- UpdateData updateData;
- if (DataContext is MainViewModel viewModel)
- {
- updateData = viewModel;
- }
- else
- {
- throw new Exception("DataContext type error");
- }
- if (string.IsNullOrEmpty(updateData.ModelName))
- {
- //alertMsg += "Model Name is Required\n";
- alertMsg += (string)Application.Current.FindResource("ModelNameEmptyAlert") + "\n";
- isAvaliable = false;
- }
- else if (ViewModel.SettingModelName != updateData.ModelName)
- {
- //alertMsg += "Model Name setting is Mismathed\n";
- alertMsg += (string)Application.Current.FindResource("ModelNameMismatchAlert") + "\n";
- isAvaliable = false;
- }
- if (string.IsNullOrEmpty(updateData.SerialNumber))
- {
- //alertMsg += "Serial Number is Required\n";
- alertMsg += (string)Application.Current.FindResource("SerialNumberEmptyAlert") + "\n";
- isAvaliable = false;
- }
- var systemIDString = updateData.ModelName + updateData.SerialNumber;
- if (!string.IsNullOrEmpty(systemIDString))
- {
- if (SystemID.TryParse(systemIDString, out SystemID systemID))
- {
- updateData.SystemID = systemID;
- }
- else
- {
- //alertMsg += "Model Name format Error\n";
- alertMsg += (string)Application.Current.FindResource("ModelNameErrorAlert") + "\n";
- isAvaliable = false;
- }
- }
- if (updateData.SystemID != null &&
- updateData.SystemID.ModelName.Network.ToString().Contains("4G"))
- {
- if (string.IsNullOrEmpty(updateData.FourGenModuleVersion))
- {
- //alertMsg += "4G Module Version is Required\n";
- alertMsg += (string)Application.Current.FindResource("FourGenVersionEmptyAlert") + "\n";
- isAvaliable = false;
- }
- if (updateData.IsSimInsert)
- {
- if (string.IsNullOrEmpty(updateData.ICCID))
- {
- //alertMsg += "ICCID is Required when sim installed\n";
- alertMsg += (string)Application.Current.FindResource("IccidEmptyAlert") + "\n";
- isAvaliable = false;
- }
- if (string.IsNullOrEmpty(updateData.IMSI))
- {
- //alertMsg += "IMSI is Required when sim installed\n";
- alertMsg += (string)Application.Current.FindResource("ImsiEmptyAlert") + "\n";
- isAvaliable = false;
- }
- }
- }
- if (updateData.FirmwareUpdateModels == null)
- {
- //alertMsg += "FirmwareUpdateModels should be decalred\n";
- alertMsg += (string)Application.Current.FindResource("FirmwareListNullAlert") + "\n";
- isAvaliable = false;
- }
- else
- {
- foreach (var model in updateData.FirmwareUpdateModels)
- {
- if (string.IsNullOrEmpty(model.Module))
- {
- //alertMsg += "Firmware module name is Required\n";
- alertMsg += (string)Application.Current.FindResource("FirmwareNameEmptyAlert") + "\n";
- isAvaliable = false;
- }
- if (string.IsNullOrEmpty(model.Version))
- {
- //alertMsg += "Firmware module name is Required\n";
- alertMsg += (string)Application.Current.FindResource("FirmwareVersionEmptyAlert") + "\n";
- isAvaliable = false;
- }
- if (string.IsNullOrEmpty(model.FirmwareFileName))
- {
- //alertMsg += "Firmware file is Required\n";
- alertMsg += (string)Application.Current.FindResource("FirmwareFileEmptyAlert") + "\n";
- isAvaliable = false;
- }
- }
- }
- if (!isAvaliable)
- {
- HintDialog.ShowMessage(alertMsg);
- }
- return isAvaliable;
- }
- private async Task UpdateTask()
- {
- DateTime startTime, stopTime;
- startTime = DateTime.Now;
- ProcedureBase.UpdateData = ViewModel;
- ProcedureBase.Logger = this;
- Dictionary<string, string> logPairs = new Dictionary<string, string>();
- //logPairs.Add("ModelName", ViewModel.SystemID.ModelName.ToString());
- //logPairs.Add("SerialNumber", ViewModel.SystemID.SerialNumber);
- ViewModel.IsUdatIng = true;
- var procedureList = ViewModel.UpdateProcedure.Where(x => x.IsActivated).ToList();
- int procedureIndex;
- for (procedureIndex = 0; procedureIndex < procedureList.Count; procedureIndex++)
- {
- procedureList[procedureIndex].LogPair.Clear();
- procedureList[procedureIndex].Reset();
- }
- for (procedureIndex = 0; procedureIndex < procedureList.Count; procedureIndex++)
- {
- uxProgress.Value = (procedureIndex * 100 / procedureList.Count);
- uxProgressRate.Content = ((int)(procedureIndex * 100 / procedureList.Count)) + "%";
- uxStatusBar.Content = string.Format((string)Application.Current.FindResource("StatusBarUpdating"), procedureList[procedureIndex].Name);// $"Processing {procedureList[procedureIndex].Name}";
- var result = await procedureList[procedureIndex].DoWork();
- foreach(var procedureLog in procedureList[procedureIndex].LogPair)
- {
- if (logPairs.ContainsKey(procedureLog.Key))
- {
- logPairs[procedureLog.Key] = procedureLog.Value;
- }
- else
- {
- logPairs.Add(procedureLog.Key, procedureLog.Value);
- }
- }
- if (!result)
- break;
- }
- //report MES result
- ReportMESLog(logPairs);
- if (procedureIndex == procedureList.Count)
- {
- uxProgress.Value = 100;
- uxProgressRate.Content = "100%";
- UpdateStatus = UpdateStatus.Sucess;
- //report Success
- DLL.SajetConnect.SajetTranFinish(true);
- }
- else
- {
- UpdateStatus = UpdateStatus.Fail;
- //uxStatusBar.Content = $"Process {procedureList[procedureIndex].Name} Failed";
- uxStatusBar.Content = string.Format((string)Application.Current.FindResource("StatusBarFailed"), procedureList[procedureIndex].Name);
- }
- stopTime = DateTime.Now;
- ViewModel.UpdateElpased = stopTime - startTime;
- CreateLogFile();
- CreateUploadCustomterLogFile();
- ViewModel.IsUdatIng = false;
- }
- private void ReportMESLog(Dictionary<string, string> logPairs)
- {
- //build header
- Dictionary<string, int> valuePairs = new Dictionary<string, int>();
- foreach (var pair in logPairs)
- {
- if(int.TryParse(pair.Value,out int val))
- {
- valuePairs.Add(pair.Key,val);
- }
- else if(pair.Value.ToLower().Contains("fail"))
- {
- valuePairs.Add(pair.Key, 0);
- }
- else if (pair.Value.ToLower().Contains("success"))
- {
- valuePairs.Add(pair.Key, 1);
- }
- else
- {
- valuePairs.Add(string.Format("{0}:{1}", pair.Key, pair.Value),1);
- }
- }
- //register Header
- var codePair = new Dictionary<string, string>();
- var model = ViewModel.SystemID.ModelName.ToString();
- foreach(var key in valuePairs.Keys)
- {
- var code = DLL.SajetConnect.SajetTransRegisterHeader(model,key);
- if (string.IsNullOrEmpty(code))
- continue;
- codePair.Add(key, code);
- }
- //report value
- var reportResult = DLL.SajetConnect.SajetTransReport(valuePairs, codePair);
- }
- private void CreateLogFile()
- {
- var fileName = ViewModel.SystemID + ViewModel.SerialNumber + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".txt";
- var folderName = "Log";
- var filePath = Path.Combine(folderName, fileName);
- string content = "";
- if (File.Exists(fileName))
- {
- File.Delete(fileName);
- }
- if (!Directory.Exists("Log"))
- {
- Directory.CreateDirectory("Log");
- }
- FileStream fileStream = new FileStream(filePath, FileMode.Create);
- StreamWriter fileWriter = new StreamWriter(fileStream);
- fileWriter.WriteLine("Barcode");
- fileWriter.WriteLine($"Model name:{ ViewModel.ModelName } , Serial number: { ViewModel.SerialNumber }");
- fileWriter.WriteLine("==========================");
- fileWriter.WriteLine("Setting file");
- fileWriter.WriteLine($"Model name:{ ViewModel.SettingModelName}");
- fileWriter.WriteLine($"4G Module Version:{ ViewModel.FourGenModuleVersion}");
- fileWriter.WriteLine($"Is sim insert:{ ViewModel.IsSimInsert}");
- fileWriter.WriteLine($"sim ICCID:{ ViewModel.ICCID}");
- fileWriter.WriteLine($"sim IMSI:{ ViewModel.IMSI}");
- foreach (var model in ViewModel.FirmwareUpdateModels)
- {
- fileWriter.WriteLine($"{model.Module} version:{ model.Version}");
- }
- var procedureList = ViewModel.UpdateProcedure.ToList();
- for (int procedureIndex = 0; procedureIndex < procedureList.Count; procedureIndex++)
- {
- var procedure = procedureList[procedureIndex];
- fileWriter.WriteLine("==========================");
- fileWriter.WriteLine(procedure.Name);
- fileWriter.WriteLine("Is Activated:" + (procedure.IsActivated ? "Yes" : "No"));
- fileWriter.WriteLine("Status:" + procedure.Status.ToString());
- fileWriter.WriteLine(procedure.InfoLog);
- }
- fileWriter.WriteLine("==========================");
- fileWriter.Close();
- fileStream.Close();
- }
- private void CreateUploadCustomterLogFile()
- {
- var fileName = ViewModel.SystemID + ViewModel.SerialNumber +"_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
- var folderName = "CustomerLog";
- var filePath = Path.Combine(folderName, fileName);
- if (File.Exists(fileName))
- {
- File.Delete(fileName);
- }
- if (!Directory.Exists("CustomerLog"))
- {
- Directory.CreateDirectory("CustomerLog");
- }
- CreateCustomerLog(filePath);
- }
- private void CreateCustomerLog(string filePath)
- {
- FileStream fileStream = new FileStream(filePath, FileMode.Create);
- StreamWriter fileWriter = new StreamWriter(fileStream);
- string borderString = "================================================================================";
- //fileWriter.WriteLine(" Switch Mode Power Supply");
- fileWriter.WriteLine(" Button Test and Firmware update");
- fileWriter.WriteLine(" test report");
- fileWriter.WriteLine("");
- fileWriter.WriteLine("Test Program Name : {0,-30} ", "FirmwareUpdate");
- fileWriter.WriteLine("Serial No : {0,-30}System Time : {1}", ViewModel.SystemID.ToString(),DateTime.Now.ToString());
- fileWriter.WriteLine("Model Name : {0,-30}Elapsed Time : {1}", ViewModel.ModelName, ViewModel.UpdateElpased.ToString(@"hh\:mm\:ss"));
- fileWriter.WriteLine("LOT Number : Environment : ");
- fileWriter.WriteLine("Order Number : Inspector : {0}", ViewModel.UserID);
- fileWriter.WriteLine("Customer : Test Result : {0}", ViewModel.UpdateProcedure.Last().Status == ProcedureStatus.PASS? "PASS":"FAIL");
- fileWriter.WriteLine("");
- fileWriter.WriteLine(borderString);
- for (int procedureIndex = 0; procedureIndex < ViewModel.UpdateProcedure.Count; procedureIndex++)
- {
- var procedure = ViewModel.UpdateProcedure[procedureIndex];
- fileWriter.WriteLine("STEP.{0} : {1,-63}{2,6}", procedureIndex+1, procedure.Name, procedure.Status.ToString());
- foreach(var reportLog in procedure.ReportLog)
- {
- fileWriter.WriteLine(reportLog);
- }
- fileWriter.WriteLine(borderString);
- }
- fileWriter.Close();
- fileStream.Close();
- }
- public void Print(string msg, bool isError = false)
- {
- DLL.SajetConnect.SajetTransLog(msg, isError);
- Dispatcher.Invoke(() => {
- Span line = new Span();
- line.Inlines.Add(msg + "\n");
- Span.SetForeground(line, isError ? Brushes.Red : Brushes.Green);
- //uxTerminal.Inlines.Add(line);
- //uxTerminalScroller.ScrollToEnd();
- });
- Console.WriteLine(msg);
- }
- #endregion
- private bool LoadConfigBySystemID(SystemID systemID)
- {
- string settingRootFolder;
- try
- {
- var defaultPath = Properties.Settings.Default.FirmwareRoot;
- if(string.IsNullOrEmpty(defaultPath))
- {
- defaultPath = ".\\";
- }
- settingRootFolder = Path.GetFullPath(defaultPath);
- }
- catch
- {
- //HintDialog.ShowMessage("Firmware root path ERROR");
- HintDialog.ShowMessage((string)Application.Current.FindResource("LoadConfigRootFolderNotfoundAlert"));
- return false;
- }
- if (!Directory.Exists(settingRootFolder))
- {
- //HintDialog.ShowMessage("Firmware root path not exist");
- HintDialog.ShowMessage((string)Application.Current.FindResource("LoadConfigFolderNotfoundAlert"));
- return false;
- }
- string modelDirectoy = Path.Combine(settingRootFolder, systemID.ModelName.ToString());
- if (!Directory.Exists(modelDirectoy))
- {
- //HintDialog.ShowMessage("Model firmware root path not exist");
- HintDialog.ShowMessage((string)Application.Current.FindResource("LoadConfigModelFolderNotfoundAlert"));
- return false;
- }
- string modelSeettingFilePath = Path.Combine(modelDirectoy, systemID.ModelName.ToString() + ".ini");
- if (!File.Exists(modelSeettingFilePath))
- {
- //HintDialog.ShowMessage("Model firmware setting not exist");
- HintDialog.ShowMessage((string)Application.Current.FindResource("LoadConfigModelInitNotfoundAlert"));
- return false;
- }
- //check format
- var settingString = File.ReadAllText(modelSeettingFilePath);
- SettingConfig setting;
- try
- {
- setting = JsonConvert.DeserializeObject<SettingConfig>(settingString);
- }
- catch
- {
- //HintDialog.ShowMessage("Setting file ERROR");
- HintDialog.ShowMessage((string)Application.Current.FindResource("LoadConfigModelInitFormatErrorAlert"));
- return false;
- }
- if (CheckSettingConfig(System.IO.Path.GetDirectoryName(modelSeettingFilePath), ref setting))
- {
- ViewModel.SystemID = systemID;
- ViewModel.ModelName = systemID.ModelName.ToString();
- ViewModel.SerialNumber = systemID.SerialNumber;
- ViewModel.SettingModelName = setting.ModelName;
- ViewModel.SettingFileName = Path.GetFileName(modelSeettingFilePath);
- ViewModel.FourGenModuleVersion = setting.FourGenModuleVersion;
- ViewModel.IsSimInsert = setting.IsSimInsert;
- ViewModel.ICCID = setting.ICCID;
- ViewModel.IMSI = setting.IMSI;
- ViewModel.FirmwareUpdateModels = setting.FirmwareUpdateList
- .Where(x => !string.IsNullOrEmpty(x.Module) && !string.IsNullOrEmpty(x.Version) && !string.IsNullOrEmpty(x.FirmwareFileName)
- ).ToList();
- UpdateProcedure();
- ViewModel.IsInputCheckpassed = CheckInputData();
- }
- return true;
- }
- private void UpdateProcedure()
- {
- List<ProcedureBase> procedures = new List<ProcedureBase>();
- //init intilize procedure list
- procedures.Add(new ButtonStatusCheckPorcedure());
- procedures.Add(new BasicInfoUpdateProcedure());
- procedures.Add(new FourGenModuleCheckProcedure());
- //for (int firemwareIndex = 0; firemwareIndex < ViewModel.FirmwareUpdateModels.Count ; firemwareIndex++)
- //{
- // //procedures.Add(new FirmwareUpdateProcedure(ViewModel.FirmwareUpdateModels[firemwareIndex]));
- // procedures.Add(new FirmwareUploadProcedure(ViewModel.FirmwareUpdateModels[firemwareIndex]));
- //}
- procedures.Add(new FirmwareBundleUploadProcedure());
- procedures.Add(new FirmwareCheckVersionProcedure());
- procedures.Add(new RestarttoIdelProcedure());
- procedures.Add(new VersionLogProcedure());
- ViewModel.UpdateProcedure.Clear();
- foreach(var p in procedures)
- {
- ViewModel.UpdateProcedure.Add(p);
- }
- //uxProcedureDataGrid.ItemsSource = procedures;
- }
- private bool CheckSettingConfig(string folderPath, ref SettingConfig setting)
- {
- if (setting == null)
- return false;
- bool isCheckPassed = true;
- if (string.IsNullOrEmpty(setting.ModelName))
- {
- //HintDialog.ShowMessage("ModelName is requred");
- HintDialog.ShowMessage((string)Application.Current.FindResource("InitModelNameEmptyAlert"));
- isCheckPassed = false;
- }
- else if(!ModelName.TryParse(setting.ModelName,out _))
- {
- //HintDialog.ShowMessage("ModelName format Error");
- HintDialog.ShowMessage((string)Application.Current.FindResource("InitModelNameErrorAlert"));
- isCheckPassed = false;
- }
- if (setting.IsSimInsert)
- {
- if (string.IsNullOrEmpty(setting.ICCID))
- {
- //HintDialog.ShowMessage("ICCID should not empty while IsSimInsert is set");
- HintDialog.ShowMessage((string)Application.Current.FindResource("InitIccidEmptyAlert"));
- isCheckPassed = false;
- }
- if (string.IsNullOrEmpty(setting.IMSI))
- {
- //HintDialog.ShowMessage("IMSI should not empty while IsSimInsert is set");
- HintDialog.ShowMessage((string)Application.Current.FindResource("InitImsiEmptyAlert"));
- isCheckPassed = false;
- }
- }
- if(setting.FirmwareUpdateList!=null)
- {
- for (int firmwareIndex = 0; firmwareIndex < setting.FirmwareUpdateList.Count; firmwareIndex++)
- {
- var model = setting.FirmwareUpdateList[firmwareIndex];
- bool isVersionVaild = !string.IsNullOrEmpty(model.Version);
- bool isFileNameVaild = !string.IsNullOrEmpty(model.FirmwareFileName);
- bool isNoduleNameVaild = !string.IsNullOrEmpty(model.Module);
- if(!isNoduleNameVaild)
- {
- //HintDialog.ShowMessage("Firmware module name should not empty");
- HintDialog.ShowMessage((string)Application.Current.FindResource("InitFirmwareNameEmptyAlert"));
- isCheckPassed = false;
- }
- if (isVersionVaild || isFileNameVaild)
- {
- if (!isVersionVaild)
- {
- //HintDialog.ShowMessage($"Version should not empty while {model.Module} firmware is set");
- HintDialog.ShowMessage(string.Format((string)Application.Current.FindResource("InitFirmwareVersionEmptyAlert"),model.Module));
- isCheckPassed = false;
- }
- if (!isFileNameVaild)
- {
- //HintDialog.ShowMessage($"File name should not empty while {model.Module} version is set");
- HintDialog.ShowMessage(string.Format((string)Application.Current.FindResource("InitFirmwareFileEmptyAlert"), model.Module));
- isCheckPassed = false;
- }
- if (isVersionVaild && isFileNameVaild)
- {
- var filePath = System.IO.Path.Combine(folderPath, model.FirmwareFileName);
- //check file exist
- if (!File.Exists(filePath))
- {
- //HintDialog.ShowMessage($"{model.Module} Firemware file is missing");
- HintDialog.ShowMessage(string.Format((string)Application.Current.FindResource("InitFirmwareFileMissingAlert"), model.Module));
- isCheckPassed = false;
- }
- else
- {
- try
- {
- using (var fs = File.OpenRead(filePath))
- {
- byte[] systemIDBytes = new byte[16];
- if (fs.Read(systemIDBytes, 0, 16) == 16)
- {
- if (systemIDBytes.ToList().Contains(0x00))
- {
- int endIndex = Array.FindIndex(systemIDBytes, (x) => { return x == 0x00; });
- //int endIndex = parameter.FindIndex((x) => { return x == 0x00; });
- if (endIndex != default && endIndex != -1)
- {
- systemIDBytes = systemIDBytes.Take(endIndex).ToArray();
- }
- }
- if (ModelName.TryParse(systemIDBytes, out var modelName))
- {
- if (modelName.ToString() != setting.ModelName)
- {
- //HintDialog.ShowMessage($"{model.Module} Firemware and ModelName is Mismatched");
- HintDialog.ShowMessage(string.Format((string)Application.Current.FindResource("InitFirmwareFileHeaderMismatchAlert"), model.Module));
- isCheckPassed = false;
- }
- }
- else
- {
- // HintDialog.ShowMessage($"{model.Module} Firemware header ERROR");
- HintDialog.ShowMessage(string.Format((string)Application.Current.FindResource("InitFirmwareFileHeaderFormatAlert"), model.Module));
- isCheckPassed = false;
- }
- }
- else
- {
- //HintDialog.ShowMessage($"{model.Module} Firemware header ERROR");
- HintDialog.ShowMessage(string.Format((string)Application.Current.FindResource("InitFirmwareFileHeaderFormatAlert"), model.Module));
- isCheckPassed = false;
- }
- //byte[] imgType = new byte[4];
- //if (fs.Read(imgType, 0, 4) == 4)
- //{
- // if (!imgType.SequenceEqual(new byte[] { 0x10, 0x00, 0x00, 0x04, }))
- // {
- // HintDialog.ShowMessage($"{model.Module} Firemware type ERROR");
- // isCheckPassed = false;
- // }
- //}
- //else
- //{
- // HintDialog.ShowMessage($"{model.Module} Firemware header ERROR");
- // isCheckPassed = false;
- //}
- }
- }
- catch
- {
- //HintDialog.ShowMessage($"{model.Module} Firemware header ERROR");
- HintDialog.ShowMessage(string.Format((string)Application.Current.FindResource("InitFirmwareFileHeaderFormatAlert"), model.Module));
- isCheckPassed = false;
- }
- model.FirmwareFileName = filePath;
- }
- }
- }
- }
- }
- return isCheckPassed;
- }
- private void ResetLogoutTimer()
- {
- if(LogoutTimer!=null)
- {
- logoutCheckCnt = 0;
- LogoutTimer.Stop();
- LogoutTimer.Start();
- }
- }
- private void DisplayLogin()
- {
- LogoutTimer?.Stop();
- ViewModel.UserID = "";
- ViewModel.WorkOrder = "";
- var signinDialog = new SigninDialog();
- try
- {
- signinDialog.Owner = this;
- }
- catch
- {
- }
- signinDialog.ShowDialog();
- this.Focus();
- //SystemID.TryParse("DWWU301J0UD1PHD3000A001A0", out var systemID);
- //SystemIDScanReseived(systemID);
- if (signinDialog.DialogResult != true)
- {
- App.Current.Shutdown();
- }
- else
- {
- ViewModel.UserID = signinDialog.UserId;
- ViewModel.WorkOrder = signinDialog.WorkOrder;
- LogoutTimer?.Start();
- }
- }
- private int logoutCheckCnt = 0;
- private void LogoutTimer_Tick(object sender, EventArgs e)
- {
- LogoutTimer.Stop();
- if (ViewModel.IsUdatIng)
- {
- logoutCheckCnt = 0;
- LogoutTimer.Start();
- Console.WriteLine("LogoutTimer_Tick reset");
- return;
- }
- else if (++logoutCheckCnt > 10)
- {
- logoutCheckCnt = 0;
- DisplayLogin();
- Console.WriteLine("LogoutTimer_Tick DisplayLogin");
- }
- else
- {
- LogoutTimer.Start();
- Console.WriteLine("LogoutTimer_Tick continue");
- }
- }
- private void Logout_Click(object sender, RoutedEventArgs e)
- {
- DisplayLogin();
- }
- private void WorkOrder_TextChanged(object sender, TextChangedEventArgs e)
- {
- //ViewModel.IsInputCheckpassed = false;
- }
- private void WorkOrder_KeyDown(object sender, KeyEventArgs e)
- {
- //ViewModel.IsInputCheckpassed = true;
- if (e.Key == Key.Enter && ViewModel.SystemID != null)
- {
- SystemIDScanReseived(ViewModel.SystemID);
- }
- }
- private void SetUpdateStatus(UpdateStatus status)
- {
- if(status == UpdateStatus.Idel)
- {
- uxStatusContainer.Background = new SolidColorBrush(Colors.White);
- uxStatus.Foreground = new SolidColorBrush(Colors.Black);
- uxStatus.Content = (string)Application.Current.FindResource("StatusIdel");//"Idel";
- uxStatusBar.Content = "";
- }
- else if (status == UpdateStatus.Updating)
- {
- uxStatusContainer.Background = new SolidColorBrush(Colors.SkyBlue);
- uxStatus.Foreground = new SolidColorBrush(Colors.Black);
- uxStatus.Content = (string)Application.Current.FindResource("StatusUpdating");//"Updating";
- }
- else if (status == UpdateStatus.Sucess)
- {
- uxStatusContainer.Background = new SolidColorBrush(Colors.Green);
- uxStatus.Foreground = new SolidColorBrush(Colors.White);
- uxStatus.Content = (string)Application.Current.FindResource("StatusSuccess");//"Success";
- uxStatusBar.Content = "";
- }
- else if (status == UpdateStatus.Fail)
- {
- uxStatusContainer.Background = new SolidColorBrush(Colors.Red);
- uxStatus.Foreground = new SolidColorBrush(Colors.White);
- uxStatus.Content = (string)Application.Current.FindResource("StatusFail");//"Fail";
- }
- }
- }
- }
|