using AddInPlugin.Entity;
|
using OpenTap;
|
using System.ComponentModel;
|
using System.IO;
|
using UtilLib;
|
|
namespace OpenTapEditor.Util
|
{
|
public class StepTypeLoader
|
{
|
public static List<ITypeData> Steps { get; private set; }
|
public static List<AdapterData> CustomSteps { get; private set; }
|
|
static StepTypeLoader()
|
{
|
LoadStep();
|
}
|
|
public static void LoadStep()
|
{
|
LoadAllStep(null);
|
LoadAdapterStep();
|
}
|
|
public static void LoadAllStep(TypeData parentType)
|
{
|
TypeData AsTypeData(ITypeData typedata)
|
{
|
do
|
{
|
if (typedata is TypeData td)
|
return td;
|
typedata = typedata?.BaseType;
|
} while (typedata != null);
|
return null;
|
}
|
|
var types = TypeData.GetDerivedTypes(TypeData.FromType(typeof(ITestStep)))
|
.Where(x => x.CanCreateInstance)
|
.Where(x => x.GetAttribute<BrowsableAttribute>()?.Browsable ?? true)
|
.Where(x => parentType == null ? true : TestStepList.AllowChild(AsTypeData(parentType).Type, AsTypeData(x)?.Type))
|
.OrderBy(x => x.GetAttribute<DisplayAttribute>()?.Order);
|
|
Steps = types.ToList();
|
}
|
|
public static void LoadAdapterStep()
|
{
|
var datas = new List<AdapterData>();
|
try
|
{
|
if (File.Exists(PathHelper.AdapterDataPath))
|
{
|
datas = XmlHelper.DeserializeFromXml<List<AdapterData>>(PathHelper.AdapterDataPath);
|
}
|
}
|
catch (Exception ex)
|
{
|
|
}
|
CustomSteps = datas;
|
}
|
}
|
}
|