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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
[![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/)
[![Build Status](https://geeklearning.visualstudio.com/_apis/public/build/definitions/f841b266-7595-4d01-9ee1-4864cf65aa73/5/badge)](#)
# gl-dotnet-storage

# gl-dotnet-storage

Expand Down
31 changes: 18 additions & 13 deletions src/GeekLearning.Storage.Azure/AzureStore.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace GeekLearning.Storage.Azure
namespace GeekLearning.Storage.Azure
{
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

public class AzureStore : IStore
{
private string connectionString;
private Lazy<CloudBlobContainer> container;
private Lazy<CloudBlobClient> client;
private string containerName;


public AzureStore(string connectionString, string containerName)
{
if (string.IsNullOrWhiteSpace(connectionString))
Expand Down Expand Up @@ -54,13 +53,13 @@ private Task<ICloudBlob> GetBlobReference(string path)
if (uri.IsAbsoluteUri)
{
return this.client.Value.GetBlobReferenceFromServerAsync(uri);
} else
}
else
{
return this.container.Value.GetBlobReferenceFromServerAsync(path);
}
}


public async Task<Stream> Read(string path)
{
return await this.ReadInMemory(path);
Expand All @@ -78,7 +77,7 @@ public async Task<string> ReadAllText(string path)
using (var reader = new StreamReader(await blockBlob.OpenReadAsync(AccessCondition.GenerateEmptyCondition(), new BlobRequestOptions(), new OperationContext())))
{
return await reader.ReadToEndAsync();
};
}
}

public async Task<string> Save(Stream data, string path, string mimeType)
Expand All @@ -103,6 +102,11 @@ public async Task<string> Save(byte[] data, string path, string mimeType)

public async Task<string[]> List(string path)
{
if (path.EndsWith("*"))
{
path = path.TrimEnd('*');
}

BlobContinuationToken continuationToken = null;
List<IListBlobItem> results = new List<IListBlobItem>();
do
Expand All @@ -112,6 +116,7 @@ public async Task<string[]> List(string path)
results.AddRange(response.Results);
}
while (continuationToken != null);

return results.Select(blob => blob.Uri.ToString()).ToArray();
}

Expand Down
2 changes: 1 addition & 1 deletion src/GeekLearning.Storage.Azure/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "0.0.1-*",
"description": "GeekLearning.Storage.Azure Class Library",
"authors": [ "autex" ],
"authors": [ "Geek Learning", "Cyprien Autexier", "Adrien Siffermann" ],
"packOptions": {
"tags": [ ],
"projectUrl": "",
Expand Down
23 changes: 13 additions & 10 deletions src/GeekLearning.Storage.FileSystem/FileSystemStore.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace GeekLearning.Storage.FileSystem
namespace GeekLearning.Storage.FileSystem
{
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

public class FileSystemStore : IStore
{
private string absolutePath;

public FileSystemStore(string path, string appPath)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
if (System.IO.Path.IsPathRooted(path))

if (Path.IsPathRooted(path))
{
this.absolutePath = path;
}
Expand All @@ -41,9 +42,10 @@ public Task<string[]> List(string path)
var directoryPath = Path.GetDirectoryName(Path.Combine(this.absolutePath, path));
if (!Directory.Exists(directoryPath))
{
return Task.FromResult(new string[0]);
return Task.FromResult(new string[0]);
}
return Task.FromResult(Directory.GetFiles(directoryPath).Select(x => x.Replace(this.absolutePath, "")).ToArray());

return Task.FromResult(Directory.GetFiles(directoryPath).Select(x => x.Replace(this.absolutePath, "").Trim('/', '\\')).ToArray());
}

public Task<Stream> Read(string path)
Expand All @@ -68,6 +70,7 @@ public async Task<string> Save(Stream data, string path, string mimeType)
{
await data.CopyToAsync(file);
}

return path;
}

Expand Down
2 changes: 1 addition & 1 deletion src/GeekLearning.Storage.FileSystem/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "0.0.1-*",
"description": "GeekLearning.Storage.FileSystem Class Library",
"authors": [ "autex" ],
"authors": [ "Geek Learning", "Cyprien Autexier", "Adrien Siffermann" ],
"packOptions": {
"tags": [ ],
"projectUrl": "",
Expand Down
2 changes: 1 addition & 1 deletion src/GeekLearning.Storage/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "0.0.1-*",
"description": "GeekLearning.Storage Class Library",
"authors": [ "autex" ],
"authors": [ "Geek Learning", "Cyprien Autexier", "Adrien Siffermann" ],
"packOptions": {
"tags": [ ],
"projectUrl": "",
Expand Down