mirror of https://github.com/abpframework/abp.git
committed by
GitHub
15 changed files with 154 additions and 64 deletions
@ -0,0 +1,15 @@ |
|||
namespace Volo.Abp.BlobStoring |
|||
{ |
|||
public class BlobNormalizeNaming |
|||
{ |
|||
public string ContainerName { get; } |
|||
|
|||
public string BlobName { get; } |
|||
|
|||
public BlobNormalizeNaming(string containerName, string blobName) |
|||
{ |
|||
ContainerName = containerName; |
|||
BlobName = blobName; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.BlobStoring |
|||
{ |
|||
public class BlobNormalizeNamingService : IBlobNormalizeNamingService, ITransientDependency |
|||
{ |
|||
protected IServiceProvider ServiceProvider { get; } |
|||
|
|||
public BlobNormalizeNamingService(IServiceProvider serviceProvider) |
|||
{ |
|||
ServiceProvider = serviceProvider; |
|||
} |
|||
|
|||
public BlobNormalizeNaming NormalizeNaming( |
|||
BlobContainerConfiguration configuration, |
|||
string containerName, |
|||
string blobName) |
|||
{ |
|||
|
|||
if (!configuration.NamingNormalizers.Any()) |
|||
{ |
|||
return new BlobNormalizeNaming(containerName, blobName); |
|||
} |
|||
|
|||
using (var scope = ServiceProvider.CreateScope()) |
|||
{ |
|||
foreach (var normalizerType in configuration.NamingNormalizers) |
|||
{ |
|||
var normalizer = scope.ServiceProvider |
|||
.GetRequiredService(normalizerType) |
|||
.As<IBlobNamingNormalizer>(); |
|||
|
|||
containerName = containerName.IsNullOrWhiteSpace()? containerName: normalizer.NormalizeContainerName(containerName); |
|||
blobName = blobName.IsNullOrWhiteSpace()? blobName: normalizer.NormalizeBlobName(blobName); |
|||
} |
|||
|
|||
return new BlobNormalizeNaming(containerName, blobName); |
|||
} |
|||
} |
|||
|
|||
public string NormalizeContainerName(BlobContainerConfiguration configuration, string containerName) |
|||
{ |
|||
if (!configuration.NamingNormalizers.Any()) |
|||
{ |
|||
return containerName; |
|||
} |
|||
|
|||
return NormalizeNaming(configuration, containerName, null).ContainerName; |
|||
} |
|||
|
|||
public string NormalizeBlobName(BlobContainerConfiguration configuration, string blobName) |
|||
{ |
|||
if (!configuration.NamingNormalizers.Any()) |
|||
{ |
|||
return blobName; |
|||
} |
|||
|
|||
return NormalizeNaming(configuration, null, blobName).BlobName; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace Volo.Abp.BlobStoring |
|||
{ |
|||
public interface IBlobNormalizeNamingService |
|||
{ |
|||
BlobNormalizeNaming NormalizeNaming(BlobContainerConfiguration configuration, string containerName, string blobName); |
|||
|
|||
string NormalizeContainerName(BlobContainerConfiguration configuration, string containerName); |
|||
|
|||
string NormalizeBlobName(BlobContainerConfiguration configuration, string blobName); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue