Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![NuGet Version](http://img.shields.io/nuget/v/GeekLearning.Storage.svg?style=flat-square&label=nuget:%20primitives)](https://www.nuget.org/packages/GeekLearning.Storage/)
[![NuGet Version](http://img.shields.io/nuget/v/GeekLearning.Storage.FileSystem.svg?style=flat-square&label=nuget:%20filesystem)](https://www.nuget.org/packages/GeekLearning.Storage.FileSystem/)
[![NuGet Version](http://img.shields.io/nuget/v/GeekLearning.Storage.Azure.svg?style=flat-square&label=nuget:%20azure%20 storage)](https://www.nuget.org/packages/GeekLearning.Storage.Azure/)
[![NuGet Version](http://img.shields.io/nuget/v/GeekLearning.Storage.svg?style=flat-square&label=NuGet:%20Abstractions)](https://www.nuget.org/packages/GeekLearning.Storage/)
[![NuGet Version](http://img.shields.io/nuget/v/GeekLearning.Storage.FileSystem.svg?style=flat-square&label=NuGet:%20FileSystem)](https://www.nuget.org/packages/GeekLearning.Storage.FileSystem/)
[![NuGet Version](http://img.shields.io/nuget/v/GeekLearning.Storage.Azure.svg?style=flat-square&label=NuGet:%20Azure%20Storage)](https://www.nuget.org/packages/GeekLearning.Storage.Azure/)
[![Build Status](https://geeklearning.visualstudio.com/_apis/public/build/definitions/f841b266-7595-4d01-9ee1-4864cf65aa73/27/badge)](#)

# Geek Learning Cloud Storage Abstraction
Expand All @@ -26,3 +26,4 @@ We don't support for Amazon S3, but it is one of our high priority objective.

You can head to our introduction [blog post](http://geeklearning.io/dotnet-core-storage-cloud-or-file-system-storage-made-easy/),
or to the [wiki](https://github.com/geeklearningio/gl-dotnet-storage/wiki).

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>GeekLearning.Storage.BasicSample</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>GeekLearning.Storage.BasicSample</PackageId>
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion>1.1.2</RuntimeFrameworkVersion>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8</PackageTargetFallback>
</PropertyGroup>

Expand All @@ -24,17 +24,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.2" />
</ItemGroup>

</Project>
7 changes: 3 additions & 4 deletions samples/GeekLearning.Storage.BasicSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ public void ConfigureServices(IServiceCollection services)
byte[] signingKey = new byte[512];
rng.GetBytes(signingKey);

services.AddStorage()
services.AddStorage(this.Configuration.GetSection("Storage"))
.AddAzureStorage()
.AddFileSystemStorage(HostingEnvironement.ContentRootPath)
.AddFileSystemStorageServer(options=> {
.AddFileSystemStorageServer(options =>
{
options.SigningKey = signingKey;
options.BaseUri = new Uri("http://localhost:11149/");
});

services.Configure<StorageOptions>(Configuration.GetSection("Storage"));

services.AddScoped<TemplatesStore>();
}
Expand Down
7 changes: 2 additions & 5 deletions samples/GeekLearning.Storage.BasicSample/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
"Storage": {
"Stores": {
"Templates": {
"Provider": "FileSystem",
"Parameters": {
"Path": "Templates",
"Access" : "Public"
}
"ProviderType": "FileSystem",
"AccessLevel": "Public"
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/GeekLearning.Storage.Azure/AzureStorageExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
namespace GeekLearning.Storage
{
using Azure;
using GeekLearning.Storage.Azure.Configuration;
using GeekLearning.Storage.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;

public static class AzureStorageExtensions
{
public static IServiceCollection AddAzureStorage(this IServiceCollection services)
{
return services
.AddSingleton<IConfigureOptions<AzureParsedOptions>, ConfigureProviderOptions<AzureParsedOptions, AzureProviderInstanceOptions, AzureStoreOptions, AzureScopedStoreOptions>>()
.AddAzureStorageServices();
}

private static IServiceCollection AddAzureStorageServices(this IServiceCollection services)
{
services.TryAddEnumerable(ServiceDescriptor.Transient<IStorageProvider, AzureStorageProvider>());
return services;
Expand Down
16 changes: 0 additions & 16 deletions src/GeekLearning.Storage.Azure/AzureStorageManagerOptions.cs

This file was deleted.

18 changes: 14 additions & 4 deletions src/GeekLearning.Storage.Azure/AzureStorageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
namespace GeekLearning.Storage.Azure
{
using GeekLearning.Storage.Azure.Configuration;
using GeekLearning.Storage.Internal;
using Microsoft.Extensions.Options;
using Storage;

public class AzureStorageProvider : IStorageProvider
public class AzureStorageProvider : StorageProviderBase<AzureParsedOptions, AzureProviderInstanceOptions, AzureStoreOptions, AzureScopedStoreOptions>
{
public string Name => "Azure";
public const string ProviderName = "Azure";

public IStore BuildStore(string storeName, IStorageStoreOptions storeOptions)
public AzureStorageProvider(IOptions<AzureParsedOptions> options)
: base(options)
{
return new AzureStore(storeName, storeOptions.Parameters["ConnectionString"], storeOptions.Parameters["Container"]);
}

public override string Name => ProviderName;

protected override IStore BuildStoreInternal(string storeName, AzureStoreOptions storeOptions)
{
return new AzureStore(storeOptions);
}
}
}
41 changes: 27 additions & 14 deletions src/GeekLearning.Storage.Azure/AzureStore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace GeekLearning.Storage.Azure
{
using GeekLearning.Storage.Azure.Configuration;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Core;
Expand All @@ -11,29 +12,41 @@

public class AzureStore : IStore
{
private Lazy<CloudBlobClient> client;
private Lazy<CloudBlobContainer> container;
private readonly AzureStoreOptions storeOptions;
private readonly Lazy<CloudBlobClient> client;
private readonly Lazy<CloudBlobContainer> container;

public AzureStore(string storeName, string connectionString, string containerName)
public AzureStore(AzureStoreOptions storeOptions)
{
this.Name = storeName;
storeOptions.Validate();

if (string.IsNullOrWhiteSpace(connectionString))
{
throw new ArgumentNullException("connectionString");
}
this.storeOptions = storeOptions;
this.client = new Lazy<CloudBlobClient>(() => CloudStorageAccount.Parse(storeOptions.ConnectionString).CreateCloudBlobClient());
this.container = new Lazy<CloudBlobContainer>(() => this.client.Value.GetContainerReference(storeOptions.FolderName));
}

if (string.IsNullOrWhiteSpace(containerName))
public string Name => this.storeOptions.Name;

public Task InitAsync()
{
BlobContainerPublicAccessType accessType;
switch (this.storeOptions.AccessLevel)
{
throw new ArgumentNullException("containerName");
case Storage.Configuration.AccessLevel.Public:
accessType = BlobContainerPublicAccessType.Container;
break;
case Storage.Configuration.AccessLevel.Confidential:
accessType = BlobContainerPublicAccessType.Blob;
break;
case Storage.Configuration.AccessLevel.Private:
default:
accessType = BlobContainerPublicAccessType.Off;
break;
}

this.client = new Lazy<CloudBlobClient>(() => CloudStorageAccount.Parse(connectionString).CreateCloudBlobClient());
this.container = new Lazy<CloudBlobContainer>(() => this.client.Value.GetContainerReference(containerName));
return this.container.Value.CreateIfNotExistsAsync(accessType, null, null);
}

public string Name { get; }

public async Task<IFileReference[]> ListAsync(string path, bool recursive, bool withMetadata)
{
if (string.IsNullOrWhiteSpace(path))
Expand Down
63 changes: 63 additions & 0 deletions src/GeekLearning.Storage.Azure/Configuration/AzureParsedOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace GeekLearning.Storage.Azure.Configuration
{
using GeekLearning.Storage.Configuration;
using System.Collections.Generic;

public class AzureParsedOptions : IParsedOptions<AzureProviderInstanceOptions, AzureStoreOptions, AzureScopedStoreOptions>
{
public string Name => AzureStorageProvider.ProviderName;

public IReadOnlyDictionary<string, string> ConnectionStrings { get; set; }

public IReadOnlyDictionary<string, AzureProviderInstanceOptions> ParsedProviderInstances { get; set; }

public IReadOnlyDictionary<string, AzureStoreOptions> ParsedStores { get; set; }

public IReadOnlyDictionary<string, AzureScopedStoreOptions> ParsedScopedStores { get; set; }

public void BindProviderInstanceOptions(AzureProviderInstanceOptions providerInstanceOptions)
{
if (!string.IsNullOrEmpty(providerInstanceOptions.ConnectionStringName)
&& string.IsNullOrEmpty(providerInstanceOptions.ConnectionString))
{
if (!this.ConnectionStrings.ContainsKey(providerInstanceOptions.ConnectionStringName))
{
throw new Exceptions.BadProviderConfiguration(
providerInstanceOptions.Name,
$"The ConnectionString '{providerInstanceOptions.ConnectionStringName}' cannot be found. Did you call AddStorage with the ConfigurationRoot?");
}

providerInstanceOptions.ConnectionString = this.ConnectionStrings[providerInstanceOptions.ConnectionStringName];
}
}

public void BindStoreOptions(AzureStoreOptions storeOptions, AzureProviderInstanceOptions providerInstanceOptions = null)
{
storeOptions.FolderName = storeOptions.FolderName.ToLowerInvariant();

if (!string.IsNullOrEmpty(storeOptions.ConnectionStringName)
&& string.IsNullOrEmpty(storeOptions.ConnectionString))
{
if (!this.ConnectionStrings.ContainsKey(storeOptions.ConnectionStringName))
{
throw new Exceptions.BadStoreConfiguration(
storeOptions.Name,
$"The ConnectionString '{storeOptions.ConnectionStringName}' cannot be found. Did you call AddStorage with the ConfigurationRoot?");
}

storeOptions.ConnectionString = this.ConnectionStrings[storeOptions.ConnectionStringName];
}

if (providerInstanceOptions == null
|| storeOptions.ProviderName != providerInstanceOptions.Name)
{
return;
}

if (string.IsNullOrEmpty(storeOptions.ConnectionString))
{
storeOptions.ConnectionString = providerInstanceOptions.ConnectionString;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace GeekLearning.Storage.Azure.Configuration
{
using GeekLearning.Storage.Configuration;

public class AzureProviderInstanceOptions : ProviderInstanceOptions
{
public string ConnectionString { get; set; }

public string ConnectionStringName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GeekLearning.Storage.Azure.Configuration
{
using GeekLearning.Storage.Configuration;

public class AzureScopedStoreOptions : AzureStoreOptions, IScopedStoreOptions
{
public string FolderNameFormat { get; set; }
}
}
32 changes: 32 additions & 0 deletions src/GeekLearning.Storage.Azure/Configuration/AzureStoreOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace GeekLearning.Storage.Azure.Configuration
{
using GeekLearning.Storage.Configuration;
using System.Collections.Generic;
using System.Linq;

public class AzureStoreOptions : StoreOptions
{
public string ConnectionString { get; set; }

public string ConnectionStringName { get; set; }

public override IEnumerable<IOptionError> Validate(bool throwOnError = true)
{
var baseErrors = base.Validate(throwOnError);
var optionErrors = new List<OptionError>();

if (string.IsNullOrEmpty(this.ConnectionString))
{
this.PushMissingPropertyError(optionErrors, nameof(this.ConnectionString));
}

var finalErrors = baseErrors.Concat(optionErrors);
if (throwOnError && finalErrors.Any())
{
throw new Exceptions.BadStoreConfiguration(this.Name, finalErrors);
}

return finalErrors;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="1.1.0" />
<PackageReference Include="WindowsAzure.Storage" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="1.1.1" />
<PackageReference Include="WindowsAzure.Storage" Version="8.1.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
public class ExtendedPropertiesProvider : IExtendedPropertiesProvider
{
private readonly FileSystemExtendedPropertiesOptions options;
private readonly IStorageFactory storageFactory;

public ExtendedPropertiesProvider(
IOptions<FileSystemExtendedPropertiesOptions> options)
Expand Down
Loading