diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 012ec976b6..7c3df0ccfd 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -293,6 +293,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.UI. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BlobStoring", "src\Volo.Abp.BlobStoring\Volo.Abp.BlobStoring.csproj", "{A0CFBDD6-A3CB-438C-83F1-5025F12E2D42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BlobStoring.Tests", "test\Volo.Abp.BlobStoring.Tests\Volo.Abp.BlobStoring.Tests.csproj", "{D53A17BB-4E23-451D-AD9B-E1F6AC3F7958}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -871,6 +873,10 @@ Global {A0CFBDD6-A3CB-438C-83F1-5025F12E2D42}.Debug|Any CPU.Build.0 = Debug|Any CPU {A0CFBDD6-A3CB-438C-83F1-5025F12E2D42}.Release|Any CPU.ActiveCfg = Release|Any CPU {A0CFBDD6-A3CB-438C-83F1-5025F12E2D42}.Release|Any CPU.Build.0 = Release|Any CPU + {D53A17BB-4E23-451D-AD9B-E1F6AC3F7958}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D53A17BB-4E23-451D-AD9B-E1F6AC3F7958}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D53A17BB-4E23-451D-AD9B-E1F6AC3F7958}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D53A17BB-4E23-451D-AD9B-E1F6AC3F7958}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1019,6 +1025,7 @@ Global {8B758716-DCC9-4223-8421-5588D1597487} = {447C8A77-E5F0-4538-8687-7383196D04EA} {79323211-E658-493E-9863-035AA4C3F913} = {447C8A77-E5F0-4538-8687-7383196D04EA} {A0CFBDD6-A3CB-438C-83F1-5025F12E2D42} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} + {D53A17BB-4E23-451D-AD9B-E1F6AC3F7958} = {447C8A77-E5F0-4538-8687-7383196D04EA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerManagerExtensions.cs b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerManagerExtensions.cs new file mode 100644 index 0000000000..196d52ab25 --- /dev/null +++ b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerManagerExtensions.cs @@ -0,0 +1,48 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Volo.Abp.BlobStoring +{ + public static class BlobContainerManagerExtensions + { + /// + /// Gets a named container. + /// + /// The blob container manager + /// Cancellation token + /// + /// The container object. + /// + public static Task GetAsync( + this IBlobContainerManager blobContainerManager, + CancellationToken cancellationToken = default + ) + { + return blobContainerManager.GetAsync( + BlobContainerNameAttribute.GetContainerName(), + cancellationToken + ); + } + + /// + /// + /// + /// The blob container manager + /// Cancellation token + /// Type of the container + /// + /// Returns true if actually deleted the container. + /// Returns false if the container with the given type was not exists. + /// + public static Task DeleteAsync( + this IBlobContainerManager blobContainerManager, + CancellationToken cancellationToken = default + ) + { + return blobContainerManager.DeleteAsync( + BlobContainerNameAttribute.GetContainerName(), + cancellationToken + ); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerNameAttribute.cs b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerNameAttribute.cs new file mode 100644 index 0000000000..12bd91d669 --- /dev/null +++ b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerNameAttribute.cs @@ -0,0 +1,41 @@ +using System; +using System.Reflection; +using JetBrains.Annotations; + +namespace Volo.Abp.BlobStoring +{ + public class BlobContainerNameAttribute : Attribute + { + [NotNull] + public string Name { get; } + + public BlobContainerNameAttribute([NotNull] string name) + { + Check.NotNullOrWhiteSpace(name, nameof(name)); + + Name = name; + } + + public virtual string GetName(Type type) + { + return Name; + } + + public static string GetContainerName() + { + return GetContainerName(typeof(T)); + } + + public static string GetContainerName(Type type) + { + var nameAttribute = type.GetCustomAttribute(); + + if (nameAttribute == null) + { + return type.FullName; + } + + return nameAttribute.GetName(type); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/IBlobContainerManager.cs b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/IBlobContainerManager.cs new file mode 100644 index 0000000000..234d687d6c --- /dev/null +++ b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/IBlobContainerManager.cs @@ -0,0 +1,35 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Volo.Abp.BlobStoring +{ + public interface IBlobContainerManager + { + /// + /// Gets a named container. + /// + /// The name of the container + /// Cancellation token + /// + /// The container object. + /// + Task GetAsync( + string name, + CancellationToken cancellationToken = default + ); + + /// + /// Deletes a container. + /// + /// The name of the container + /// Cancellation token + /// + /// Returns true if actually deleted the container. + /// Returns false if the container with the given was not exists. + /// + Task DeleteAsync( + string name, + CancellationToken cancellationToken = default + ); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/IBlobManager.cs b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/IBlobManager.cs index 26d3457cca..384b818110 100644 --- a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/IBlobManager.cs +++ b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/IBlobManager.cs @@ -79,9 +79,4 @@ namespace Volo.Abp.BlobStoring //TODO: Create shortcut extension methods: GetAsArraryAsync, GetAsStringAsync(encoding) (and null versions) } - - public interface IBlobContainerManager - { - //Get (or create), Delete (if does exists) - } } \ No newline at end of file diff --git a/framework/test/Volo.Abp.BlobStoring.Tests/Volo.Abp.BlobStoring.Tests.csproj b/framework/test/Volo.Abp.BlobStoring.Tests/Volo.Abp.BlobStoring.Tests.csproj new file mode 100644 index 0000000000..d1776263a2 --- /dev/null +++ b/framework/test/Volo.Abp.BlobStoring.Tests/Volo.Abp.BlobStoring.Tests.csproj @@ -0,0 +1,16 @@ + + + + + + netcoreapp3.1 + + + + + + + + + + diff --git a/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestBase.cs b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestBase.cs new file mode 100644 index 0000000000..7027cb8147 --- /dev/null +++ b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestBase.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Testing; + +namespace Volo.Abp.BlobStoring +{ + public abstract class AbpBlobStoringTestBase : AbpIntegratedTest + { + + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestModule.cs b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestModule.cs new file mode 100644 index 0000000000..63a0c5deb5 --- /dev/null +++ b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestModule.cs @@ -0,0 +1,13 @@ +using Volo.Abp.Modularity; + +namespace Volo.Abp.BlobStoring +{ + [DependsOn( + typeof(AbpBlobStoringModule), + typeof(AbpTestBaseModule) + )] + public class AbpBlobStoringTestModule : AbpModule + { + + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/BlobContainerNameAttribute_Tests.cs b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/BlobContainerNameAttribute_Tests.cs new file mode 100644 index 0000000000..a482e7811b --- /dev/null +++ b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/BlobContainerNameAttribute_Tests.cs @@ -0,0 +1,35 @@ +using Shouldly; +using Xunit; + +namespace Volo.Abp.BlobStoring +{ + public class BlobContainerNameAttribute_Tests + { + [Fact] + public void Should_Get_Specified_Name() + { + BlobContainerNameAttribute + .GetContainerName() + .ShouldBe("ContName2"); + } + + [Fact] + public void Should_Get_Full_Class_Name_If_Not_Specified() + { + BlobContainerNameAttribute + .GetContainerName() + .ShouldBe(typeof(MyContainerType1).FullName); + } + + private class MyContainerType1 + { + + } + + [BlobContainerName("ContName2")] + private class MyContainerType2 + { + + } + } +} \ No newline at end of file