-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7973a53
commit f28540f
Showing
8 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
Creational/DesignPatterns.FactoryMethod/AzureStorageDownloader.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,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); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Creational/DesignPatterns.FactoryMethod/AzureStorageFactory.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,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); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Creational/DesignPatterns.FactoryMethod/AzureStorageUploader.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,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); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Creational/DesignPatterns.FactoryMethod/DesignPatterns.FactoryMethod.csproj
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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.17.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,6 @@ | ||
namespace DesignPatterns.FactoryMethod; | ||
|
||
public interface IFileDownloader | ||
{ | ||
void DownloadFile(string fileName, string destinationPath); | ||
} |
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,6 @@ | ||
namespace DesignPatterns.FactoryMethod; | ||
|
||
public interface IFileUploader | ||
{ | ||
void UploadFile(string filePath); | ||
} |
7 changes: 7 additions & 0 deletions
7
Creational/DesignPatterns.FactoryMethod/IStorageServiceFactory.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,7 @@ | ||
namespace DesignPatterns.FactoryMethod; | ||
|
||
public interface IStorageServiceFactory | ||
{ | ||
IFileUploader CreateUploader(); | ||
IFileDownloader CreateDownloader(); | ||
} |
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