11using System . Text . Json ;
22using Quick . Protocol ;
3- using Quick . Protocol . Utils ;
4- using Quick . Xml ;
53using System ;
6- using System . Collections . Generic ;
74using System . ComponentModel ;
8- using System . Data ;
95using System . Drawing ;
10- using System . IO ;
116using System . Linq ;
12- using System . Reflection ;
137using System . Text ;
148using System . Threading . Tasks ;
159using System . Windows . Forms ;
16- using QpTestClient . Utils ;
1710
1811namespace QpTestClient
1912{
2013 public partial class ConnectForm : Form
2114 {
2215 [ DesignerSerializationVisibility ( DesignerSerializationVisibility . Hidden ) ]
2316 public TestConnectionInfo ConnectionInfo { get ; private set ; }
24-
17+ private QpClientOptions clientOptions = null ;
2518 public ConnectForm ( )
2619 {
2720 InitializeComponent ( ) ;
@@ -33,7 +26,7 @@ public ConnectForm()
3326
3427 public void EditConnectionInfo ( TestConnectionInfo connectionInfo )
3528 {
36- this . ConnectionInfo = XmlConvert . Deserialize < TestConnectionInfo > ( XmlConvert . Serialize ( connectionInfo ) , QpdFileUtils . XmlConvertOptions ) ;
29+ this . ConnectionInfo = connectionInfo ;
3730 txtName . Text = connectionInfo . Name ;
3831 var qpClientTypeInfo = QpClientTypeManager . Instance . GetAll ( ) . FirstOrDefault ( t => t . ClientType . FullName == connectionInfo . QpClientTypeName ) ;
3932 cbConnectType . SelectedItem = qpClientTypeInfo ;
@@ -47,32 +40,31 @@ private void ConnectForm_Load(object sender, EventArgs e)
4740
4841 if ( cbConnectType . Items . Count <= 0 )
4942 return ;
50- var qpClientTypeName = "Quick.Protocol.Tcp.QpTcpClient" ;
43+
5144 if ( ConnectionInfo != null )
52- qpClientTypeName = ConnectionInfo . QpClientTypeName ;
53- var item = QpClientTypeManager . Instance . GetAll ( ) . FirstOrDefault ( t => t . ClientType . FullName == qpClientTypeName ) ;
54- if ( item != null )
45+ {
46+ var qpClientTypeName = ConnectionInfo . QpClientTypeName ;
47+ var item = QpClientTypeManager . Instance . GetAll ( ) . FirstOrDefault ( t => t . ClientType . FullName == qpClientTypeName ) ;
5548 cbConnectType . SelectedItem = item ;
56- else
57- cbConnectType . SelectedIndex = 0 ;
49+ }
5850 }
5951
6052 private void cbConnectType_SelectedIndexChanged ( object sender , EventArgs e )
6153 {
6254 var qpClientTypeInfo = ( QpClientTypeInfo ) cbConnectType . SelectedItem ;
63-
64- QpClientOptions options = null ;
6555 if ( ConnectionInfo != null && qpClientTypeInfo . ClientType . FullName == ConnectionInfo . QpClientTypeName )
6656 {
67- options = ( QpClientOptions ) JsonSerializer . Deserialize (
68- JsonSerializer . Serialize ( ConnectionInfo . QpClientOptions ) ,
69- qpClientTypeInfo . OptionsType ) ;
57+ clientOptions = ConnectionInfo . QpClientOptions . Clone ( ) ;
7058 }
7159 else
7260 {
73- options = qpClientTypeInfo . CreateOptionsInstanceFunc ( ) ;
61+ clientOptions = qpClientTypeInfo . CreateOptionsInstanceFunc ( ) ;
7462 }
75- pgOptions . SelectedObject = options ;
63+ pnlClientOptions . Controls . Clear ( ) ;
64+ var control = qpClientTypeInfo . CreateOptionsControlFunc ( ) ;
65+ control . DataContext = clientOptions ;
66+ control . Dock = DockStyle . Fill ;
67+ pnlClientOptions . Controls . Add ( control ) ;
7668 }
7769
7870 private void btnOk_Click ( object sender , EventArgs e )
@@ -89,7 +81,7 @@ private void btnOk_Click(object sender, EventArgs e)
8981 {
9082 Name = name ,
9183 QpClientTypeName = qpClientTypeInfo . ClientType . FullName ,
92- QpClientOptions = ( QpClientOptions ) pgOptions . SelectedObject ,
84+ QpClientOptions = clientOptions ,
9385 Instructions = ConnectionInfo ? . Instructions
9486 } ;
9587 DialogResult = DialogResult . OK ;
0 commit comments