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 } /// /// Interaction logic for MainWindow.xaml /// 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(), }; 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 logPairs = new Dictionary(); //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 logPairs) { //build header Dictionary valuePairs = new Dictionary(); 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(); 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(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 procedures = new List(); //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"; } } } }