Пример #1
0
        public async Task UploadRulesAsync <T1, T2>(List <T1> requestRules, List <T2> responseRules, ActuatorStaticDataCollection staticDataCollection = null) where T1 : IFiddlerHttpTamper where T2 : IFiddlerHttpTamper
        {
            MultipartFormDataContent multipartFormData = new MultipartFormDataContent();

            if (staticDataCollection != null)
            {
                multipartFormData.Add(new StringContent(MyJsonHelper.JsonDataContractJsonSerializer.ObjectToJsonStr(staticDataCollection)), "staticData");
            }
            if (requestRules != null)
            {
                foreach (var request in requestRules)
                {
                    multipartFormData.Add(new StringContent(MyJsonHelper.JsonDataContractJsonSerializer.ObjectToJsonStr(request)), "requestRule");
                }
            }
            if (responseRules != null)
            {
                foreach (var response in responseRules)
                {
                    multipartFormData.Add(new StringContent(MyJsonHelper.JsonDataContractJsonSerializer.ObjectToJsonStr(response)), "responseRule");
                }
            }

            try
            {
                await httpClient.PostAsync(string.Format(@"{0}freehttp/RuleDetails?ruleversion={1}&{2}", ConfigurationData.BaseUrl, UserComputerInfo.GetRuleVersion(), WebService.UserComputerInfo.GetFreeHttpUser()), multipartFormData);
            }
            catch (Exception ex)
            {
                await RemoteLogService.ReportLogAsync(ex.ToString(), RemoteLogService.RemoteLogOperation.RuleUpload, RemoteLogService.RemoteLogType.Error);
            }
            finally
            {
            }
        }
Пример #2
0
        public async Task <ShareRuleSummary> GetShareRuleSummaryAsync()
        {
            try
            {
                HttpResponseMessage responseMessage = await httpClient.GetAsync($"{ConfigurationData.BaseUrl}freehttp/sharerule/sharerulesummary?{_userInfoStr}");

                if (responseMessage.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    await RemoteLogService.ReportLogAsync("GetPersonalShareRulesAsync fail", RemoteLogService.RemoteLogOperation.ShareRule, RemoteLogService.RemoteLogType.Error);
                }
                else
                {
                    NowShareRuleSummary = MyJsonHelper.JsonDataContractJsonSerializer.JsonStringToObject <ShareRuleSummary>(await responseMessage.Content.ReadAsStringAsync());
                    if (NowShareRuleSummary == null)
                    {
                        await RemoteLogService.ReportLogAsync($"JsonStringToObject fail in【GetPersonalShareRulesAsync】 that {await responseMessage.Content.ReadAsStringAsync()}", RemoteLogService.RemoteLogOperation.ShareRule, RemoteLogService.RemoteLogType.Error);
                    }
                    else
                    {
                        return(NowShareRuleSummary);
                    }
                }
            }
            catch (Exception ex)
            {
                await RemoteLogService.ReportLogAsync(ex.ToString(), RemoteLogService.RemoteLogOperation.ShareRule, RemoteLogService.RemoteLogType.Error);
            }

            return(default);
Пример #3
0
        public static async Task <string> UploadRulesAsync <T1, T2>(List <T1> requestRules, List <T2> responseRules, ActuatorStaticDataCollection staticDataCollection = null, FiddlerRuleGroup ruleGroup = null, string executeUrl = null) where T1 : IFiddlerHttpTamper where T2 : IFiddlerHttpTamper
        {
            MultipartFormDataContent multipartFormData = new MultipartFormDataContent();

            if (staticDataCollection != null)
            {
                multipartFormData.Add(new StringContent(MyJsonHelper.JsonDataContractJsonSerializer.ObjectToJsonStr(staticDataCollection)), "staticData");
            }
            if (ruleGroup != null)
            {
                multipartFormData.Add(new StringContent(MyJsonHelper.JsonDataContractJsonSerializer.ObjectToJsonStr(ruleGroup)), "groupData");
            }
            if (requestRules != null)
            {
                foreach (var request in requestRules)
                {
                    multipartFormData.Add(new StringContent(MyJsonHelper.JsonDataContractJsonSerializer.ObjectToJsonStr(request)), "requestRule");
                }
            }
            if (responseRules != null)
            {
                foreach (var response in responseRules)
                {
                    multipartFormData.Add(new StringContent(MyJsonHelper.JsonDataContractJsonSerializer.ObjectToJsonStr(response)), "responseRule");
                }
            }

            try
            {
                HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(string.Format(executeUrl ?? _uploadRuleUrl, ConfigurationData.BaseUrl, UserComputerInfo.GetRuleVersion(), WebService.UserComputerInfo.GetFreeHttpUser()), multipartFormData);

                if (httpResponseMessage.IsSuccessStatusCode)
                {
                    return(await httpResponseMessage.Content.ReadAsStringAsync());
                }
            }
            catch (Exception ex)
            {
                await RemoteLogService.ReportLogAsync(ex.ToString(), RemoteLogService.RemoteLogOperation.RuleUpload, RemoteLogService.RemoteLogType.Error);
            }
            finally
            {
            }
            return(null);
        }
Пример #4
0
 private void StartSilentUpgrade()
 {
     if (System.Threading.Thread.CurrentThread.IsBackground)//大部分情况在async方法里使用这种方式也没有效果 1:不能确保线程执行到这里没有被主线程结束,2:对于async方法大部分情况执行这里的代码也是上一个线程,到await 才可能切换线程 (不过仍然可以通过同步的方式启动async方法)
     {
         System.Threading.Thread.CurrentThread.IsBackground = false;
     }
     //_ = await RemoteLogService.ReportLogAsync() 父进程可能先结束,不会管以异步启动的任务是否完成
     RemoteLogService.ReportLogAsync("start SilentUpgrade", RemoteLogService.RemoteLogOperation.SilentUpgrade, RemoteLogService.RemoteLogType.Info).Wait();
     //MyHelper.SelfUpgradeHelp.UpdateDllAsync("https://lulianqi.com/file/FreeHttpUpgradeFile").Wait();
     MyHelper.SelfUpgradeHelp.UpdateDllAsync(SilentUpgradeUrl).ContinueWith((result) =>
     {
         if (!string.IsNullOrEmpty(result.Result))
         {
             RemoteLogService.ReportLogAsync(result.Result, RemoteLogService.RemoteLogOperation.SilentUpgrade, RemoteLogService.RemoteLogType.Error).Wait();
         }
         else
         {
             RemoteLogService.ReportLogAsync("SilentUpgrade complete", RemoteLogService.RemoteLogOperation.SilentUpgrade, RemoteLogService.RemoteLogType.Info).Wait();
         }
     }).Wait();
 }
Пример #5
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);
                                                      }
                                          });
        }