chr
2026-04-08 53e656200368a983e563550e2cc1acbc6d86b729
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
using DynamicExpresso;
using OpenTap;
using OpenTap.Addin;
using System;
 
namespace AddInPlugin.Util
{
    public static class TestPlanRunAddIn
    {
        public static Interpreter GetInterpreter(this TestPlanRun run, ITestStep step)
        {
            var target = new Interpreter();
            target.SetVariable("this", MethodUtil.Instance);
            target.SetVariable("FileGlobals", run.FileGlobalsRuntime);
            target.SetVariable("StationGlobals", run.StationGlobalsRuntime);
            target.SetVariable("Parameters", run.ParametersRuntime);
            target.SetVariable("Step", step);
 
            target.SetVariable("Locals", run.LocalsRuntime);
 
            var context = step?.GetParent<ContextStep>();
            if (context != null)
            {
                target.SetVariable("Context", context.GetContextVariables());
            }
            return target;
        }
 
        public static dynamic Resolve(this TestPlanRun run, ITestStep step, string expr)
        {
            return Resolve(run, step, expr, typeof(void));
        }
 
        public static T Resolve<T>(this TestPlanRun run, ITestStep step, string expr)
        {
            return Resolve(run, step, expr, typeof(T));
        }
 
        public static dynamic Resolve(this TestPlanRun run, ITestStep step, string expr, Type targetType)
        {
            if (expr == null) return null;
            //if ((expr.StartsWith("\"") && !expr.EndsWith("\"")) || (expr.EndsWith("\"") && !expr.StartsWith("\"")))
            //{
            //    throw new Exception("String Val Format Error");
            //}
            var target = GetInterpreter(run, step);
            if (targetType == typeof(string))
            {
                return target.Eval(expr)?.ToString();
            }
            return target.Eval(expr, targetType);
        }
 
        public static void Update(this TestPlanRun run, ITestStep step, string expr)
        {
            var target = GetInterpreter(run, step);
            target.Eval(expr);
        }
 
        public static void Update(this TestPlanRun run, ITestStep step, string name, object value)
        {
            var target = GetInterpreter(run, step);
            var expr = $"{name} = __temp";
            target.Eval(expr, new Parameter("__temp", value));
        }
    }
}