chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using AddInPlugin.Util;
using OpenTap;
using System;
using System.Linq;
using System.Threading;
using System.Xml.Serialization;
 
namespace AddInPlugin
{
    [Display("For", Group: "流程控制", Order: 0)]
    [AllowAnyChild]
    public class ForStep : TestStep, CanBreakBase, CanContinueBase
    {
        [Display("变量名")]
        public string VariableName { get; set; }
 
        [Display("起始值")]
        public int StartVal { get; set; } = 0;
 
        [Display("循环次数")]
        public int LoopNum { get; set; }
 
        [Display("步进")]
        public int StepVal { get; set; } = 1;
 
        [XmlIgnore]
        public bool? IsBreaked { get; set; }
 
        [XmlIgnore]
        public bool? IsContinued { get; set; }
 
        public ForStep() : base()
        {
        }
 
        public override void PrePlanRun()
        {
 
        }
 
        void RunChildrenInLoop()
        {
            var steps = EnabledChildSteps.ToArray();
            foreach (var _step in steps)
            {
                if (IsBreaked == true)
                {
                    break;
                }
                if (IsContinued == true)
                {
                    IsContinued = false;
                    continue;
                }
                var now = DateTime.Now;
                RunChildStep(_step);
            }
        }
 
        public override void Run()
        {
            try
            {
                PlanRun.Update(this, VariableName, StartVal);
                int num = 0;
                while (num < LoopNum && IsBreaked != true)
                {
                    RunChildrenInLoop();
                    string add = $"{VariableName} = {VariableName} + {StepVal}";
                    PlanRun.Update(this, add);
                    num++;
                }
                if (IsBreaked == true)
                {
                    Log.Info("Breaked");
                }
                UpgradeVerdict(Verdict.NotSet);
            }
            catch (Exception ex)
            {
                Log.Error("For Run error. {0}", ex);
                UpgradeVerdict(Verdict.Error);
            }
            finally
            {
 
            }
        }
 
        public override void PostPlanRun()
        {
            // 重置状态
            IsBreaked = null;
        }
    }
}