@@ -14,28 +14,35 @@ namespace _1RM.Service
1414{
1515 public partial class SessionControlService
1616 {
17+ #if DEBUG
1718 public static void CredentialTest ( )
1819 {
1920 var pingCredentials = new List < Credential >
2021 {
22+ new Credential ( )
23+ {
24+ Name = "asfasdas12312312312" ,
25+ Address = "127.012311.131231231" , Port = "5000" ,
26+ } ,
2127 new Credential ( )
2228 {
2329 Name = "asfasdas" ,
2430 Address = "127.0.1.1" , Port = "5000" ,
2531 } ,
26- // new Credential()
27- // {
28- // Address = "127.0.0.1", Port = "5000",
29- // },
32+ new Credential ( )
33+ {
34+ Address = "127.0.0.1" , Port = "5000" ,
35+ } ,
3036 new Credential ( )
3137 {
3238 Name = "xcv1" ,
3339 Address = "192.168.100.1" , Port = "3389" ,
3440 } ,
35- //new Credential()
36- //{
37- // Address = "172.20.65.31", Port = "3389",
38- //},
41+ new Credential ( )
42+ {
43+ Name = "asfasdxxxxxxxxxxxxxxxxas12312312312" ,
44+ Address = "172.20.65.31" , Port = "3389" ,
45+ } ,
3946 new Credential ( )
4047 {
4148 Name = "98vs" ,
@@ -61,20 +68,24 @@ public static void CredentialTest()
6168 }
6269 } ) ;
6370 }
71+ #endif
72+
6473
6574 /// <summary>
6675 /// Find the first connectable address from the given credentials. if return null then no address is connectable.
6776 /// </summary>
6877 private static async Task < Credential ? > FindFirstConnectableAddressAsync ( IEnumerable < Credential > pingCredentials , string protocolDisplayName )
6978 {
70- var credentials = pingCredentials . ToList ( ) ;
71- const int maxWaitSeconds = 10 ;
79+ var credentials = pingCredentials . Select ( x => x . CloneMe ( ) ) . ToList ( ) ;
80+ const int maxWaitSeconds = 5 ;
7281 var cts = new CancellationTokenSource ( ) ;
7382
7483 var uiPingItems = new List < PingTestItem > ( ) ;
7584 foreach ( var credential in credentials )
7685 {
77- uiPingItems . Add ( new PingTestItem ( credential . Name , credential . Address )
86+ credential . Address = string . IsNullOrEmpty ( credential . Address ) ? credentials . First ( ) . Address : credential . Address ;
87+ credential . Port = string . IsNullOrEmpty ( credential . Port ) ? credentials . First ( ) . Port : credential . Port ;
88+ uiPingItems . Add ( new PingTestItem ( credential . Name , credential . Address + ":" + credential . Port )
7889 {
7990 Status = PingStatus . None ,
8091 } ) ;
@@ -135,7 +146,7 @@ await Execute.OnUIThreadAsync(() =>
135146 while ( ts . Any ( ) )
136147 {
137148 var completedTask = await Task . WhenAny ( ts ) ;
138- if ( completedTask ? . Result == true )
149+ if ( completedTask . IsCanceled == false && completedTask ? . Result == true )
139150 {
140151 completedTaskIndex = tasks . IndexOf ( completedTask ) ;
141152 SimpleLogHelper . DebugInfo ( $ "Task{ completedTaskIndex } completed first. Cancelling remaining tasks.") ;
@@ -169,7 +180,7 @@ await Execute.OnUIThreadAsync(() =>
169180 if ( completedTaskIndex >= 0 && completedTaskIndex < tasks . Count )
170181 {
171182 // close the pop window
172- await Execute . OnUIThreadAsync ( ( ) => { dlg . RequestClose ( ) ; } ) ;
183+ // await Execute.OnUIThreadAsync(() => { dlg.RequestClose(); });
173184 return credentials [ completedTaskIndex ] . CloneMe ( ) ;
174185 }
175186 else
@@ -191,6 +202,7 @@ await Execute.OnUIThreadAsync(() =>
191202 private static async Task < Credential ? > GetCredential ( ProtocolBaseWithAddressPort protocol , string assignCredentialName )
192203 {
193204 var newCredential = protocol . GetCredential ( ) ;
205+ newCredential . Name = "default" ;
194206 // use assign credential 应用指定的 credential
195207 var assignCredential = protocol . AlternateCredentials . FirstOrDefault ( x => x . Name == assignCredentialName ) ;
196208 if ( assignCredential != null )
@@ -202,7 +214,7 @@ await Execute.OnUIThreadAsync(() =>
202214 // check if need to ping before connect
203215 bool isPingBeforeConnect = protocol . IsPingBeforeConnect == true
204216 // do not ping if rdp protocol and gateway is used
205- && protocol is not RDP { GatewayMode : EGatewayMode . DoNotUseGateway } ;
217+ && protocol is not RDP { GatewayMode : EGatewayMode . UseTheseGatewayServerSettings } ;
206218 var isAutoAlternateAddressSwitching = protocol . IsAutoAlternateAddressSwitching == true
207219 // if any host or port in assignCredential,then disabled `AutoAlternateAddressSwitching`
208220 && string . IsNullOrEmpty ( assignCredential ? . Address ) && string . IsNullOrEmpty ( assignCredential ? . Port )
0 commit comments