-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUpdateSessionSettingsCommandHandler.cs
More file actions
61 lines (48 loc) · 2.4 KB
/
UpdateSessionSettingsCommandHandler.cs
File metadata and controls
61 lines (48 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using ByteSync.Common.Business.Sessions;
using ByteSync.ServerCommon.Exceptions;
using ByteSync.ServerCommon.Interfaces.Mappers;
using ByteSync.ServerCommon.Interfaces.Repositories;
using ByteSync.ServerCommon.Interfaces.Services;
using ByteSync.ServerCommon.Interfaces.Services.Clients;
using MediatR;
using Microsoft.Extensions.Logging;
namespace ByteSync.ServerCommon.Commands.CloudSessions;
public class UpdateSessionSettingsCommandHandler : IRequestHandler<UpdateSessionSettingsRequest, bool>
{
private readonly ICloudSessionsRepository _cloudSessionsRepository;
private readonly IInvokeClientsService _invokeClientsService;
private readonly ILogger<UpdateSessionSettingsCommandHandler> _logger;
public UpdateSessionSettingsCommandHandler(ICloudSessionsRepository cloudSessionsRepository, IInventoryRepository inventoryRepository,
ISynchronizationRepository synchronizationRepository, IRedisInfrastructureService redisInfrastructureService, ISessionMemberMapper sessionMemberMapper,
IInvokeClientsService invokeClientsService, ILogger<UpdateSessionSettingsCommandHandler> logger)
{
_cloudSessionsRepository = cloudSessionsRepository;
_invokeClientsService = invokeClientsService;
_logger = logger;
}
public async Task<bool> Handle(UpdateSessionSettingsRequest request, CancellationToken cancellationToken)
{
if (request.Settings == null)
{
throw new BadRequestException("UpdateSessionSettings: sessionSettings null");
}
var result = await _cloudSessionsRepository.Update(request.SessionId, cloudSessionData =>
{
if (cloudSessionData.IsSessionActivated)
{
return false;
}
cloudSessionData.UpdateSessionSettings(request.Settings);
_logger.LogInformation("UpdateSessionSettings: {cloudSession}", cloudSessionData.SessionId);
return true;
});
if (result.IsSaved)
{
var sessionSettingsUpdatedDto = new SessionSettingsUpdatedDTO(request.SessionId, request.Client.ClientInstanceId, request.Settings);
await _invokeClientsService.SessionGroupExcept(request.SessionId, request.Client)
.SessionSettingsUpdated(sessionSettingsUpdatedDto).ConfigureAwait(false);
return true;
}
return false;
}
}