refactor: standardize project names to Musify.* and flatten layout
- Flatten nested per-repo folders into flat Musify.* projects at root - Rename assemblies/csproj: Domain->Musify.Domain, Application->Musify.Application, Infrastructure->Musify.Infrastructure, WebApi->Musify.Api, Worker->Musify.Worker, StreamingGateway->Musify.StreamingGateway - Rename WebApi.* namespaces to Musify.Api.* - Update all ProjectReference paths and the solution file - Consolidate stray per-repo dotfiles; add root .gitattributes - Move flutter client out to _archive
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Musify.Application.Contracts;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using Musify.Infrastructure.MassTransit.Logs;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities.Files
|
||||
{
|
||||
internal class CopyFileInBucketActivity(
|
||||
IStorageService storageHandler,
|
||||
ILogger<CopyFileInBucketActivity> logger)
|
||||
: IActivity<CopyFileInBucketArguments, CopyFileInBucketLog>
|
||||
{
|
||||
public const string ExecuteEndpointName = "copy-file-in-bucket";
|
||||
|
||||
public async Task<ExecutionResult> Execute(ExecuteContext<CopyFileInBucketArguments> executeContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
await storageHandler.CopyFileAsync(
|
||||
executeContext.Arguments.SourceBucket,
|
||||
executeContext.Arguments.SourceKey,
|
||||
executeContext.Arguments.DestinationBucket,
|
||||
executeContext.Arguments.DestinationKey,
|
||||
executeContext.CancellationToken);
|
||||
|
||||
return executeContext.Completed(new CopyFileInBucketLog(
|
||||
executeContext.Arguments.DestinationBucket,
|
||||
executeContext.Arguments.DestinationKey));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to copy {SourceBucket}/{SourceKey} to {DestinationBucket}/{DestinationKey}",
|
||||
executeContext.Arguments.SourceBucket,
|
||||
executeContext.Arguments.SourceKey,
|
||||
executeContext.Arguments.DestinationBucket,
|
||||
executeContext.Arguments.DestinationKey);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CompensationResult> Compensate(CompensateContext<CopyFileInBucketLog> compensateContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
await storageHandler.RemoveFileAsync(
|
||||
compensateContext.Log.DestinationBucket,
|
||||
compensateContext.Log.DestinationKey,
|
||||
compensateContext.CancellationToken);
|
||||
return compensateContext.Compensated();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to compensate copied file {Bucket}/{Key}",
|
||||
compensateContext.Log.DestinationBucket,
|
||||
compensateContext.Log.DestinationKey);
|
||||
return compensateContext.Failed(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Musify.Application.Contracts;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using Musify.Infrastructure.MassTransit.Logs;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities.Files
|
||||
{
|
||||
internal class DownloadFileFromBucketActivity(
|
||||
IStorageService storageHandler,
|
||||
ILogger<DownloadFileFromBucketActivity> logger)
|
||||
: IActivity<DownloadFileFromBucketArguments, DownloadFileFromBucketLog>
|
||||
{
|
||||
public const string ExecuteEndpointName = "download-file-from-bucket";
|
||||
|
||||
public async Task<ExecutionResult> Execute(ExecuteContext<DownloadFileFromBucketArguments> executeContext)
|
||||
{
|
||||
var destinationPath = executeContext.GetVariable<string>(executeContext.Arguments.DestinationFilePathVariable);
|
||||
ArgumentNullException.ThrowIfNull(destinationPath, nameof(destinationPath));
|
||||
|
||||
try
|
||||
{
|
||||
using var fileStream = await storageHandler.GetFileAsync(
|
||||
executeContext.Arguments.Bucket,
|
||||
executeContext.Arguments.Key,
|
||||
executeContext.CancellationToken);
|
||||
|
||||
var destinationDirectory = Path.GetDirectoryName(destinationPath);
|
||||
if (!string.IsNullOrWhiteSpace(destinationDirectory))
|
||||
Directory.CreateDirectory(destinationDirectory);
|
||||
|
||||
if (fileStream.CanSeek)
|
||||
fileStream.Position = 0;
|
||||
|
||||
using var destinationStream = File.Create(destinationPath);
|
||||
await fileStream.CopyToAsync(destinationStream, executeContext.CancellationToken);
|
||||
return executeContext.Completed(new DownloadFileFromBucketLog(
|
||||
executeContext.Arguments.Bucket,
|
||||
executeContext.Arguments.Key,
|
||||
destinationPath));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to download file from bucket");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<CompensationResult> Compensate(CompensateContext<DownloadFileFromBucketLog> compensateContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(compensateContext.Log.DestinationFilePath);
|
||||
return Task.FromResult(compensateContext.Compensated());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to compensate downloaded file {DestinationFilePath}", compensateContext.Log.DestinationFilePath);
|
||||
return Task.FromResult(compensateContext.Failed(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using MassTransit;
|
||||
using Amazon.S3;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using System.Net;
|
||||
using Musify.Application.Contracts;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities.Files
|
||||
{
|
||||
internal class RemoveFileFromBucketActivity(
|
||||
IStorageService storageHandler,
|
||||
ILogger<RemoveFileFromBucketActivity> logger)
|
||||
: IExecuteActivity<RemoveFileFromBucketArguments>
|
||||
{
|
||||
public const string ExecuteEndpointName = "remove-file-from-bucket";
|
||||
|
||||
public async Task<ExecutionResult> Execute(ExecuteContext<RemoveFileFromBucketArguments> executeContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
await storageHandler.RemoveFileAsync(
|
||||
executeContext.Arguments.Bucket,
|
||||
executeContext.Arguments.Key,
|
||||
executeContext.CancellationToken);
|
||||
return executeContext.Completed();
|
||||
}
|
||||
catch (AmazonS3Exception exception) when (
|
||||
exception.StatusCode == HttpStatusCode.NotFound
|
||||
|| string.Equals(exception.ErrorCode, "NoSuchKey", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
logger.LogInformation(
|
||||
"Key {Key} not found in bucket {Bucket}, skipping",
|
||||
executeContext.Arguments.Key,
|
||||
executeContext.Arguments.Bucket);
|
||||
return executeContext.Completed();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to remove {Key} from bucket {Bucket}",
|
||||
executeContext.Arguments.Key,
|
||||
executeContext.Arguments.Bucket);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Musify.Application.Contracts;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using Musify.Infrastructure.MassTransit.Logs;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities
|
||||
{
|
||||
public class TransferFilesToBucketActivity(
|
||||
IStorageService storageHandler,
|
||||
ILogger<TransferFilesToBucketActivity> logger)
|
||||
: IActivity<TransferFilesToBucketArguments, TransferFilesToBucketLog>
|
||||
{
|
||||
public const string ExecuteEndpointName = "transfer-files-to-bucket";
|
||||
|
||||
public async Task<ExecutionResult> Execute(ExecuteContext<TransferFilesToBucketArguments> executeContext)
|
||||
{
|
||||
var folderPath = executeContext.GetVariable<string>(executeContext.Arguments.SourceDirectoryVariable);
|
||||
ArgumentNullException.ThrowIfNull(folderPath, nameof(folderPath));
|
||||
var destinationKey = executeContext.Arguments.DestinationKey;
|
||||
ArgumentNullException.ThrowIfNull(destinationKey, nameof(destinationKey));
|
||||
|
||||
try
|
||||
{
|
||||
var uploadedKeys = Directory.GetFiles(folderPath)
|
||||
.Select(file => Path.Combine(destinationKey, Path.GetFileName(file)))
|
||||
.ToArray();
|
||||
|
||||
await storageHandler.TransferFilesAsync(
|
||||
folderPath,
|
||||
executeContext.Arguments.DestinationBucket,
|
||||
destinationKey,
|
||||
executeContext.CancellationToken);
|
||||
return executeContext.Completed();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to transfer files from {FolderPath} to {DestinationBucket}",
|
||||
folderPath,
|
||||
executeContext.Arguments.DestinationBucket);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CompensationResult> Compensate(CompensateContext<TransferFilesToBucketLog> compensateContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var uploadedKey in compensateContext.Log.UploadedKeys)
|
||||
{
|
||||
await storageHandler.RemoveFileAsync(
|
||||
compensateContext.Log.DestinationBucket,
|
||||
uploadedKey,
|
||||
compensateContext.CancellationToken);
|
||||
}
|
||||
|
||||
return compensateContext.Compensated();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to compensate file transfers to {DestinationBucket}", compensateContext.Log.DestinationBucket);
|
||||
return compensateContext.Failed(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Musify.Application.Contracts;
|
||||
using Musify.Infrastructure.MassTransit.Arguments;
|
||||
using Musify.Infrastructure.MassTransit.Logs;
|
||||
|
||||
namespace Musify.Infrastructure.MassTransit.Activities.Files
|
||||
{
|
||||
public class UploadFileToBucketActivity(IStorageService storageHandler,
|
||||
ILogger<UploadFileToBucketActivity> logger)
|
||||
: IActivity<UploadFileToBucketArguments, UploadFileToBucketLog>
|
||||
{
|
||||
public const string ExecuteEndpointName = "upload-file-to-bucket";
|
||||
|
||||
public async Task<ExecutionResult> Execute(ExecuteContext<UploadFileToBucketArguments> executeContext)
|
||||
{
|
||||
var sourceFilePath = executeContext.GetVariable<string>(executeContext.Arguments.FilePathVariable);
|
||||
ArgumentNullException.ThrowIfNull(sourceFilePath, nameof(sourceFilePath));
|
||||
var fileName = Path.GetFileName(sourceFilePath);
|
||||
var destinationKey = string.Join('/', new[] { executeContext.Arguments.DestinationRoute, fileName }
|
||||
.Where(static s => !string.IsNullOrWhiteSpace(s))
|
||||
.Select(static s => s.Trim().Trim('/', '\\')));
|
||||
|
||||
try
|
||||
{
|
||||
await storageHandler.UploadFileAsync(
|
||||
sourceFilePath,
|
||||
executeContext.Arguments.DestinationBucket,
|
||||
destinationKey,
|
||||
executeContext.CancellationToken);
|
||||
return executeContext.CompletedWithVariables(new UploadFileToBucketLog(
|
||||
executeContext.Arguments.DestinationBucket,
|
||||
destinationKey));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to upload file to bucket");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CompensationResult> Compensate(CompensateContext<UploadFileToBucketLog> compensateContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
await storageHandler.RemoveFileAsync(
|
||||
compensateContext.Log.DestinationBucket,
|
||||
compensateContext.Log.DestinationKey,
|
||||
compensateContext.CancellationToken);
|
||||
return compensateContext.Compensated();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Error compensating file upload for {Bucket}/{Key}",
|
||||
compensateContext.Log.DestinationBucket,
|
||||
compensateContext.Log.DestinationKey);
|
||||
return compensateContext.Failed(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user