Repository navigation
Expand file tree
/
Copy pathApiItem.cs
More file actions
134 lines (115 loc) · 3.95 KB
/
Copy pathApiItem.cs
File metadata and controls
134 lines (115 loc) · 3.95 KB
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
124
125
126
127
128
129
130
131
132
133
134
using Newtonsoft.Json;
using QuantBox.APIProvider.UI;
using XAPI.Callback;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using XAPI;
namespace QuantBox.APIProvider.Single
{
/// <summary>
/// 由用户选择Dll,然后加载,得到
///
/// </summary>
public class ApiItem : ICloneable
{
public const string CATEGORY_INFO = "Information";
public const string CATEGORY_Type = "Type";
internal BindingList<UserItem> LinkedUserList;
internal BindingList<ServerItem> LinkedServerList;
private string _dllPath;
[Editor(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string DllPath
{
get {
if (ProviderHost.autoMakeRelativePath)
{
return PathHelper.MakeRelativePath(_dllPath);
}
else
{
return PathHelper.MakeAbsolutePath(_dllPath);
}
}
set
{
string tmp_dllPath;
if (ProviderHost.autoMakeRelativePath)
{
tmp_dllPath = PathHelper.MakeRelativePath(value);
}
else
{
tmp_dllPath = PathHelper.MakeAbsolutePath(value);
}
// 不一样
bool diff = _dllPath != tmp_dllPath;
_dllPath = tmp_dllPath;
// 这个地方导致Json无法还原,所以先判断是否需要进行调用
if (LinkedUserList != null) {
if (Api == null || diff)
{
Api = new XApi(_dllPath);
}
if (Api != null) {
try
{
Type = Api.GetApiTypes;
Name = Api.GetApiName;
Version = Api.GetApiVersion;
// 取公共部分
UseType = UseType & Type;
}
catch(Exception ex)
{
Api = null;
Type = ApiType.Nono;
Name = ex.Message;
Version = "请使用depends检查一下是否缺少依赖";
UseType = ApiType.Nono;
}
}
}
}
}
[Browsable(false)]
internal XApi Api { get; set; }
[Category(CATEGORY_INFO)]
[ReadOnly(true)]
public string Name { get; set; }
[Category(CATEGORY_INFO)]
[ReadOnly(true)]
public string Version { get; set; }
[TypeConverter(typeof(UserItemConverter))]
public int User { get; set; }
[TypeConverter(typeof(ServerItemConverter))]
public int Server { get; set; }
private BindingList<UserItem> userList = new BindingList<UserItem>();
public BindingList<UserItem> UserList
{
get { return userList; }
set { userList = value; }
}
public string LogPrefix { get; set; }
[Category(CATEGORY_Type)]
[ReadOnly(true)]
public ApiType Type { get; set; }
[Category(CATEGORY_Type)]
[Editor(typeof(ApiTypeSelectorEditor), typeof(UITypeEditor))]
public ApiType UseType { get; set; }
public override string ToString()
{
return string.Format("LogPrefix={0};UseType={1};Name={2}", LogPrefix, UseType, Name);
}
public object Clone()
{
return this.MemberwiseClone();
}
}
}