diff --git a/Creational/DesignPatterns.FactoryMethod/AzureStorageDownloader.cs b/Creational/DesignPatterns.FactoryMethod/AzureStorageDownloader.cs new file mode 100644 index 0000000..31f5c28 --- /dev/null +++ b/Creational/DesignPatterns.FactoryMethod/AzureStorageDownloader.cs @@ -0,0 +1,19 @@ +using Azure.Storage.Blobs; + +namespace DesignPatterns.FactoryMethod; + +public class AzureStorageDownloader : IFileDownloader +{ + private readonly BlobContainerClient containerClient; + + public AzureStorageDownloader(string connectionString, string containerName) + { + this.containerClient = new BlobContainerClient(connectionString, containerName); + } + + public void DownloadFile(string fileName, string destinationPath) + { + BlobClient blobClient = this.containerClient.GetBlobClient(fileName); + blobClient.DownloadTo(destinationPath); + } +} diff --git a/Creational/DesignPatterns.FactoryMethod/AzureStorageFactory.cs b/Creational/DesignPatterns.FactoryMethod/AzureStorageFactory.cs new file mode 100644 index 0000000..dd17ba0 --- /dev/null +++ b/Creational/DesignPatterns.FactoryMethod/AzureStorageFactory.cs @@ -0,0 +1,23 @@ +namespace DesignPatterns.FactoryMethod; + +public class AzureStorageFactory : IStorageServiceFactory +{ + private readonly string connectionString; + private readonly string containerName; + + public AzureStorageFactory(string connectionString, string containerName) + { + this.connectionString = connectionString; + this.containerName = containerName; + } + + public IFileUploader CreateUploader() + { + return new AzureStorageUploader(this.connectionString, this.containerName); + } + + public IFileDownloader CreateDownloader() + { + return new AzureStorageDownloader(this.connectionString, this.containerName); + } +} diff --git a/Creational/DesignPatterns.FactoryMethod/AzureStorageUploader.cs b/Creational/DesignPatterns.FactoryMethod/AzureStorageUploader.cs new file mode 100644 index 0000000..8788b61 --- /dev/null +++ b/Creational/DesignPatterns.FactoryMethod/AzureStorageUploader.cs @@ -0,0 +1,20 @@ +using Azure.Storage.Blobs; + +namespace DesignPatterns.FactoryMethod; + +public class AzureStorageUploader : IFileUploader +{ + private readonly BlobContainerClient containerClient; + + public AzureStorageUploader(string connectionString, string containerName) + { + this.containerClient = new BlobContainerClient(connectionString, containerName); + } + + public void UploadFile(string filePath) + { + var fileName = Path.GetFileName(filePath); + var blobClient = this.containerClient.GetBlobClient(fileName); + blobClient.Upload(filePath, true); + } +} diff --git a/Creational/DesignPatterns.FactoryMethod/DesignPatterns.FactoryMethod.csproj b/Creational/DesignPatterns.FactoryMethod/DesignPatterns.FactoryMethod.csproj new file mode 100644 index 0000000..8a1420b --- /dev/null +++ b/Creational/DesignPatterns.FactoryMethod/DesignPatterns.FactoryMethod.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Creational/DesignPatterns.FactoryMethod/IFileDownloader.cs b/Creational/DesignPatterns.FactoryMethod/IFileDownloader.cs new file mode 100644 index 0000000..bf3c6ec --- /dev/null +++ b/Creational/DesignPatterns.FactoryMethod/IFileDownloader.cs @@ -0,0 +1,6 @@ +namespace DesignPatterns.FactoryMethod; + +public interface IFileDownloader +{ + void DownloadFile(string fileName, string destinationPath); +} diff --git a/Creational/DesignPatterns.FactoryMethod/IFileUploader.cs b/Creational/DesignPatterns.FactoryMethod/IFileUploader.cs new file mode 100644 index 0000000..ee0cbd9 --- /dev/null +++ b/Creational/DesignPatterns.FactoryMethod/IFileUploader.cs @@ -0,0 +1,6 @@ +namespace DesignPatterns.FactoryMethod; + +public interface IFileUploader +{ + void UploadFile(string filePath); +} diff --git a/Creational/DesignPatterns.FactoryMethod/IStorageServiceFactory.cs b/Creational/DesignPatterns.FactoryMethod/IStorageServiceFactory.cs new file mode 100644 index 0000000..32bbf66 --- /dev/null +++ b/Creational/DesignPatterns.FactoryMethod/IStorageServiceFactory.cs @@ -0,0 +1,7 @@ +namespace DesignPatterns.FactoryMethod; + +public interface IStorageServiceFactory +{ + IFileUploader CreateUploader(); + IFileDownloader CreateDownloader(); +} diff --git a/DesignPatterns.sln b/DesignPatterns.sln index 1312456..9288388 100644 --- a/DesignPatterns.sln +++ b/DesignPatterns.sln @@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns.Singleton", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns.Singleton.UnitTests", "Creational\DesignPatterns.Singleton.UnitTests\DesignPatterns.Singleton.UnitTests.csproj", "{FFB0861F-5182-40CA-BD19-33BCB0FBA4F6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns.FactoryMethod", "Creational\DesignPatterns.FactoryMethod\DesignPatterns.FactoryMethod.csproj", "{DAE417C1-F239-4514-9689-6466F0B52A99}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -54,6 +56,10 @@ Global {FFB0861F-5182-40CA-BD19-33BCB0FBA4F6}.Debug|Any CPU.Build.0 = Debug|Any CPU {FFB0861F-5182-40CA-BD19-33BCB0FBA4F6}.Release|Any CPU.ActiveCfg = Release|Any CPU {FFB0861F-5182-40CA-BD19-33BCB0FBA4F6}.Release|Any CPU.Build.0 = Release|Any CPU + {DAE417C1-F239-4514-9689-6466F0B52A99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DAE417C1-F239-4514-9689-6466F0B52A99}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DAE417C1-F239-4514-9689-6466F0B52A99}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DAE417C1-F239-4514-9689-6466F0B52A99}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {DCE06EB6-BAB5-4573-AF67-128DBCCDB90C} = {7FF0E83F-EBEB-4103-BCD1-2F100E82FCD1} @@ -63,5 +69,6 @@ Global {FA3C4F09-104E-4F7D-9ADB-E7F22917ADF7} = {5961ADCC-5FA6-4076-A9F4-C1D3207ABE1A} {658DB1C6-AC85-4E03-99C4-C79116E558F5} = {AE005ED4-5F0B-4AF9-81AE-AAE3AD6F8901} {FFB0861F-5182-40CA-BD19-33BCB0FBA4F6} = {AE005ED4-5F0B-4AF9-81AE-AAE3AD6F8901} + {DAE417C1-F239-4514-9689-6466F0B52A99} = {AE005ED4-5F0B-4AF9-81AE-AAE3AD6F8901} EndGlobalSection EndGlobal