-
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.
* s3 storage Implementation * S3 Storage sample * fix readme
- Loading branch information
Showing
15 changed files
with
637 additions
and
107 deletions.
There are no files selected for viewing
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,82 +1,96 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Skidbladnir.Storage.GridFsStorage.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Storage.GridFsStorage.Sample", | ||
"program": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.GridFsStorage.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Storage.GridFsStorage.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.GridFsStorage.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Storage.LocalFileStorage.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Storage.LocalFileStorage.Sample", | ||
"program": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.LocalFileStorage.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Storage.LocalFileStorage.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.LocalFileStorage.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Storage.WebDav.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Storage.WebDav.Sample", | ||
"program": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.WebDav.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Storage.WebDav.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.WebDav.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbkadnir.Repository.EntityFrameworkCore.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbkadnir.Repository.EntityFrameworkCore.Sample", | ||
"program": "${workspaceFolder}/samples/Repository/Skidbkadnir.Repository.EntityFrameworkCore.Sample/bin/Debug/netcoreapp3.1/Skidbkadnir.Repository.EntityFrameworkCore.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Repository/Skidbkadnir.Repository.EntityFrameworkCore.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Modules.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Modules.Sample", | ||
"program": "${workspaceFolder}/samples/Modules/Skidbladnir.Modules.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Modules.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Modules/Skidbladnir.Modules.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Messaging.Redis.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Messaging.Redis.Sample", | ||
"program": "${workspaceFolder}/samples/Messaging/Skidbladnir.Messaging.Redis.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Messaging.Redis.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Messaging/Skidbladnir.Messaging.Redis.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Client.Freenom.Dns.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Client.Freenom.Dns.Sample", | ||
"program": "${workspaceFolder}/samples/Client/Skidbladnir.Client.Freenom.Dns.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Client.Freenom.Dns.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Client/Skidbladnir.Client.Freenom.Dns.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
} | ||
] | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Skidbladnir.Storage.GridFsStorage.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Storage.GridFsStorage.Sample", | ||
"program": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.GridFsStorage.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Storage.GridFsStorage.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.GridFsStorage.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Storage.LocalFileStorage.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Storage.LocalFileStorage.Sample", | ||
"program": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.LocalFileStorage.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Storage.LocalFileStorage.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.LocalFileStorage.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Storage.WebDav.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Storage.WebDav.Sample", | ||
"program": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.WebDav.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Storage.WebDav.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.WebDav.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbkadnir.Repository.EntityFrameworkCore.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbkadnir.Repository.EntityFrameworkCore.Sample", | ||
"program": "${workspaceFolder}/samples/Repository/Skidbkadnir.Repository.EntityFrameworkCore.Sample/bin/Debug/netcoreapp3.1/Skidbkadnir.Repository.EntityFrameworkCore.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Repository/Skidbkadnir.Repository.EntityFrameworkCore.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Modules.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Modules.Sample", | ||
"program": "${workspaceFolder}/samples/Modules/Skidbladnir.Modules.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Modules.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Modules/Skidbladnir.Modules.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Messaging.Redis.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Messaging.Redis.Sample", | ||
"program": "${workspaceFolder}/samples/Messaging/Skidbladnir.Messaging.Redis.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Messaging.Redis.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Messaging/Skidbladnir.Messaging.Redis.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Client.Freenom.Dns.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Client.Freenom.Dns.Sample", | ||
"program": "${workspaceFolder}/samples/Client/Skidbladnir.Client.Freenom.Dns.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Client.Freenom.Dns.Sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/samples/Client/Skidbladnir.Client.Freenom.Dns.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
}, | ||
{ | ||
"name": "Skidbladnir.Storage.S3.Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build-Skidbladnir.Storage.S3.Sample", | ||
"program": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.S3.Sample/bin/Debug/netcoreapp3.1/Skidbladnir.Storage.S3.Sample.dll", | ||
"args": [], | ||
"env": { | ||
"DOTNET_ENVIRONMENT": "Development" | ||
}, | ||
"cwd": "${workspaceFolder}/samples/Storage/Skidbladnir.Storage.S3.Sample", | ||
"stopAtEntry": false, | ||
"console": "internalConsole" | ||
} | ||
] | ||
} |
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
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,24 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Skidbladnir.Modules; | ||
|
||
namespace Skidbladnir.Storage.S3.Sample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.UseSkidbladnirModules<StartupModule>(configuration => | ||
{ | ||
var storageConfiguration = new S3StorageConfiguration(); | ||
configuration.AppConfiguration.GetSection("Storage").Bind(storageConfiguration); | ||
configuration.Add(storageConfiguration); | ||
}); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
samples/Storage/Skidbladnir.Storage.S3.Sample/Skidbladnir.Storage.S3.Sample.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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<UserSecretsId>331ba4d8-efbc-4df6-ac78-d12ab711db05</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.10" /> | ||
|
||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.10" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Modules\Skidbladnir.Modules\Skidbladnir.Modules.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Storage\Skidbladnir.Storage.Abstractions\Skidbladnir.Storage.Abstractions.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Storage\Skidbladnir.Storage.S3\Skidbladnir.Storage.S3.csproj" /> | ||
</ItemGroup> | ||
</Project> |
107 changes: 107 additions & 0 deletions
107
samples/Storage/Skidbladnir.Storage.S3.Sample/StartupModule.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,107 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Skidbladnir.Modules; | ||
using Skidbladnir.Storage.Abstractions; | ||
using FileInfo = Skidbladnir.Storage.Abstractions.FileInfo; | ||
namespace Skidbladnir.Storage.S3.Sample | ||
{ | ||
public class StartupModule : RunnableModule | ||
{ | ||
private ILogger<StartupModule> _logger; | ||
private IStorage<S3StorageInfo> _storage; | ||
|
||
public override void Configure(IServiceCollection services) | ||
{ | ||
var storageConfiguration = Configuration.Get<S3StorageConfiguration>(); | ||
services.AddS3Storage(storageConfiguration); | ||
} | ||
|
||
public override async Task StartAsync(IServiceProvider provider, CancellationToken cancellationToken) | ||
{ | ||
_logger = provider.GetService<ILogger<StartupModule>>(); | ||
_storage = provider.GetService<IStorage<S3StorageInfo>>(); | ||
try | ||
{ | ||
var testString = $"This is a test text for write to file {DateTime.UtcNow}"; | ||
var testBinary = Encoding.UTF8.GetBytes(testString); | ||
|
||
var currentDir = await _storage.GetFilesAsync(""); | ||
_logger.LogInformation("Files in root dir"); | ||
foreach (var fileInfo in currentDir) | ||
{ | ||
_logger.LogInformation("Filename: {FileName}\t\t Length: {Length}\t\t Date: {Date}", | ||
fileInfo.FileName, | ||
fileInfo.Size, fileInfo.CreatedDate); | ||
await DownloadFileAndPrint(fileInfo); | ||
} | ||
|
||
_logger.LogInformation("upload file:"); | ||
var testFileUploadStream = new MemoryStream(testBinary); | ||
var uploadFileinfo = await _storage.UploadFileAsync(testFileUploadStream, "testFile.txt"); | ||
_logger.LogInformation("Filename: {FileName}\t\t Length: {Length}\t\t Date: {Date}", | ||
uploadFileinfo.FileName, | ||
uploadFileinfo.Size, uploadFileinfo.CreatedDate); | ||
|
||
_logger.LogInformation("copy file"); | ||
await _storage.CopyAsync(uploadFileinfo.FilePath, $"{uploadFileinfo.FilePath}.new"); | ||
await _storage.CopyAsync(uploadFileinfo.FilePath, | ||
$"newFolder{Path.DirectorySeparatorChar}{uploadFileinfo.FilePath}.new"); | ||
|
||
_logger.LogInformation("move file"); | ||
await _storage.MoveAsync($"{uploadFileinfo.FilePath}.new", $"{uploadFileinfo.FilePath}.backup"); | ||
await _storage.CopyAsync($"{uploadFileinfo.FilePath}.backup", $"very/long/sub/dir/path/{uploadFileinfo.FilePath}"); | ||
|
||
_logger.LogInformation("remove base file"); | ||
await _storage.DeleteAsync(uploadFileinfo.FilePath); | ||
|
||
_logger.LogInformation("Files in root dir"); | ||
currentDir = await _storage.GetFilesAsync(""); | ||
foreach (var fileInfo in currentDir) | ||
{ | ||
_logger.LogInformation("Filename: {FileName}\t\t Length: {Length}\t\t Date: {Date}", | ||
fileInfo.FileName, | ||
fileInfo.Size, fileInfo.CreatedDate); | ||
await DownloadFileAndPrint(fileInfo); | ||
} | ||
|
||
_logger.LogInformation("Files in newFolder dir"); | ||
currentDir = await _storage.GetFilesAsync("newFolder"); | ||
foreach (var fileInfo in currentDir) | ||
{ | ||
_logger.LogInformation("Filename: {FileName}\t\t Length: {Length}\t\t Date: {Date}", | ||
fileInfo.FileName, | ||
fileInfo.Size, fileInfo.CreatedDate); | ||
await DownloadFileAndPrint(fileInfo); | ||
} | ||
|
||
_logger.LogInformation("Files in very/long/sub/dir/path/ dir"); | ||
currentDir = await _storage.GetFilesAsync("very/long/sub/dir/path/"); | ||
foreach (var fileInfo in currentDir) | ||
{ | ||
_logger.LogInformation("Filename: {FileName}\t\t Length: {Length}\t\t Date: {Date}", | ||
fileInfo.FileName, | ||
fileInfo.Size, fileInfo.CreatedDate); | ||
await DownloadFileAndPrint(fileInfo); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError(e, "Error in storage sample"); | ||
} | ||
} | ||
|
||
private async Task DownloadFileAndPrint(FileInfo info) | ||
{ | ||
var result = await _storage.DownloadFileAsync(info.FilePath); | ||
await using var fileStream = result.Content; | ||
using var streamReader = new StreamReader(fileStream); | ||
var fileContent = await streamReader.ReadToEndAsync(); | ||
_logger.LogInformation("File Content: {Content}", fileContent); | ||
} | ||
} | ||
} |
Oops, something went wrong.