shayne_lo 7 mesi fa
parent
commit
5a0f6b1276

+ 3 - 0
ApiTest/MainWindow.xaml

@@ -70,6 +70,9 @@
                 <Button Margin="5" Click="UploadFirmware_Click">
                     <TextBlock Text="UploadFirmware" />
                 </Button>
+                <Button Margin="5" Click="ReStart_Click">
+                    <TextBlock Text="ReStart" />
+                </Button>
             </StackPanel>
             <TextBox
                 x:Name="uxResult"

+ 12 - 4
ApiTest/MainWindow.xaml.cs

@@ -26,12 +26,12 @@ namespace ApiTest
         {
             InitializeComponent();
 
-            //uxIp.Text = "192.168.80.129";
-            //uxAccount.Text = "zerova";
-            //uxPass.Text = "t6sji4j83";
-            uxIp.Text = "192.168.100.1";
+            uxIp.Text = "192.168.80.129";
             uxAccount.Text = "zerova";
             uxPass.Text = "t6sji4j83";
+            //uxIp.Text = "192.168.100.1";
+            //uxAccount.Text = "zerova";
+            //uxPass.Text = "t6sji4j83";
         }
 
         private async void GetVersion_Click(object sender, RoutedEventArgs e)
@@ -141,5 +141,13 @@ namespace ApiTest
 
             EvHttpClient.ResetServerIpAddress(uxIp.Text);
         }
+
+        private async void ReStart_Click(object sender, RoutedEventArgs e)
+        {
+            TryUpdateConfig();
+
+            var result = await EvApi.Restart();
+            uxResult.Text = JsonConvert.SerializeObject(result.Result);
+        }
     }
 }

+ 1 - 1
ApiTest/Properties/AssemblyInfo.cs

@@ -53,4 +53,4 @@ using System.Windows;
 // [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyFileVersion("1.13.2.0")]
-[assembly: AssemblyInformationalVersion("2a6cbf5")]
+[assembly: AssemblyInformationalVersion("d874701")]

+ 1 - 1
AwInitilizer/MainWindow.xaml.cs

@@ -749,11 +749,11 @@ namespace AwInitilizer
 
             procedures.Add(new Procedure.BasicInfoUpdate.BasicInfoUpdateProcedure());
             procedures.Add(new Procedure.FirmwareBundleUpload.FirmwareBundleUploadProcedure());
+            procedures.Add(new Procedure.FirmwareCheckVersion.FirmwareCheckVersionProcedure());
             procedures.Add(new Procedure.FourGenModuleCheck.FourGenModuleCheckProcedure());
             procedures.Add(new Procedure.WifRssiCheck.WifRssiCheckProcedure());
             procedures.Add(new Procedure.TelcomModemImeiRecord.TelcomModemImeiRecordProcedure());
             //procedures.Add(new Procedure.FirmwareBundleUpload.FirmwareFtpUploadProcedure());
-            procedures.Add(new Procedure.FirmwareCheckVersion.FirmwareCheckVersionProcedure());
             procedures.Add(new Procedure.ButtonStatusCheck.ButtonStatusCheckPorcedure());
             procedures.Add(new Procedure.RestarttoIdle.RestarttoIdleProcedure());
             procedures.Add(new Procedure.VersionLog.VersionLogProcedure());

+ 24 - 0
AwInitilizer/Procedure/WifRssiCheckProcedure.cs

@@ -82,6 +82,30 @@ namespace AwInitilizer.Procedure.WifRssiCheck
             var ssid = AppSettingConfig.Instance.WifiApSSID;
             var pwd = AppSettingConfig.Instance.WifiApPassword;
             var cmdResult = await EvApi.SetWifiStationMode(ssid, pwd);
+            if (cmdResult == null || !cmdResult.Result)
+            {
+                return false;
+            }
+
+            var restartResult = await EvApi.Restart();
+            if (restartResult == null || !restartResult.Result)
+            {
+                return false;
+            }
+
+            int pollingCnt;
+            for (pollingCnt = 0; pollingCnt < 16; pollingCnt++)
+            {
+                await Task.Delay(TimeSpan.FromSeconds(15));
+                var response = await ChekCsuBootCompelete();
+                if (response)
+                    break;
+            }
+            if (pollingCnt == 16)
+            {
+                LogWriter.Log("Wait reboot complete time out");
+            }
+
             return cmdResult.Result;
         }
 

+ 1 - 1
AwInitilizer/Properties/AssemblyInfo.cs

@@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
 // [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyFileVersion("1.13.2.0")]
-[assembly: AssemblyInformationalVersion("2a6cbf5")]
+[assembly: AssemblyInformationalVersion("d874701")]

