Skip to content

Commit 61400d5

Browse files
committed
Enforce member order across solution.
1 parent dae9e5b commit 61400d5

File tree

49 files changed

+612
-955
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+612
-955
lines changed

ControlR.Agent.Common/Services/Base/IpcServerInitializerBase.cs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,13 @@ internal abstract class IpcServerInitializerBase(
1717
ILogger logger) : BackgroundService
1818
{
1919
protected IHubConnection<IAgentHub> HubConnection { get; } = hubConnection;
20-
protected IIpcConnectionFactory IpcFactory { get; } = ipcFactory;
2120
protected IIpcClientAuthenticator IpcAuthenticator { get; } = ipcAuthenticator;
21+
protected IIpcConnectionFactory IpcFactory { get; } = ipcFactory;
2222
protected IIpcServerStore IpcStore { get; } = ipcStore;
2323
protected ILogger Logger { get; } = logger;
2424
protected IProcessManager ProcessManager { get; } = processManager;
2525
protected TimeProvider TimeProvider { get; } = timeProvider;
2626

27-
protected abstract Task<IIpcServer> CreateServer(string pipeName, CancellationToken cancellationToken);
28-
29-
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
30-
{
31-
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(3), TimeProvider);
32-
33-
try
34-
{
35-
while (await timer.WaitForNextTickAsync(stoppingToken))
36-
{
37-
try
38-
{
39-
await AcceptConnection(stoppingToken);
40-
}
41-
catch (Exception ex)
42-
{
43-
Logger.LogError(ex, "Error while accepting IPC connections.");
44-
}
45-
}
46-
}
47-
catch (OperationCanceledException ex)
48-
{
49-
Logger.LogInformation(ex, "Stopping IPC server. Application is shutting down.");
50-
}
51-
}
52-
5327
protected virtual async Task AcceptConnection(CancellationToken cancellationToken)
5428
{
5529
try
@@ -93,9 +67,31 @@ protected virtual async Task AcceptConnection(CancellationToken cancellationToke
9367
Logger.LogError(ex, "Error while accepting IPC connection.");
9468
}
9569
}
70+
protected abstract Task<IIpcServer> CreateServer(string pipeName, CancellationToken cancellationToken);
71+
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
72+
{
73+
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(3), TimeProvider);
9674

75+
try
76+
{
77+
while (await timer.WaitForNextTickAsync(stoppingToken))
78+
{
79+
try
80+
{
81+
await AcceptConnection(stoppingToken);
82+
}
83+
catch (Exception ex)
84+
{
85+
Logger.LogError(ex, "Error while accepting IPC connections.");
86+
}
87+
}
88+
}
89+
catch (OperationCanceledException ex)
90+
{
91+
Logger.LogInformation(ex, "Stopping IPC server. Application is shutting down.");
92+
}
93+
}
9794
protected abstract string GetPipeName();
98-
9995
protected Task HandleConnection(IIpcServer server, ClientCredentials credentials, CancellationToken cancellationToken)
10096
{
10197
try

ControlR.Agent.Common/Services/Linux/IpcServerInitializerLinux.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ internal class IpcServerInitializerLinux(
2222
private readonly IFileSystem _fileSystem = fileSystem;
2323
private readonly IOptions<InstanceOptions> _instanceOptions = instanceOptions;
2424

25-
protected override string GetPipeName() => IpcPipeNames.GetPipeName(_instanceOptions.Value.InstanceId);
26-
2725
protected override async Task<IIpcServer> CreateServer(string pipeName, CancellationToken cancellationToken)
2826
{
2927
var pipeServer = await IpcFactory.CreateServer(pipeName);
3028
SetPipePermissions(pipeName, pipeServer, cancellationToken).Forget();
3129
return pipeServer;
3230
}
31+
protected override string GetPipeName() => IpcPipeNames.GetPipeName(_instanceOptions.Value.InstanceId);
3332

3433
private async Task SetPipePermissions(string pipeName, IIpcServer pipeServer, CancellationToken cancellationToken)
3534
{

ControlR.Agent.Common/Services/Linux/ServiceControlLinux.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ internal class ServiceControlLinux(
1212
ILogger<ServiceControlLinux> logger) : IServiceControl
1313
{
1414
private static readonly TimeSpan _serviceStatusTimeout = TimeSpan.FromSeconds(10);
15+
1516
private readonly IHeadlessServerDetector _headlessServerDetector = headlessServerDetector;
16-
private readonly ILoggedInUserProvider _loggedInUserProvider = loggedInUserProvider;
1717
private readonly IOptions<InstanceOptions> _instanceOptions = instanceOptions;
18+
private readonly ILoggedInUserProvider _loggedInUserProvider = loggedInUserProvider;
1819
private readonly ILogger<ServiceControlLinux> _logger = logger;
1920
private readonly IProcessManager _processManager = processManager;
2021

@@ -42,7 +43,6 @@ public async Task StartAgentService(bool throwOnFailure)
4243
}
4344
}
4445
}
45-
4646
public async Task StartDesktopClientService(bool throwOnFailure)
4747
{
4848
// Check if running on headless server
@@ -87,7 +87,6 @@ public async Task StartDesktopClientService(bool throwOnFailure)
8787
}
8888
}
8989
}
90-
9190
public async Task StopAgentService(bool throwOnFailure)
9291
{
9392
try
@@ -112,7 +111,6 @@ public async Task StopAgentService(bool throwOnFailure)
112111
}
113112
}
114113
}
115-
116114
public async Task StopDesktopClientService(bool throwOnFailure)
117115
{
118116
// Check if running on headless server
@@ -167,7 +165,6 @@ private string GetAgentServiceName()
167165

168166
return $"controlr.agent-{_instanceOptions.Value.InstanceId}.service";
169167
}
170-
171168
private string GetDesktopClientServiceName()
172169
{
173170
if (string.IsNullOrWhiteSpace(_instanceOptions.Value.InstanceId))
@@ -177,7 +174,6 @@ private string GetDesktopClientServiceName()
177174

178175
return $"controlr.desktop-{_instanceOptions.Value.InstanceId}.service";
179176
}
180-
181177
private async Task StartDesktopClientForUser(string uid, string serviceName, bool throwOnFailure)
182178
{
183179
try
@@ -204,7 +200,6 @@ await _processManager.StartAndWaitForExit("sudo",
204200
}
205201
}
206202
}
207-
208203
private async Task StopDesktopClientForUser(string uid, string serviceName, bool throwOnFailure)
209204
{
210205
try

ControlR.Agent.Common/Services/Mac/DesktopSessionProviderMac.cs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public async Task<DesktopSession[]> GetActiveDesktopClients()
4343

4444
return [.. uiSessions];
4545
}
46-
4746
public async Task<string[]> GetLoggedInUsers()
4847
{
4948
var sessions = await GetActiveUiSessions();
@@ -67,7 +66,6 @@ private static int GenerateSessionId(string username, string tty)
6766
return Math.Abs(hash % 9000) + 1000; // Range: 1000-9999
6867
}
6968

