123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916 |
- using AwInitilizer.Model;
- using AwInitilizer.Procedure;
- using MesAdaptor;
- using Microsoft.Win32;
- using Newtonsoft.Json;
- using PhihongSystemID;
- 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 DispatcherTimer LogoutTimer;
- private KeyinListener keyinListener;
- private bool IsInitilizing = false;
- private PhihongSystemID.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;
- LogoutTimer = new DispatcherTimer();
- LogoutTimer.Interval = TimeSpan.FromMinutes(1);
- LogoutTimer.Tick += LogoutTimer_Tick;
- keyinListener = new KeyinListener(this);
- keyinListener.OnSystemIDReseived += KeyinListener_OnSystemIDReseived;
- Loaded += MainWindow_Loaded;
- //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>(),
- };
- LogoutTimer.Start();
- }
- private void KeyinListener_OnSystemIDReseived(object sender, SystemID systemID)
- {
- SystemIDScanReseived(systemID);
- }
- protected override void OnClosing(CancelEventArgs e)
- {
- base.OnClosing(e);
- try
- {
- LogoutTimer.Tick -= LogoutTimer_Tick;
- LogoutTimer.Stop();
- }
- catch
- {
- }
- Environment.Exit(0);
- }
- private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
- {
- ResetLogoutTimer();
- }
- private void SystemIDScanReseived(SystemID systemID)
- {
- ViewModel.IsInputCheckpassed = false;
- inputSystemID = systemID;
- var serialNumber = systemID.ToString();
- if (!SajetConnect.SajetTransSnCheck(ref serialNumber))
- {
- HintDialog.ShowMessage((string)Application.Current.FindResource("SnWoMisMatch"));
- return;
- }
- else
- {
- if (LoadConfigBySystemID(systemID))
- {
- UpdateStatus = UpdateStatus.Idel;
- }
- }
- }
- 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 (!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;
- MesErrorCode mesErrorCode = MesErrorCode.None;
- 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)
- {
- logPairs[procedureLog.Key] = procedureLog.Value;
- }
- if (!result)
- {
- mesErrorCode = Converter.MesErrorCodeMaper.GetMesErrorCode(procedureList[procedureIndex]);
- break;
- }
- }
- //report MES result
- ReportMESLog(logPairs);
- if (procedureIndex == procedureList.Count)
- {
- uxProgress.Value = 100;
- uxProgressRate.Content = "100%";
- UpdateStatus = UpdateStatus.Sucess;
- //report Success
- SajetConnect.SajetTranFinishSuccess();
- }
- else
- {
- UpdateStatus = UpdateStatus.Fail;
- //uxStatusBar.Content = $"Process {procedureList[procedureIndex].Name} Failed";
- uxStatusBar.Content = string.Format((string)Application.Current.FindResource("StatusBarFailed"), procedureList[procedureIndex].Name);
- //report Fail
- SajetConnect.SajetTranFinishFail(mesErrorCode);
- }
- stopTime = DateTime.Now;
- ViewModel.UpdateElpased = stopTime - startTime;
- CreateLogFile();
- CreateUploadCustomterLogFile();
- ViewModel.IsUdatIng = false;
- ViewModel.IsInputCheckpassed = false;
- }
- private void ReportMESLog(Dictionary<string, string> logPairs)
- {
- //report value
- var reportResult = SajetConnect.SajetTransReport(logPairs);
- }
- 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)
- {
- SajetConnect.SajetTransLog(msg);
- 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 = AppSettingConfig.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.FirmwareFileName)
- ).ToList();
- UpdateProcedure();
- ViewModel.IsInputCheckpassed = CheckInputData();
- }
- return true;
- }
- private void UpdateProcedure()
- {
- List<ProcedureBase> procedures = new List<ProcedureBase>();
- //init intilize procedure list
- procedures.Add(new Procedure.BasicInfoUpdate.BasicInfoUpdateProcedure());
- procedures.Add(new Procedure.FourGenModuleCheck.FourGenModuleCheckProcedure());
- procedures.Add(new Procedure.WifRssiCheck.WifRssiCheckProcedure());
- //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 Procedure.FirmwareBundleUpload.FirmwareBundleUploadProcedure());
- procedures.Add(new Procedure.FirmwareCheckVersion.FirmwareCheckVersionProcedure());
- procedures.Add(new Procedure.ButtonStatusCheck.ButtonStatusCheckPorcedure());
- procedures.Add(new Procedure.RestarttoIdel.RestarttoIdelProcedure());
- procedures.Add(new Procedure.VersionLog.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("DSWU601U0UD2PHD2111A001A0", out var systemID);
- //SystemIDScanReseived(systemID);
- if (signinDialog.DialogResult != true)
- {
- SajetConnect.SajetTransClose();
- 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";
- }
- }
- }
- }
|