+ 1 - 1
ConfigEditor/Properties/AssemblyInfo.cs

@@ -53,4 +53,4 @@ using System.Windows;
 // [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyFileVersion("1.13.2.0")]
-[assembly: AssemblyInformationalVersion("2a6cbf5")]
+[assembly: AssemblyInformationalVersion("d874701")]

+ 19 - 0
CsuWebApiLib/EvApi.cs

@@ -587,6 +587,25 @@ namespace CsuWebApiLib
             };
         }
 
+        public static async Task<EvApiResult<bool>> Restart()
+        {
+            var result = await EvHttpClient.SetRestart();
+            if (!result.IsSuccess)
+            {
+                return new EvApiResult<bool>()
+                {
+                    Result = false,
+                    Response = result.Msg
+                };
+            }
+
+            return new EvApiResult<bool>()
+            {
+                Result = !string.IsNullOrEmpty(result.Msg),
+                Response = result.Msg,
+            };
+        }
+
         private static int? GetIntValue(string key, string source)
         {
             Regex rx = new Regex($"({key})\\\": ([0-9]*)");

+ 171 - 12
CsuWebApiLib/EvHttpClient.cs

@@ -194,6 +194,16 @@ namespace CsuWebApiLib
             return CallBase(api, param, customContents: new List<HttpContent>() { });
         }
 
