Skip to content

Commit aa84184

Browse files
committed
feat: check alternative addresses when rdp is reconnecting. #869
1 parent e7e2a0c commit aa84184

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

Ui/Service/SessionControlService_AlternateCredential.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static void CredentialTest()
7474
/// <summary>
7575
/// Find the first connectable address from the given credentials. if return null then no address is connectable.
7676
/// </summary>
77-
private static async Task<Credential?> FindFirstConnectableAddressAsync(IEnumerable<Credential> pingCredentials, string protocolDisplayName)
77+
public static async Task<Credential?> FindFirstConnectableAddressAsync(IEnumerable<Credential> pingCredentials, string protocolDisplayName)
7878
{
7979
var credentials = pingCredentials.Select(x => x.CloneMe()).ToList();
8080
const int maxWaitSeconds = 5;
@@ -209,7 +209,7 @@ await Execute.OnUIThreadAsync(() =>
209209
/// <summary>
210210
/// if return null then no address is connectable.
211211
/// </summary>
212-
private static async Task<Credential?> GetCredential(ProtocolBaseWithAddressPort protocol, string assignCredentialName)
212+
public static async Task<Credential?> GetCredential(ProtocolBaseWithAddressPort protocol, string assignCredentialName = "")
213213
{
214214
var newCredential = protocol.GetCredential();
215215
newCredential.Name = protocol.DisplayName;

Ui/View/Host/ProtocolHosts/AxMsRdpClient09Host.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Linq;
34
using System.Threading;
45
using System.Threading.Tasks;
56
using System.Windows;
@@ -12,6 +13,10 @@
1213
using Shawn.Utils.Wpf;
1314
using Shawn.Utils.Wpf.Controls;
1415
using Stylet;
16+
using Windows.Security.Credentials;
17+
using System.Collections.Generic;
18+
using _1RM.Model.Protocol.Base;
19+
using _1RM.Service;
1520

1621
namespace _1RM.View.Host.ProtocolHosts
1722
{
@@ -49,6 +54,28 @@ public override void ReConn()
4954
});
5055
RdpClientDispose();
5156

57+
58+
// check if it needs to auto switch address
59+
var isAutoAlternateAddressSwitching = _rdpSettings.IsAutoAlternateAddressSwitching == true
60+
// if none of the alternate credential has host or port,then disabled `AutoAlternateAddressSwitching`
61+
&& _rdpSettings.AlternateCredentials.Any(x => !string.IsNullOrEmpty(x.Address) || !string.IsNullOrEmpty(x.Port));
62+
if (isAutoAlternateAddressSwitching)
63+
{
64+
var t = Task.Factory.StartNew(async () =>
65+
{
66+
var c = await SessionControlService.GetCredential(_rdpSettings);
67+
if (c != null)
68+
{
69+
_rdpSettings.SetCredential(c);
70+
_rdpSettings.DisplayName = c.Name;
71+
_rdpClient.Server = _rdpSettings.Address;
72+
_rdpClient.AdvancedSettings2.RDPPort = _rdpSettings.GetPort();
73+
}
74+
});
75+
t.Wait();
76+
}
77+
78+
5279
Status = ProtocolHostStatus.NotInit;
5380

5481
int w = 0;

0 commit comments

Comments
 (0)