24
24
using ProtocolHostStatus = _1RM . View . Host . ProtocolHosts . ProtocolHostStatus ;
25
25
using Screen = System . Windows . Forms . Screen ;
26
26
using _1RM . Service . DataSource ;
27
- using _1RM . View . ServerList ;
28
27
29
28
namespace _1RM . Service
30
29
{
@@ -39,8 +38,8 @@ public SessionControlService(DataSourceService sourceService, ConfigurationServi
39
38
_sourceService = sourceService ;
40
39
_configurationService = configurationService ;
41
40
_appData = appData ;
42
- GlobalEventHelper . OnRequestServerConnect += this . ShowRemoteHost ;
43
- GlobalEventHelper . OnRequestQuickConnect += this . ShowRemoteHost ;
41
+ GlobalEventHelper . OnRequestServerConnect += this . ShowRemoteHostById ;
42
+ GlobalEventHelper . OnRequestQuickConnect += this . ShowRemoteHostByObject ;
44
43
}
45
44
46
45
public void Release ( )
@@ -306,15 +305,25 @@ private void ConnectWithTab(ProtocolBase server, Runner runner, string assignTab
306
305
}
307
306
}
308
307
309
- private void ShowRemoteHost ( ProtocolBase server , string ? assignTabToken , string ? assignRunnerName , string ? via )
308
+ private void ShowRemoteHostByObject ( ProtocolBase serverOrg , string ? assignTabToken , string ? assignRunnerName , string ? fromView , string assignCredentialName = "" )
310
309
{
311
310
// if is OnlyOneInstance server and it is connected now, activate it and return.
312
- if ( this . ActivateOrReConnIfServerSessionIsOpened ( server ) )
311
+ if ( this . ActivateOrReConnIfServerSessionIsOpened ( serverOrg ) )
313
312
return ;
314
313
315
314
316
- if ( string . IsNullOrEmpty ( via ) == false )
317
- MsAppCenterHelper . TraceSessionOpen ( server . Protocol , via ) ;
315
+ if ( string . IsNullOrEmpty ( fromView ) == false )
316
+ MsAppCenterHelper . TraceSessionOpen ( serverOrg . Protocol , fromView ) ;
317
+
318
+ var server = serverOrg . Clone ( ) ;
319
+ if ( server is ProtocolBaseWithAddressPortUserPwd protocol
320
+ && protocol . Credentials ? . Count > 0
321
+ && protocol . Credentials . Any ( x => x . Name == assignCredentialName ) )
322
+ {
323
+ var c = protocol . Credentials . First ( x => x . Name == assignCredentialName ) ;
324
+ if ( ! string . IsNullOrEmpty ( c . Address ) )
325
+ protocol . Address = c . Address ;
326
+ }
318
327
319
328
// run script before connected
320
329
server . RunScriptBeforeConnect ( ) ;
@@ -353,7 +362,7 @@ private void ShowRemoteHost(ProtocolBase server, string? assignTabToken, string?
353
362
PrintCacheCount ( ) ;
354
363
}
355
364
356
- private void ShowRemoteHost ( string serverId , string ? assignTabToken , string ? assignRunnerName , string via )
365
+ private void ShowRemoteHostById ( string serverId , string ? assignTabToken , string ? assignRunnerName , string fromView , string assignCredentialName = "" )
357
366
{
358
367
#region START MULTIPLE SESSION
359
368
// if serverId <= 0, then start multiple sessions
@@ -362,7 +371,7 @@ private void ShowRemoteHost(string serverId, string? assignTabToken, string? ass
362
371
var list = _appData . VmItemList . Where ( x => x . IsSelected ) . ToArray ( ) ;
363
372
foreach ( var item in list )
364
373
{
365
- this . ShowRemoteHost ( item . Id , assignTabToken , assignRunnerName , "" ) ;
374
+ this . ShowRemoteHostById ( item . Id , assignTabToken , assignRunnerName , fromView ) ;
366
375
}
367
376
return ;
368
377
}
@@ -384,7 +393,7 @@ private void ShowRemoteHost(string serverId, string? assignTabToken, string? ass
384
393
ConnectTimeRecorder . UpdateAndSave ( vmServer . Server ) ;
385
394
vmServer . LastConnectTime = ConnectTimeRecorder . Get ( vmServer . Server ) ;
386
395
387
- ShowRemoteHost ( vmServer . Server , assignTabToken , assignRunnerName , via ) ;
396
+ ShowRemoteHostByObject ( vmServer . Server , assignTabToken , assignRunnerName , fromView , assignCredentialName ) ;
388
397
}
389
398
390
399
public void AddTab ( TabWindowBase tab )
0 commit comments