浏览代码

another version

Robert 4 年之前
父节点
当前提交
4ab8c99529

+ 45 - 2
AwInitilizer/DLL/SajetConnect.cs

@@ -8,6 +8,48 @@ using System.Threading.Tasks;
 namespace AwInitilizer.DLL
 {
     public class SajetConnect
+    {
+        public static bool IsEmsEnabled { get; set; } = true;
+
+        public static bool SajetTransStart() => IsEmsEnabled ? SajetConnectDLL.SajetTransStart() : true;
+
+        public static bool SajetTransClose() => IsEmsEnabled ? SajetConnectDLL.SajetTransClose() : true;
+
+        public static bool SajetTransData(int command, IntPtr data, IntPtr length)
+            => IsEmsEnabled ? SajetConnectDLL.SajetTransData(command, data, length) : true;
+
+        public static bool SajetTransData_C(int command, out string data)
+        {
+            if(IsEmsEnabled)
+            {
+                return SajetConnectDLL.SajetTransData_C(command, out data);
+            }
+            else
+            {
+                data = "";
+                return true;
+            }
+        }
+
+        public static bool SajetTransSignIn(ref string data)
+            => IsEmsEnabled ? SajetConnectDLL.SajetTransSignIn(ref data) : true;
+
+        public static bool SajetTransWoCheck(ref string workOrder)
+            => IsEmsEnabled ? SajetConnectDLL.SajetTransWoCheck(ref workOrder) : true;
+        public static bool SajetTransSnCheck(ref string serialNumber)
+            => IsEmsEnabled ? SajetConnectDLL.SajetTransSnCheck(ref serialNumber) : true;
+        public static bool SajetTranFinish(bool Result)
+            => IsEmsEnabled ? SajetConnectDLL.SajetTranFinish(Result) : true;
+        public static string SajetTransRegisterHeader(string model, string header)
+            => IsEmsEnabled ? SajetConnectDLL.SajetTransRegisterHeader(model, header) : "";
+        public static bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
+            => IsEmsEnabled ? SajetConnectDLL.SajetTransReport(resultPair, codePair) : true;
+        public static bool SajetTransLog(string data, bool isError)
+            => IsEmsEnabled ? SajetConnectDLL.SajetTransLog(data, isError) : true;
+    }
+
+
+    public class SajetConnectDLL
     {
         public enum CMD
         {
@@ -250,10 +292,11 @@ namespace AwInitilizer.DLL
             var resultString1 = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(dataIntPtr);
 
             System.Runtime.InteropServices.Marshal.Copy(dataIntPtr, dataArray, 0, dataArrayLength);
-            System.Runtime.InteropServices.Marshal.Release(dataIntPtr);
+            //System.Runtime.InteropServices.Marshal.Release(dataIntPtr);
+            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(dataIntPtr);
 
             var readLength = System.Runtime.InteropServices.Marshal.ReadInt32(lengthIntPtr);
-            System.Runtime.InteropServices.Marshal.Release(lengthIntPtr);
+            //System.Runtime.InteropServices.Marshal.Release(lengthIntPtr);
 
             var resultString = Encoding.ASCII.GetString(dataArray);
 

+ 3 - 0
AwInitilizer/Initilizer.csproj

@@ -44,6 +44,9 @@
     <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
     </Reference>
+    <Reference Include="RestSharp, Version=106.11.7.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
+      <HintPath>..\packages\RestSharp.106.11.7\lib\net452\RestSharp.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Data" />
     <Reference Include="System.Web" />

+ 24 - 3
AwInitilizer/MainWindow.xaml.cs

@@ -101,7 +101,25 @@ namespace AwInitilizer
         {
             base.OnClosing(e);
 
-            LogoutTimer.Tick -= LogoutTimer_Tick;
+            try
+            {
+                CleanInputTimer.Tick -= CleanInputTimer_Tick;
+                CleanInputTimer.Stop();
+            }
+            catch
+            {
+
+            }
+
+            try
+            {
+                LogoutTimer.Tick -= LogoutTimer_Tick;
+                LogoutTimer.Stop();
+            }
+            catch
+            {
+
+            }
         }
 
         private void MainWindow_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
@@ -225,6 +243,9 @@ namespace AwInitilizer
             //;           test.ShowDialog();
 
             DisplayLogin();
+
+            var tester = new ProcedureBase();
+            _  = tester.ChekCsuBootCompelete();
         }
 
         private void StartInit_Click(object sender, RoutedEventArgs e)
@@ -584,7 +605,7 @@ namespace AwInitilizer
             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":"Failed");
+            fileWriter.WriteLine("Customer          :                               Test Result  : {0}", ViewModel.UpdateProcedure.Last().Status == ProcedureStatus.PASS? "PASS":"FAIL");
             fileWriter.WriteLine("");
 
             fileWriter.WriteLine(borderString);
@@ -906,7 +927,7 @@ namespace AwInitilizer
             }
             signinDialog.ShowDialog();
 
-            //SystemID.TryParse("DSWU601J0UW2PHD2045A004A0", out var systemID);
+            //SystemID.TryParse("DWWU301J0UD1PHD3000A001A0", out var systemID);
             //SystemIDScanReseived(systemID);
 
             if (signinDialog.DialogResult != true)

+ 22 - 14
AwInitilizer/Procedure/ButtonStatusCheckPorcedure.cs

@@ -31,22 +31,30 @@ namespace AwInitilizer.Procedure
             //wait restart
             Logger.Print("Waiting response..");
 
-            object response = false;
-            int pollingCnt = 0;
-            for (pollingCnt = 0; pollingCnt < 14; pollingCnt++)
-            {
-                response = await GetButtonStatus();
-                if (response!=null)
-                    break;
-                await Task.Delay(TimeSpan.FromSeconds(30));
-            }
+            //object response = false;
+            //int pollingCnt = 0;
+            //for (pollingCnt = 0; pollingCnt < 14; pollingCnt++)
+            //{
+            //    response = await GetButtonStatus();
+            //    if (response!=null)
+            //        break;
+            //    await Task.Delay(TimeSpan.FromSeconds(30));
+            //}
+
+            //ReportLog.Add(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<14", pollingCnt * 0.5));
 
-            ReportLog.Add(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<14", pollingCnt * 0.5));
+            ////timeout
+            //if (pollingCnt >= 14)
+            //{
+            //    Logger.Print("Wait EVSE timeout", isError: true);
+            //    return false;
+            //}
 
-            //timeout
-            if (pollingCnt >= 14)
+            var response = await GetButtonStatus();
+            if (response == null)
             {
-                Logger.Print("Wait EVSE timeout", isError: true);
+                ReportLog.Add("EVSE connect failed");
+                Logger.Print("EVSE connect failed", isError: true);
                 return false;
             }
 
@@ -151,7 +159,7 @@ namespace AwInitilizer.Procedure
                 ShowDialog(
                     string.Format((string)Application.Current.FindResource("BtnPressPressHint"), btnLang),
                     (string)Application.Current.FindResource("BtnPressHintTitle"),
-                    "", imgUrl, cancelAble: false); ;
+                    "", imgUrl, cancelAble: false);
 
                 //retry 20 times, 20*0.5 = 10 seconds 
                 int testCnt;

+ 89 - 5
AwInitilizer/Procedure/FirmwareBundleUploadProcedure.cs

@@ -31,7 +31,7 @@ namespace AwInitilizer.Procedure
             for (pollingCnt = 0; pollingCnt < 56; pollingCnt++)
             {
                 await Task.Delay(TimeSpan.FromSeconds(15));
-                response = await ChekCsuBootCompelete();
+                response = await CheckGetQuertyAction();
                 if (response)
                     break;
             }
@@ -50,13 +50,28 @@ namespace AwInitilizer.Procedure
             LogPair.Add($"UploadStartWait", "1");
 
             //upload firmware
+            //return await UploadWithHttpWebRequest();
+            bool result = false;
+            for(int tryCnt = 0; tryCnt< 10; tryCnt++)
+            {
+                result = await UploadWithRestSharp();
+                if (result)
+                    break;
+                else
+                    await Task.Delay(1000);
+            }
+            return result;
+        }
+
+        private async Task<bool> UploadWithHttpWebRequest()
+        {
             var updateList = UpdateData.FirmwareUpdateModels;
             //open all file stream
             //List<FileStream> firmwareFileStream = new List<FileStream>();
             List<UploadFile> UploadFileList = new List<UploadFile>();
             try
             {
-                for(int modelIndex = 0;modelIndex < updateList.Count;modelIndex++) //foreach (var model in updateList)
+                for (int modelIndex = 0; modelIndex < updateList.Count; modelIndex++) //foreach (var model in updateList)
                 {
                     var model = updateList[modelIndex];
                     var stream = File.Open(model.FirmwareFileName, FileMode.Open);
@@ -75,6 +90,8 @@ namespace AwInitilizer.Procedure
                 LogPair.Add($"FirmwareUpload", "0");
                 return false;
             }
+
+            Logger.Print("Uploading Firmware", isError: false);
             //upload
             try
             {
@@ -97,22 +114,89 @@ namespace AwInitilizer.Procedure
                 InfoLog += $"file upload failed";
                 LogPair.Add($"FirmwareUpload", "0");
             }
+            Logger.Print("Firmware Upload Complete", isError: false);
             LogPair.Add($"FirmwareUpload", "1");
             //release all
             foreach (var uploadFile in UploadFileList)
             {
-                if(uploadFile!=null && uploadFile.Stream!=null)
+                if (uploadFile != null && uploadFile.Stream != null)
                 {
-                    uploadFile.Stream.Close();
+                    Logger.Print($"Close {uploadFile.Filename}", isError: false);
+                    try
+                    {
+                        uploadFile.Stream.Close();
+                        uploadFile.Stream.Dispose();
+                    }
+                    catch
+                    {
+
+                    }
                 }
             }
             return true;
         }
 
+        private async Task<bool> UploadWithRestSharp()
+        {
+            var updateList = UpdateData.FirmwareUpdateModels;
+
+            var restClient = new RestSharp.RestClient($"https://{ServerIpAddress}");
+            var request = new RestSharp.RestRequest("upgrade_iso_action.php", RestSharp.Method.POST);
+            request.AlwaysMultipartFormData = true;
+            request.AddHeader("Content-Type", "multipart/form-data");
+
+            request.AddParameter("fw_tag", "iso");
+
+            foreach (var file in updateList)
+            {
+                request.AddFile("files[]", file.FirmwareFileName);
+            }
+
+            RestSharp.IRestResponse response = await restClient.ExecuteAsync(request);
+            if (response.IsSuccessful)
+            {
+                InfoLog += $"get firmware update response {response.Content}\n";
+                Logger.Print("Firmware Upload Complete", isError: false);
+                LogPair.Add($"FirmwareUpload", "1");
+                return true;
+            }
+            else
+            {
+                InfoLog += $"file upload failed";
+                InfoLog += response.ErrorMessage;
+                Logger.Print("Firmware Upload Failed", isError: true);
+                Logger.Print(response.ErrorMessage,isError:true);
+                LogPair.Add($"FirmwareUpload", "0");
+                return false;
+            }
+        }
+
+        public async Task<byte[]> UploadFilesRestSharp(string address, IEnumerable<string> files, NameValueCollection values)
+        {
+            var restClient = new RestSharp.RestClient(address);
+            var request = new RestSharp.RestRequest(RestSharp.Method.POST);
+            request.AlwaysMultipartFormData = true;
+            request.AddHeader("Content-Type", "multipart/form-data");
+
+            request.AddParameter("fw_tag", "iso");
+
+            foreach (var file in files)
+            {
+                request.AddFile("files[]", file);
+            }
+
+            RestSharp.IRestResponse response = restClient.Execute(request);
+            if(response.IsSuccessful)
+            {
+
+            }
+            return response.RawBytes;
+        }
+
         public async Task<byte[]> UploadFiles(string address, IEnumerable<UploadFile> files, NameValueCollection values)
         {
             var request = (HttpWebRequest)HttpWebRequest.Create(address);
-            //request.Timeout = 10 * 1000;
+            request.Timeout = 2 * 60 * 1000;
             request.KeepAlive = true;
             request.Accept = "*/*";
             request.Method = "POST";

+ 1 - 1
AwInitilizer/Procedure/FirmwareUploadProcedure.cs

@@ -113,7 +113,7 @@ namespace AwInitilizer.Procedure
         public async Task<byte[]> UploadFiles(string address, IEnumerable<UploadFile> files, NameValueCollection values)
         {
             var request = (HttpWebRequest)HttpWebRequest.Create(address);
-            //request.Timeout = 10 * 1000;
+            request.Timeout = 60 * 1000;
             request.KeepAlive = true;
             request.Accept = "*/*";
             request.Method = "POST";

+ 32 - 5
AwInitilizer/Procedure/ProcedureBase.cs

@@ -16,7 +16,7 @@ namespace AwInitilizer.Procedure
 {
     public enum ProcedureStatus
     {
-        Idle,Pass,Failed
+        IDLE,PASS,FAIL
     }
 
     public class ProcedureBase
@@ -45,7 +45,7 @@ namespace AwInitilizer.Procedure
             Logger.Print(Name + "Started");
             var result = await Run();
             Dispose();
-            Status = result ? ProcedureStatus.Pass : ProcedureStatus.Failed;
+            Status = result ? ProcedureStatus.PASS : ProcedureStatus.FAIL;
             Logger.Print(Name + "Complete");
             return result;
         }
@@ -57,7 +57,7 @@ namespace AwInitilizer.Procedure
 
         public void Reset()
         {
-            Status = ProcedureStatus.Idle;
+            Status = ProcedureStatus.IDLE;
             InfoLog = "";
         }
 
@@ -82,7 +82,7 @@ namespace AwInitilizer.Procedure
             return true;
         }
 
-        internal async Task<bool> ChekCsuBootCompelete()
+        public async Task<bool> ChekCsuBootCompelete()
         {
             //await Task.Delay(TimeSpan.FromMinutes(2));
             try
@@ -93,7 +93,7 @@ namespace AwInitilizer.Procedure
                     parameters.Add("opt", "2");
                     webClient.QueryString = parameters;
 
-                    using (Stream stream = await webClient.OpenReadTaskAsync($"https://{ServerIpAddress}/get_query_action.php"))
+                    using (Stream stream = webClient.OpenRead($"https://{ServerIpAddress}/get_query_action.php"))
                     // 使用 StreamReader 讀取 stream 內的字元
                     using (StreamReader reader = new StreamReader(stream))
                     {
@@ -130,6 +130,33 @@ namespace AwInitilizer.Procedure
             }
         }
 
+        public async Task<bool> CheckGetQuertyAction()
+        {
+            //await Task.Delay(TimeSpan.FromMinutes(2));
+            try
+            {
+                using (WebClientTimeout webClient = new WebClientTimeout())
+                {
+                    NameValueCollection parameters = new NameValueCollection();
+                    parameters.Add("opt", "2");
+                    webClient.QueryString = parameters;
+
+                    using (Stream stream = webClient.OpenRead($"https://{ServerIpAddress}/get_query_action.php"))
+                    // 使用 StreamReader 讀取 stream 內的字元
+                    using (StreamReader reader = new StreamReader(stream))
+                    {
+                        // 將 StreamReader 所讀到的字元轉為 string
+                        string request = reader.ReadToEnd();
+                        return true;
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                return false;
+            }
+        }
+
         private void Dispose()
         {
             if(serialPortocol!=null)

+ 1 - 1
AwInitilizer/Properties/AssemblyInfo.cs

@@ -53,4 +53,4 @@ using System.Windows;
 // [assembly: AssemblyVersion("1.0.0.0")]
 [assembly: AssemblyVersion("1.0.0.0")]
 [assembly: AssemblyFileVersion("1.0.0.0")]
-[assembly: AssemblyInformationalVersion("0a9455b")]
+[assembly: AssemblyInformationalVersion("2d3163d")]

+ 18 - 0
AwInitilizer/SigninDialog.xaml.cs

@@ -37,6 +37,19 @@ namespace AwInitilizer
 
             string id = uxIdBox.Text;
             string idBackup = id;
+
+            if (CheckIsMesDisableAccount())
+            {
+                DLL.SajetConnect.IsEmsEnabled = false;
+                DialogResult = true;
+                this.Close();
+                return;
+            }
+            else
+            {
+                DLL.SajetConnect.IsEmsEnabled = true;
+            }
+
             if (DLL.SajetConnect.SajetTransSignIn(ref id))
             {
                 if (string.IsNullOrEmpty(id) || id.StartsWith("NG"))
@@ -89,5 +102,10 @@ namespace AwInitilizer
             this.Close();
             return;
         }
+
+        private bool CheckIsMesDisableAccount()
+        {
+            return uxIdBox.Text == "Admin" && uxWorkOrderBox.Text == "Admin21896826";
+        }
     }
 }

+ 1 - 0
AwInitilizer/packages.config

@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net48" />
+  <package id="RestSharp" version="106.11.7" targetFramework="net48" />
 </packages>

+ 15 - 25
AwInitlizerInstaller/AwInitlizerInstaller.vdproj

@@ -34,30 +34,30 @@
         "Entry"
         {
         "MsmKey" = "8:_757BA0BD19C3D246BA621DB64DE2384D"
-        "OwnerKey" = "8:_DAA98DDE772D47D1A3A47A8277D61590"
+        "OwnerKey" = "8:_75A660E899044A1CAA106DA8B79AB179"
         "MsmSig" = "8:_UNDEFINED"
         }
         "Entry"
         {
-        "MsmKey" = "8:_78ADCBE0D92EA001CDA0D5ECE8D69FA4"
-        "OwnerKey" = "8:_DAA98DDE772D47D1A3A47A8277D61590"
+        "MsmKey" = "8:_75A660E899044A1CAA106DA8B79AB179"
+        "OwnerKey" = "8:_UNDEFINED"
         "MsmSig" = "8:_UNDEFINED"
         }
         "Entry"
         {
-        "MsmKey" = "8:_9190A32435564C0AA37658F1C98CE7D4"
-        "OwnerKey" = "8:_UNDEFINED"
+        "MsmKey" = "8:_78ADCBE0D92EA001CDA0D5ECE8D69FA4"
+        "OwnerKey" = "8:_75A660E899044A1CAA106DA8B79AB179"
         "MsmSig" = "8:_UNDEFINED"
         }
         "Entry"
         {
-        "MsmKey" = "8:_C9BC5A526B0440DCB63705909B3D2F7C"
+        "MsmKey" = "8:_9190A32435564C0AA37658F1C98CE7D4"
         "OwnerKey" = "8:_UNDEFINED"
         "MsmSig" = "8:_UNDEFINED"
         }
         "Entry"
         {
-        "MsmKey" = "8:_DAA98DDE772D47D1A3A47A8277D61590"
+        "MsmKey" = "8:_C9BC5A526B0440DCB63705909B3D2F7C"
         "OwnerKey" = "8:_UNDEFINED"
         "MsmSig" = "8:_UNDEFINED"
         }
@@ -70,19 +70,19 @@
         "Entry"
         {
         "MsmKey" = "8:_UNDEFINED"
-        "OwnerKey" = "8:_DAA98DDE772D47D1A3A47A8277D61590"
+        "OwnerKey" = "8:_757BA0BD19C3D246BA621DB64DE2384D"
         "MsmSig" = "8:_UNDEFINED"
         }
         "Entry"
         {
         "MsmKey" = "8:_UNDEFINED"
-        "OwnerKey" = "8:_78ADCBE0D92EA001CDA0D5ECE8D69FA4"
+        "OwnerKey" = "8:_75A660E899044A1CAA106DA8B79AB179"
         "MsmSig" = "8:_UNDEFINED"
         }
         "Entry"
         {
         "MsmKey" = "8:_UNDEFINED"
-        "OwnerKey" = "8:_757BA0BD19C3D246BA621DB64DE2384D"
+        "OwnerKey" = "8:_78ADCBE0D92EA001CDA0D5ECE8D69FA4"
         "MsmSig" = "8:_UNDEFINED"
         }
     }
@@ -178,23 +178,13 @@
         {
             "LaunchCondition"
             {
-                "{A06ECF26-33A3-4562-8140-9B0E340D4F24}:_10AB054652B047A293D239715AB90C86"
-                {
-                "Name" = "8:.NET Core"
-                "Message" = "8:[VSDNETCOREMSG]"
-                "AllowLaterVersions" = "11:FALSE"
-                "InstallUrl" = "8:https://dotnet.microsoft.com/download/dotnet-core/[NetCoreVerMajorDotMinor]"
-                "IsNETCore" = "11:TRUE"
-                "Architecture" = "2:0"
-                "Runtime" = "2:0"
-                }
-                "{A06ECF26-33A3-4562-8140-9B0E340D4F24}:_BD309AB8CB6A46AF977164CAF7BDF362"
+                "{A06ECF26-33A3-4562-8140-9B0E340D4F24}:_D0C82ED0E2FD42C1BFE77BB01DDECAF4"
                 {
                 "Name" = "8:.NET Framework"
                 "Message" = "8:[VSDNETMSG]"
                 "FrameworkVersion" = "8:.NETFramework,Version=v4.8"
                 "AllowLaterVersions" = "11:FALSE"
-                "InstallUrl" = "8:http://go.microsoft.com/fwlink/?LinkId=863262"
+                "InstallUrl" = "8:https://go.microsoft.com/fwlink/?linkid=2088631"
                 }
             }
         }
@@ -581,7 +571,7 @@
         }
         "Shortcut"
         {
-            "{970C0BB2-C7D0-45D7-ABFA-7EC378858BC0}:_5862128EB32848B1824C63B6264915EA"
+            "{970C0BB2-C7D0-45D7-ABFA-7EC378858BC0}:_E050C15677214F69A86F0DF50FBF9EFB"
             {
             "Name" = "8:Initilizer"
             "Arguments" = "8:"
@@ -589,7 +579,7 @@
             "ShowCmd" = "3:1"
             "IconIndex" = "3:0"
             "Transitive" = "11:FALSE"
-            "Target" = "8:_DAA98DDE772D47D1A3A47A8277D61590"
+            "Target" = "8:_75A660E899044A1CAA106DA8B79AB179"
             "Folder" = "8:_5D843E07890C4EEA8A900CE8C1AA8C33"
             "WorkingFolder" = "8:_DE11C1EA8CD74CA9820344EFA2A02676"
             "Icon" = "8:"
@@ -994,7 +984,7 @@
         }
         "ProjectOutput"
         {
-            "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_DAA98DDE772D47D1A3A47A8277D61590"
+            "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_75A660E899044A1CAA106DA8B79AB179"
             {
             "SourcePath" = "8:..\\AwInitilizer\\obj\\Debug\\AwInitilizer.exe"
             "TargetName" = "8:"

+ 1 - 1
Initilizer/AssemblyInfo.cs

@@ -11,5 +11,5 @@
 
 [assembly: AssemblyVersion("1.0.0.0")]
 [assembly: AssemblyFileVersion("1.0.0.0")]
-[assembly: AssemblyInformationalVersion("0a9455b")]
+[assembly: AssemblyInformationalVersion("2d3163d")]