예제 #1
0
        private RuleDetails GetRuleDetailsFromToken(string shareToken)
        {
            RuleDetails ruleDetails = null;

            try
            {
                System.Threading.Tasks.Task <RuleDetails> ruleTask = System.Threading.Tasks.Task.Run(new Func <RuleDetails>(() =>
                {
                    //return WebService.RemoteRuleService.GetRemoteRuleAsync(watermakTextBox_ruleToken.Text).GetAwaiter().GetResult();
                    return(shareRuleService.GetShareRuleDetailAsync(shareToken).GetAwaiter().GetResult());
                }));
                ruleDetails = ruleTask.GetAwaiter().GetResult();
                if (ruleDetails == null)
                {
                    MessageBox.Show("your rule token is not permitted", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                else if (ruleDetails.ModificHttpRuleCollection == null || ((ruleDetails.ModificHttpRuleCollection.RequestRuleList == null || ruleDetails.ModificHttpRuleCollection.RequestRuleList.Count == 0) && (ruleDetails.ModificHttpRuleCollection.ResponseRuleList == null || ruleDetails.ModificHttpRuleCollection.ResponseRuleList.Count == 0)))
                {
                    MessageBox.Show("can not find any rule in your storage spaces", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    ruleDetails = null;
                }
            }
            catch (Exception ex)
            {
                _           = RemoteLogService.ReportLogAsync(ex.ToString(), RemoteLogService.RemoteLogOperation.RemoteRule, RemoteLogService.RemoteLogType.Error);
                ruleDetails = null;
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(ruleDetails);
        }
예제 #2
0
 private void bt_getRule_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(watermakTextBox_ruleToken.Text))
         {
             MessageBox.Show("just input your rule token", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
             return;
         }
         ClearRemoteRule();
         System.Threading.Tasks.Task <RuleDetails> ruleTask = System.Threading.Tasks.Task.Run(new Func <RuleDetails>(() =>
         {
             //6077f8fa617545cb9fbf12b1c874f7ee
             return(WebService.RemoteRuleService.GetRemoteRuleAsync(watermakTextBox_ruleToken.Text).GetAwaiter().GetResult());
         }));
         RuleDetails ruleDetails = ruleTask.GetAwaiter().GetResult();
         if (ruleDetails == null)
         {
             MessageBox.Show("your rule token is not permitted", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
             return;
         }
         if (ruleDetails.ModificHttpRuleCollection == null || ((ruleDetails.ModificHttpRuleCollection.RequestRuleList == null || ruleDetails.ModificHttpRuleCollection.RequestRuleList.Count == 0) && (ruleDetails.ModificHttpRuleCollection.ResponseRuleList == null || ruleDetails.ModificHttpRuleCollection.ResponseRuleList.Count == 0)))
         {
             MessageBox.Show("can not find any rule in your storage spaces", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
             return;
         }
         //this.Height = 560;
         foreach (var tempRule in ruleDetails.ModificHttpRuleCollection.RequestRuleList)
         {
             GetRemoteRuleWindowAddRuleToListView(lv_remote_requestRuleList, tempRule);
         }
         foreach (var tempRule in ruleDetails.ModificHttpRuleCollection.ResponseRuleList)
         {
             GetRemoteRuleWindowAddRuleToListView(lv_remote_responseRuleList, tempRule);
         }
         lb_info_2.Text = string.Format("Get RequestRule:{0} ; ResponseRule:{1} ; StaticData:{2}", ruleDetails.ModificHttpRuleCollection.RequestRuleList.Count, ruleDetails.ModificHttpRuleCollection.ResponseRuleList.Count, ruleDetails.StaticDataCollection?.Count ?? 0);
         nowRuleDetails = ruleDetails;
     }
     catch (Exception ex)
     {
         _ = RemoteLogService.ReportLogAsync(ex.ToString(), RemoteLogService.RemoteLogOperation.RemoteRule, RemoteLogService.RemoteLogType.Error);
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #3
0
 T IAwaitable <T> .GetResult()
 {
     return(_Task.GetAwaiter().GetResult());
 }