Beispiel #1
0
 public static async Task ReportLogAsync(string message , RemoteLogOperation operation = RemoteLogOperation.Unknown, RemoteLogType type =  RemoteLogType.Info)
 {
     RemoteLogDetail remoteLogDetail = new RemoteLogDetail() {
         UserToken = WebService.UserComputerInfo.UserToken,
         UserMac = WebService.UserComputerInfo.GetComputerMac(),
         MachineName = WebService.UserComputerInfo.GetMachineName(),
         Version = UserComputerInfo.GetFreeHttpVersion(),
         Type = type.ToString(),
         Operation = operation.ToString(),
         Message = message
     };
     try
     {
         await httpClient.PostAsync(string.Format(@"{0}freehttp/UserLogReport", ConfigurationData.BaseUrl), new StringContent(MyJsonHelper.JsonDataContractJsonSerializer.ObjectToJsonStr(remoteLogDetail), Encoding.UTF8, "application/json"));
     }
     catch{ }
 }
Beispiel #2
0
        public void StartCheckUpgrade()
        {
            //Task checkUpgradeCheckUpgrade = new Task(CheckUpgrade);
            //checkUpgradeCheckUpgrade.Start();
            //checkUpgradeCheckUpgrade.ContinueWith((task) => { StartCheckUpgrade(); });

            Task <UpgradeServiceEventArgs> checkUpgradeTask = new Task <UpgradeServiceEventArgs>(() =>
            {
                //string tempResponse = myHttp.SendData(string.Format(@"{0}freehttp/UpdateCheck/v{1}?dotnetrelease={2}&{3}", ConfigurationData.BaseUrl, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),  UserComputerInfo.GetDotNetRelease(), UserComputerInfo.GetFreeHttpUser()));
                //string isNeedUpdata = FreeHttp.AutoTest.ParameterizationPick.ParameterPickHelper.PickStrParameter("\"isNeedUpdata\":", ",", tempResponse);
                //string isSilentUpgrade = FreeHttp.AutoTest.ParameterizationPick.ParameterPickHelper.PickStrParameter("\"isSilentUpgrade\":", ",", tempResponse);
                //string url = FreeHttp.AutoTest.ParameterizationPick.ParameterPickHelper.PickStrParameter("\"url\":\"", "\",", tempResponse);
                //string message = FreeHttp.AutoTest.ParameterizationPick.ParameterPickHelper.PickStrParameter("\"message\":\"", "\"", tempResponse);
                //if (string.IsNullOrEmpty(isNeedUpdata))
                //{
                //    return new UpgradeServiceEventArgs(false, null);
                //}
                //if (isNeedUpdata == "true")
                //{
                //    if (isSilentUpgrade == "true") SilentUpgradeUrl = url;
                //    return new UpgradeServiceEventArgs(true, url, null, isSilentUpgrade == "true");
                //}
                //if (!string.IsNullOrEmpty(message))
                //{
                //    return new UpgradeServiceEventArgs(true, null, message);
                //}
                //return null;

                try
                {
                    HttpResponseMessage response = httpClient.GetAsync(string.Format(@"{0}freehttp/UpdateCheck/v{1}?dotnetrelease={2}&{3}", ConfigurationData.BaseUrl, UserComputerInfo.GetFreeHttpVersion(), UserComputerInfo.GetDotNetRelease(), UserComputerInfo.GetFreeHttpUser())).GetAwaiter().GetResult();
                    if (response.IsSuccessStatusCode)
                    {
                        UpdateInfo updateInfo = MyJsonHelper.JsonDataContractJsonSerializer.JsonStringToObject <UpdateInfo>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult());
                        if (updateInfo == null)
                        {
                            _ = RemoteLogService.ReportLogAsync("JsonStringToObject fail that StartCheckUpgrade", RemoteLogService.RemoteLogOperation.CheckUpgrade, RemoteLogService.RemoteLogType.Error);
                            return(new UpgradeServiceEventArgs(false, null));
                        }
                        if (updateInfo.isNeedUpdata && updateInfo.isSilentUpgrade && !string.IsNullOrEmpty(updateInfo.url))
                        {
                            SilentUpgradeUrl = updateInfo.url;
                        }
                        return(new UpgradeServiceEventArgs(true, updateInfo));
                    }
                    else
                    {
                        _ = RemoteLogService.ReportLogAsync("StartCheckUpgrade get error response", RemoteLogService.RemoteLogOperation.CheckUpgrade, RemoteLogService.RemoteLogType.Error);
                        return(new UpgradeServiceEventArgs(false, null));
                    }
                }
                catch (Exception ex)
                {
                    _ = RemoteLogService.ReportLogAsync(ex.ToString(), RemoteLogService.RemoteLogOperation.Exception, RemoteLogService.RemoteLogType.Error);
                    return(new UpgradeServiceEventArgs(false, null));
                }
            });

            checkUpgradeTask.Start();
            checkUpgradeTask.ContinueWith((task) => { if (checkUpgradeTask.Result != null)
                                                      {
                                                          this.GetUpgradeMes(this, checkUpgradeTask.Result);
                                                      }
                                          });
        }