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)
|
{
|
|
}
|
}
|
}
|
}
|