70-
7169
private async Task AddVncSessions(List<DesktopSession> sessions)
7270
{
7371
try
@@ -114,7 +112,27 @@ private async Task AddVncSessions(List<DesktopSession> sessions)
114112
_logger.LogDebug(ex, "Error detecting VNC sessions");
115113
}
116114
}
115+
private async Task<bool> CheckPermissionsViaIpc(IpcServerRecord serverInfo)
116+
{
117+
try
118+
{
119+
var ipcDto = new CheckOsPermissionsIpcDto(serverInfo.Process.Id);
120+
var ipcResult = await serverInfo.Server.Invoke<CheckOsPermissionsIpcDto, CheckOsPermissionsResponseIpcDto>(ipcDto, timeoutMs: 3000);
117121

122+
if (ipcResult.IsSuccess && ipcResult.Value is not null)
123+
{
124+
return ipcResult.Value.ArePermissionsGranted;
125+
}
126+
127+
_logger.LogWarning("Failed to get permissions via IPC for process {ProcessId}", serverInfo.Process.Id);
128+
return false;
129+
}
130+
catch (Exception ex)
131+
{
132+
_logger.LogError(ex, "Error checking permissions via IPC for process {ProcessId}", serverInfo.Process.Id);
133+
return false;
134+
}
135+
}
118136
private async Task<DesktopSession[]> GetActiveUiSessions()
119137
{
120138
var sessions = new List<DesktopSession>();
@@ -179,7 +197,6 @@ private async Task<DesktopSession[]> GetActiveUiSessions()
179197

180198
return [.. sessions];
181199
}
182-
183200
private async Task<Dictionary<string, string>> GetLoggedInUserMap()
184201
{
185202
var userMap = new Dictionary<string, string>(); // uid -> username
@@ -218,7 +235,6 @@ private async Task<Dictionary<string, string>> GetLoggedInUserMap()
218235

219236
return userMap;
220237
}
221-
222238
private async Task<Result<string>> TryGetUsernameForProcess(IProcess process,
223239
Dictionary<string, string> loggedInUsers)
224240
{
@@ -249,26 +265,4 @@ private async Task<Result<string>> TryGetUsernameForProcess(IProcess process,
249265

250266
return Result.Fail<string>("Failed to get username");
251267
}
252-
253-
private async Task<bool> CheckPermissionsViaIpc(IpcServerRecord serverInfo)
254-
{
255-
try
256-
{
257-
var ipcDto = new CheckOsPermissionsIpcDto(serverInfo.Process.Id);
258-
var ipcResult = await serverInfo.Server.Invoke<CheckOsPermissionsIpcDto, CheckOsPermissionsResponseIpcDto>(ipcDto, timeoutMs: 3000);
259-
260-
if (ipcResult.IsSuccess && ipcResult.Value is not null)
261-
{
262-
return ipcResult.Value.ArePermissionsGranted;
263-
}
264-
265-
_logger.LogWarning("Failed to get permissions via IPC for process {ProcessId}", serverInfo.Process.Id);
266-
return false;
267-
}
268-
catch (Exception ex)
269-
{
270-
_logger.LogError(ex, "Error checking permissions via IPC for process {ProcessId}", serverInfo.Process.Id);
271-
return false;
272-
}
273-
}
274268
}

ControlR.Agent.Common/Services/Mac/IpcServerInitializerMac.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ internal class IpcServerInitializerMac(
2626
private readonly IFileSystemUnix _fileSystemUnix = fileSystemUnix;
2727
private readonly IOptions<InstanceOptions> _instanceOptions = instanceOptions;
2828

29-
protected override string GetPipeName() => IpcPipeNames.GetPipeName(_instanceOptions.Value.InstanceId);
30-
3129
protected override async Task<IIpcServer> CreateServer(string pipeName, CancellationToken cancellationToken)
3230
{
3331
var pipeServer = await IpcFactory.CreateServer(pipeName);
3432
SetPipePermissions(pipeName, pipeServer, cancellationToken).Forget();
3533
return pipeServer;
3634
}
35+
protected override string GetPipeName() => IpcPipeNames.GetPipeName(_instanceOptions.Value.InstanceId);
3736

3837
private async Task SetPipePermissions(string pipeName, IIpcServer pipeServer, CancellationToken cancellationToken)
3938
{

0 commit comments

Comments
 (0)