+        internal static Task<EvHttpClientResult> SetRestart()
+        {
+            string api = "set_restart_action.php";
+            //Dictionary<string, string> param = new Dictionary<string, string>(){
+            //    {key,value},
+            //};
+
+            return CallBase(api, new Dictionary<string, string>(), customContents: new List<HttpContent>() { });
+        }
+
         private static async Task<EvHttpClientResult> CallBase(
             string api,
             Dictionary<string, string> param,
@@ -201,6 +211,11 @@ namespace CsuWebApiLib
             List<HttpContent> customContents = null,
             int timeOutSeconds = 5)
         {
+            //if (!await CallWithNewVersion(api, param, firmwareNames, customContents, timeOutSeconds))
+            //{
+            //    CallWithOldVersion();
+            //}
+
             try
             {
                 var url = string.Format("{0}/{1}", ServerUrl, api);
@@ -229,19 +244,163 @@ namespace CsuWebApiLib
                     {
                         formContent.Add(new ByteArrayContent(System.IO.File.ReadAllBytes(fileName)), "file[]");
                     }
+                }
+
+                if (customContents != null)
+                {
+                    foreach (var content in customContents)
+                    {
+                        formContent.Add(content);
+                    }
+                }
+
+                HttpResponseMessage postResult;
+                string result = null;
+
+
+                var handler = new HttpClientHandler();
+                handler.ClientCertificateOptions = ClientCertificateOption.Manual;
+                handler.ServerCertificateCustomValidationCallback =
+                    (httpRequestMessage, cert, cetChain, policyErrors) =>
+                    {
+                        return true;
+                    };
+
+                using (HttpClient evClient = new HttpClient(handler))
+                {
+                    evClient.Timeout = TimeSpan.FromSeconds(timeOutSeconds);
+
+                    try
+                    {
+                        EvHttpClientLogger.Instance.Log("post with new version");
+                        postResult = await evClient.PostAsync(url, formContent);
+                        EvHttpClientLogger.Instance.Log(postResult.StatusCode.ToString());
+
+                        //MessageBox.Show("Rest Result:" + postResult.StatusCode);
+                        if (postResult == null || !postResult.IsSuccessStatusCode)
+                        {
+                            throw new Exception("Post fail");
+                        }
+                        result = await postResult.Content.ReadAsStringAsync();
+                        EvHttpClientLogger.Instance.Log(result);
+
+                        //MessageBox.Show("Rest Result:" + result);
+
+                        if (result.Contains("File is uploaded, please wait a moment to upgrade"))
+                        {
+                            return new EvHttpClientResult()
+                            {
+                                IsSuccess = true,
+                                Msg = result,
+                            };
+                        }
+
+                        if (result.Contains("Charger restarted successfully"))
+                        {
+                            return new EvHttpClientResult()
+                            {
+                                IsSuccess = true,
+                                Msg = result,
+                            };
+                        }
+
+                        var check = JsonConvert.DeserializeObject<EvAuthMsg>(result);
+                        if (check != null &&
+                            check.result != null &&
+                            check.result.ToLower() == "fail")
+                        {
+                            return new EvHttpClientResult()
+                            {
+                                IsSuccess = false,
+                                Msg = result,
+                            };
+                        }
+
+                        return new EvHttpClientResult()
+                        {
+                            IsSuccess = true,
+                            Msg = result,
+                        };
+                    }
+                    catch (Exception e)
+                    {
+                        //post fail
+                        EvHttpClientLogger.Instance.Log(e.Message);
+                        EvHttpClientLogger.Instance.Log(e.StackTrace);
+                    }
+                }
+
+                using (WebClientTimeout webClient = new WebClientTimeout())
+                {
+                    EvHttpClientLogger.Instance.Log("post with old version");
+                    NameValueCollection parameters = new NameValueCollection();
+                    foreach (var inpam in param)
+                    {
+                        parameters.Add(inpam.Key, inpam.Value);
+                    }
+                    webClient.QueryString = parameters;
 
-                    //if (firmwareNames.Count == 1)
-                    //{
-                    //    var fileName = firmwareNames[0];
-                    //    formContent.Add(new ByteArrayContent(System.IO.File.ReadAllBytes(fileName)), "file");
-                    //}
-                    //else
-                    //{
-                    //    foreach (var fileName in firmwareNames)
-                    //    {
-                    //        formContent.Add(new ByteArrayContent(System.IO.File.ReadAllBytes(fileName)), "file[]");
-                    //    }
-                    //}
+                    using (Stream stream = webClient.OpenRead(url))
+                    // 使用 StreamReader 讀取 stream 內的字元
+                    using (StreamReader reader = new StreamReader(stream))
+                    {
+                        // 將 StreamReader 所讀到的字元轉為 string
+                        result = await reader.ReadToEndAsync();
+                    }
+                    EvHttpClientLogger.Instance.Log(result);
+
+                    var check = JsonConvert.DeserializeObject<EvAuthMsg>(result);
+                    if (check != null &&
+                        check.result != null &&
+                        check.result.ToLower() == "fail")
+                    {
+                        return new EvHttpClientResult()
+                        {
+                            IsSuccess = false,
+                            Msg = result,
+                        };
+                    }
+                }
+                return new EvHttpClientResult() { IsSuccess = true, Msg = result };
+
+            }
+            catch (Exception e)
+            {
+                return new EvHttpClientResult() { IsSuccess = false, Msg = e.Message }; ;
+            }
+        }
+
+        private static async Task<EvHttpClientResult> CallWithNewVersion(string api, Dictionary<string, string> param, List<string> firmwareNames, List<HttpContent> customContents, int timeOutSeconds)
+        {
+
+            try
+            {
+                var url = string.Format("{0}/{1}", ServerUrl, api);
+                EvHttpClientLogger.Instance.Log(url);
+
+                Dictionary<string, string> pams = new Dictionary<string, string>
+                {
+                    { "account", Account },
+                    { "password", Pass }
+                };
+                foreach (var pam in param)
+                {
+                    pams.Add(pam.Key, pam.Value);
+                }
+
+
+                var formContent = new MultipartFormDataContent();
+                foreach (var pam in pams)
+                {
+                    formContent.Add(new StringContent(pam.Value), pam.Key);
+                }
+
+                if (firmwareNames != null)
+                {
+                    foreach (var fileName in firmwareNames)
+                    {
+                        formContent.Add(new ByteArrayContent(System.IO.File.ReadAllBytes(fileName)), "file[]");
+                    }
                 }
 
                 if (customContents != null)

+ 1 - 1
CsuWebApiLib/Properties/AssemblyInfo.cs

@@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
 // [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyFileVersion("1.13.2.0")]
-[assembly: AssemblyInformationalVersion("2a6cbf5")]
+[assembly: AssemblyInformationalVersion("d874701")]

+ 1 - 1
Editor/Properties/AssemblyInfo.cs

@@ -53,4 +53,4 @@ using System.Windows;
 // [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyFileVersion("1.13.2.0")]
-[assembly: AssemblyInformationalVersion("2a6cbf5")]
+[assembly: AssemblyInformationalVersion("d874701")]

+ 1 - 1
InitializerModel/Properties/AssemblyInfo.cs

@@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
 // [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyFileVersion("1.13.2.0")]
-[assembly: AssemblyInformationalVersion("2a6cbf5")]
+[assembly: AssemblyInformationalVersion("d874701")]

+ 1 - 1
Initilizer/AssemblyInfo.cs

@@ -11,5 +11,5 @@
 
 [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyFileVersion("1.13.2.0")]
-[assembly: AssemblyInformationalVersion("2a6cbf5")]
+[assembly: AssemblyInformationalVersion("d874701")]
 

+ 1 - 1
MesAdaptor/Properties/AssemblyInfo.cs

@@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
 // [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyVersion("1.13.2.0")]
 [assembly: AssemblyFileVersion("1.13.2.0")]
-[assembly: AssemblyInformationalVersion("2a6cbf5")]
+[assembly: AssemblyInformationalVersion("d874701")]