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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using AddInPlugin;
using AddInPlugin.Entity;
using CommunityToolkit.Mvvm.ComponentModel;
using OpenTap;
using OpenTap.Addin.Util;
using OpenTapEditor.Provider;
using OpenTapEditor.Util;
using System.IO;
using System.Text;
using System.Windows;
using UtilLib;
 
namespace OpenTapEditor
{
    /// <summary>
    /// AdapterSetting.xaml 的交互逻辑
    /// </summary>
    [ObservableObject]
    public partial class AdapterSetting : Window
    {
        [ObservableProperty]
        private string stepName;
 
        [ObservableProperty]
        private string stepGroup;
 
        [ObservableProperty]
        private List<string> groupSource = new List<string>();
 
        private ITestStep step;
 
        private IList<AdapterData> datasource;
 
        public AdapterSetting()
        {
            DataContext = this;
            GroupSource = StepTypeLoader.CustomSteps.Where(a=>!string.IsNullOrEmpty(a.Group))
                .Select(a => a.Group).ToList();
            InitializeComponent();
        }
 
        public bool? Open(ITypeData type, IList<AdapterData> datasource)
        {
            try
            {
                this.datasource = datasource;
                var newStep = (ITestStep)type.CreateInstance();
                this.step = newStep;
                UpdateSource(this.step);
            }
            catch (Exception ex)
            {
 
            }
            return this.ShowDialog();
        }
 
        public bool? Open(ITestStep step, IList<AdapterData> datasource)
        {
            try
            {
                this.datasource = datasource;
                this.step = step;
                UpdateSource(this.step);
            }
            catch (Exception ex)
            {
 
            }
            return this.ShowDialog();
        }
 
        private void UpdateSource(object obj)
        {
            //var annotations = AnnotationCollection.Annotate(obj);
            view.Children.Clear();
            //view.Children.Add(DutControlProvider.GetControl(annotations));
            view.Children.Add(GridControlProvider.GetControl(obj));
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (datasource.FirstOrDefault(e => e.Name == this.StepName) != null)
                {
                    MessageBox.Show("名称不能重复");
                    return;
                }
 
                TapSerializer serializer = new TapSerializer();
                using (var str = new MemoryStream())
                {
                    serializer.Serialize(str, this.step);
                    var xmlCache = Encoding.UTF8.GetString(str.ToArray());
                    //XmlDocument doc = new XmlDocument();
                    //doc.LoadXml(xmlCache);
                    //XmlNode myNode = doc.DocumentElement;
                    var adapterData = new AdapterData();
 
                    adapterData.Name = this.StepName;
                    adapterData.Group = this.StepGroup;
                    adapterData.Xml = xmlCache;
                    adapterData.DataValue = new SerializableDictionary<string, string>();
                    if (this.step is VariableTestStep vts && vts.MethodVariables != null)
                    {
                        foreach (var mv in vts.MethodVariables)
                        {
                            adapterData.DataValue[mv.Name] = mv.ValueStr;
                        }
                    }
                    datasource.Add(adapterData);
                    //var step = serializer.DeserializeFromString(xmlCache, TypeData.FromType(typeof(ITestStep)));
                    XmlHelper.SerializeToXml(PathHelper.AdapterDataPath, datasource);
                }
            }
            catch (Exception ex)
            {
 
            }
        }
    }
}