-
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
89433ce
commit dbb9a53
Showing
21 changed files
with
206 additions
and
56 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
Creational/DesignPatterns.AbstractFactory/DataLake/Directory.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,8 @@ | ||
namespace DesignPatterns.AbstractFactory.DataLake; | ||
|
||
public class Directory : IPathInfo | ||
{ | ||
public string Name { get; init; } | ||
public string Path { get; init; } | ||
public string Uri { get; init; } | ||
} |
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,8 @@ | ||
namespace DesignPatterns.AbstractFactory.DataLake; | ||
|
||
public class File : IPathInfo | ||
{ | ||
public string Name { get; init; } | ||
public string Path { get; init; } | ||
public string Uri { get; init; } | ||
} |
51 changes: 51 additions & 0 deletions
51
Creational/DesignPatterns.AbstractFactory/DataLake/Storage.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,51 @@ | ||
using Azure.Storage.Files.DataLake; | ||
|
||
namespace DesignPatterns.AbstractFactory.DataLake; | ||
|
||
public class Storage : IStorage | ||
{ | ||
private readonly StorageSettings settings; | ||
private readonly DataLakeServiceClient dataLakeServiceClient; | ||
|
||
public Storage(StorageSettings settings, DataLakeServiceClient dataLakeServiceClient) | ||
{ | ||
this.settings = settings; | ||
this.dataLakeServiceClient = dataLakeServiceClient; | ||
} | ||
|
||
public async Task<IPathInfo> CreateDirectory(string name) | ||
{ | ||
var fileSystemClient = this.dataLakeServiceClient.GetFileSystemClient(this.settings.FileSystemName); | ||
await fileSystemClient.CreateIfNotExistsAsync(); | ||
var response = await fileSystemClient.CreateDirectoryAsync(name); | ||
if (!response.HasValue) | ||
{ | ||
throw new DirectoryNotFoundException($"Could not create the '{name}' directory."); | ||
} | ||
|
||
return new Directory | ||
{ | ||
Name = response.Value.Name, | ||
Path = response.Value.Path, | ||
Uri = response.Value.Path | ||
}; | ||
} | ||
|
||
public async Task<IPathInfo> CreateFile(string name) | ||
{ | ||
var fileSystemClient = this.dataLakeServiceClient.GetFileSystemClient(this.settings.FileSystemName); | ||
await fileSystemClient.CreateIfNotExistsAsync(); | ||
var response = await fileSystemClient.CreateFileAsync(name); | ||
if (!response.HasValue) | ||
{ | ||
throw new FileNotFoundException($"Could not create the '{name}' file."); | ||
} | ||
|
||
return new File | ||
{ | ||
Name = response.Value.Name, | ||
Path = response.Value.Path, | ||
Uri = response.Value.Path | ||
}; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Creational/DesignPatterns.AbstractFactory/DataLake/StorageFactory.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.Files.DataLake; | ||
|
||
namespace DesignPatterns.AbstractFactory.DataLake; | ||
|
||
public class StorageFactory : IStorageFactory | ||
{ | ||
private readonly StorageSettings settings; | ||
private readonly DataLakeServiceClient serviceClient; | ||
|
||
public StorageFactory(StorageSettings settings, DataLakeServiceClient serviceClient) | ||
{ | ||
this.settings = settings; | ||
this.serviceClient = serviceClient; | ||
} | ||
|
||
public IStorage Create() | ||
{ | ||
return new Storage(settings, serviceClient); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Creational/DesignPatterns.AbstractFactory/DataLake/StorageSettings.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,6 @@ | ||
namespace DesignPatterns.AbstractFactory.DataLake; | ||
|
||
public class StorageSettings | ||
{ | ||
public string FileSystemName { get; init; } | ||
} |
14 changes: 0 additions & 14 deletions
14
Creational/DesignPatterns.AbstractFactory/DataLakeStorage.cs
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.AbstractFactory; | ||
|
||
public interface IPathInfo | ||
{ | ||
string Name { get; } | ||
string Path { get; } | ||
} |
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
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
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.AbstractFactory.Local; | ||
|
||
public class Directory : IPathInfo | ||
{ | ||
public string Name { get; init; } | ||
public string Path { get; init; } | ||
} |
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.AbstractFactory.Local; | ||
|
||
public class File : IPathInfo | ||
{ | ||
public string Name { get; init; } | ||
public string Path { get; init; } | ||
} |
39 changes: 39 additions & 0 deletions
39
Creational/DesignPatterns.AbstractFactory/Local/Storage.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,39 @@ | ||
namespace DesignPatterns.AbstractFactory.Local; | ||
|
||
public class Storage : IStorage | ||
{ | ||
private readonly StorageSettings settings; | ||
|
||
public Storage(StorageSettings settings) | ||
{ | ||
this.settings = settings; | ||
} | ||
|
||
public Task<IPathInfo> CreateDirectory(string name) | ||
{ | ||
var directoryPath = Path.Combine(this.settings.Path, name); | ||
var directoryInfo = new DirectoryInfo(directoryPath); | ||
directoryInfo.Create(); | ||
var result = new Directory | ||
{ | ||
Name = directoryInfo.Name, | ||
Path = directoryInfo.FullName | ||
}; | ||
|
||
return Task.FromResult<IPathInfo>(result); | ||
} | ||
|
||
public Task<IPathInfo> CreateFile(string name) | ||
{ | ||
var filePath = Path.Combine(this.settings.Path, name); | ||
var fileInfo = new FileInfo(filePath); | ||
fileInfo.Create(); | ||
var result = new File | ||
{ | ||
Name = fileInfo.Name, | ||
Path = fileInfo.FullName | ||
}; | ||
|
||
return Task.FromResult<IPathInfo>(result); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Creational/DesignPatterns.AbstractFactory/Local/StorageFactory.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,16 @@ | ||
namespace DesignPatterns.AbstractFactory.Local; | ||
|
||
public class StorageFactory : IStorageFactory | ||
{ | ||
private readonly StorageSettings settings; | ||
|
||
public StorageFactory(StorageSettings settings) | ||
{ | ||
this.settings = settings; | ||
} | ||
|
||
public IStorage Create() | ||
{ | ||
return new Storage(this.settings); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Creational/DesignPatterns.AbstractFactory/Local/StorageSettings.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,6 @@ | ||
namespace DesignPatterns.AbstractFactory.Local; | ||
|
||
public class StorageSettings | ||
{ | ||
public string Path { get; init; } | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
Console.WriteLine("Hello, World!"); | ||
var host = Host.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration(ctx => ctx.AddJsonFile("appsettings.json")) | ||
.ConfigureServices(services => { }) | ||
.Build(); | ||
|
||
Console.WriteLine(); |
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,8 @@ | ||
{ | ||
"DataLake": { | ||
"FileSystemName": "abstract-factory-example" | ||
}, | ||
"Local": { | ||
"Path": "/home" | ||
} | ||
} |