77using System . Linq ;
88using System . Reflection ;
99using System . Text ;
10+ using System . Text . Json ;
1011using System . Windows . Forms ;
1112using System . Xml . Linq ;
1213
@@ -17,38 +18,46 @@ public class QpClientTypeManager
1718 public static QpClientTypeManager Instance { get ; } = new QpClientTypeManager ( ) ;
1819 private Dictionary < string , QpClientTypeInfo > dict = null ;
1920
20- private void register ( Type clientType , Func < QpClientOptions > createOptionsInstanceFunc , Func < ClientOptionsControl > createOptionsControlFunc )
21+ private void register ( QpClientTypeInfo qpClientTypeInfo )
2122 {
22- var clientTypeFullName = clientType . FullName ;
23- var name = clientType . GetCustomAttribute < DisplayNameAttribute > ( ) ? . DisplayName ?? clientTypeFullName ;
24- dict [ clientTypeFullName ] = new QpClientTypeInfo ( )
25- {
26- Name = name ,
27- ClientType = clientType ,
28- CreateOptionsInstanceFunc = createOptionsInstanceFunc ,
29- CreateOptionsControlFunc = createOptionsControlFunc
30- } ;
23+ dict [ qpClientTypeInfo . TypeName ] = qpClientTypeInfo ;
3124 }
3225
3326 public void Init ( )
3427 {
3528 dict = new Dictionary < string , QpClientTypeInfo > ( ) ;
36- register (
37- typeof ( Quick . Protocol . Tcp . QpTcpClient ) ,
38- ( ) => new Quick . Protocol . Tcp . QpTcpClientOptions ( ) ,
39- ( ) => new Controls . ClientOptions . TcpClientOptionsControl ( ) ) ;
40- register (
41- typeof ( Quick . Protocol . Pipeline . QpPipelineClient ) ,
42- ( ) => new Quick . Protocol . Pipeline . QpPipelineClientOptions ( ) ,
43- ( ) => new Controls . ClientOptions . PipelineClientOptionsControl ( ) ) ;
44- register (
45- typeof ( Quick . Protocol . SerialPort . QpSerialPortClient ) ,
46- ( ) => new Quick . Protocol . SerialPort . QpSerialPortClientOptions ( ) ,
47- ( ) => new Controls . ClientOptions . SerialPortClientOptionsControl ( ) ) ;
48- register (
49- typeof ( Quick . Protocol . WebSocket . Client . QpWebSocketClient ) ,
50- ( ) => new Quick . Protocol . WebSocket . Client . QpWebSocketClientOptions ( ) ,
51- ( ) => new Controls . ClientOptions . WebSocketClientOptionsControl ( ) ) ;
29+ register ( new QpClientTypeInfo ( )
30+ {
31+ TypeName = typeof ( Quick . Protocol . Tcp . QpTcpClient ) . FullName ,
32+ Name = "TCP" ,
33+ CreateOptionsControlFunc = ( ) => new Controls . ClientOptions . TcpClientOptionsControl ( ) ,
34+ CreateOptionsInstanceFunc = ( ) => new Quick . Protocol . Tcp . QpTcpClientOptions ( ) ,
35+ DeserializeQpClientOptions = stream => JsonSerializer . Deserialize ( stream , Quick . Protocol . Tcp . QpTcpClientOptionsSerializerContext . Default . QpTcpClientOptions )
36+ } ) ;
37+ register ( new QpClientTypeInfo ( )
38+ {
39+ TypeName = typeof ( Quick . Protocol . Pipeline . QpPipelineClient ) . FullName ,
40+ Name = "命名管道" ,
41+ CreateOptionsControlFunc = ( ) => new Controls . ClientOptions . PipelineClientOptionsControl ( ) ,
42+ CreateOptionsInstanceFunc = ( ) => new Quick . Protocol . Pipeline . QpPipelineClientOptions ( ) ,
43+ DeserializeQpClientOptions = stream => JsonSerializer . Deserialize ( stream , Quick . Protocol . Pipeline . QpPipelineClientOptionsSerializerContext . Default . QpPipelineClientOptions )
44+ } ) ;
45+ register ( new QpClientTypeInfo ( )
46+ {
47+ TypeName = typeof ( Quick . Protocol . SerialPort . QpSerialPortClient ) . FullName ,
48+ Name = "串口" ,
49+ CreateOptionsControlFunc = ( ) => new Controls . ClientOptions . SerialPortClientOptionsControl ( ) ,
50+ CreateOptionsInstanceFunc = ( ) => new Quick . Protocol . SerialPort . QpSerialPortClientOptions ( ) ,
51+ DeserializeQpClientOptions = stream => JsonSerializer . Deserialize ( stream , Quick . Protocol . SerialPort . QpSerialPortClientOptionsSerializerContext . Default . QpSerialPortClientOptions )
52+ } ) ;
53+ register ( new QpClientTypeInfo ( )
54+ {
55+ TypeName = typeof ( Quick . Protocol . WebSocket . Client . QpWebSocketClient ) . FullName ,
56+ Name = "WebSocket" ,
57+ CreateOptionsControlFunc = ( ) => new Controls . ClientOptions . WebSocketClientOptionsControl ( ) ,
58+ CreateOptionsInstanceFunc = ( ) => new Quick . Protocol . WebSocket . Client . QpWebSocketClientOptions ( ) ,
59+ DeserializeQpClientOptions = stream => JsonSerializer . Deserialize ( stream , Quick . Protocol . WebSocket . Client . QpWebSocketClientOptionsSerializerContext . Default . QpWebSocketClientOptions )
60+ } ) ;
5261 }
5362
5463 public QpClientTypeInfo Get ( string qpClientTypeName )
0 commit comments