-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #701 from Crypter-File-Transfer/stable
Merge 'stable' to 'main'
- Loading branch information
Showing
12 changed files
with
213 additions
and
22 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
Crypter.Core/Features/EventLog/Commands/LogSuccessfulTransferPreviewCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2024 Crypter File Transfer | ||
* | ||
* This file is part of the Crypter file transfer project. | ||
* | ||
* Crypter is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Crypter source code is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* You can be released from the requirements of the aforementioned license | ||
* by purchasing a commercial license. Buying such a license is mandatory | ||
* as soon as you develop commercial activities involving the Crypter source | ||
* code without disclosing the source code of your own applications. | ||
* | ||
* Contact the current copyright holder to discuss commercial license options. | ||
*/ | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Crypter.Common.Enums; | ||
using Crypter.DataAccess; | ||
using Crypter.DataAccess.Entities; | ||
using Crypter.DataAccess.Entities.JsonTypes.EventLogAdditionalData; | ||
using MediatR; | ||
using Unit = EasyMonads.Unit; | ||
|
||
namespace Crypter.Core.Features.EventLog.Commands; | ||
|
||
public sealed record LogSuccessfulTransferPreviewCommand(Guid ItemId, TransferItemType ItemType, Guid? UserId, DateTimeOffset Timestamp) : IRequest<Unit>; | ||
|
||
internal sealed class LogSuccessfulTransferPreviewCommandHandler : IRequestHandler<LogSuccessfulTransferPreviewCommand, Unit> | ||
{ | ||
private readonly DataContext _dataContext; | ||
|
||
public LogSuccessfulTransferPreviewCommandHandler(DataContext dataContext) | ||
{ | ||
_dataContext = dataContext; | ||
} | ||
|
||
public async Task<Unit> Handle(LogSuccessfulTransferPreviewCommand request, CancellationToken cancellationToken) | ||
{ | ||
SuccessfulTransferPreviewAdditionalData additionalData = new SuccessfulTransferPreviewAdditionalData(request.ItemId, request.ItemType, request.UserId); | ||
EventLogEntity logEntity = EventLogEntity.Create(EventLogType.TransferPreviewSuccess, additionalData, request.Timestamp); | ||
|
||
_dataContext.EventLogs.Add(logEntity); | ||
await _dataContext.SaveChangesAsync(CancellationToken.None); | ||
|
||
return Unit.Default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Crypter.Core/Features/Transfer/Events/SuccessfulTransferPreviewEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (C) 2024 Crypter File Transfer | ||
* | ||
* This file is part of the Crypter file transfer project. | ||
* | ||
* Crypter is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Crypter source code is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* You can be released from the requirements of the aforementioned license | ||
* by purchasing a commercial license. Buying such a license is mandatory | ||
* as soon as you develop commercial activities involving the Crypter source | ||
* code without disclosing the source code of your own applications. | ||
* | ||
* Contact the current copyright holder to discuss commercial license options. | ||
*/ | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Crypter.Common.Enums; | ||
using Crypter.Core.Services; | ||
using Hangfire; | ||
using MediatR; | ||
|
||
namespace Crypter.Core.Features.Transfer.Events; | ||
|
||
public sealed record SuccessfulTransferPreviewEvent(Guid ItemId, TransferItemType ItemType, Guid? UserId, DateTimeOffset Timestamp) : INotification; | ||
|
||
internal sealed class SuccessfulTransferPreviewEventHandler : INotificationHandler<SuccessfulTransferPreviewEvent> | ||
{ | ||
private readonly IBackgroundJobClient _backgroundJobClient; | ||
private readonly IHangfireBackgroundService _hangfireBackgroundService; | ||
|
||
public SuccessfulTransferPreviewEventHandler( | ||
IBackgroundJobClient backgroundJobClient, | ||
IHangfireBackgroundService hangfireBackgroundService) | ||
{ | ||
_backgroundJobClient = backgroundJobClient; | ||
_hangfireBackgroundService = hangfireBackgroundService; | ||
} | ||
|
||
public Task Handle(SuccessfulTransferPreviewEvent notification, CancellationToken cancellationToken) | ||
{ | ||
_backgroundJobClient.Enqueue(() => _hangfireBackgroundService.LogSuccessfulTransferPreviewAsync(notification.ItemId, notification.ItemType, notification.UserId, notification.Timestamp)); | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.