-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better sample
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 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,6 +1,6 @@ | ||
{ | ||
"projects": [ "src", "tests", "samples" ], | ||
"sdk": { | ||
"version": "1.0.0-preview2-003121" | ||
"version": "1.0.0-preview2-003133" | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
samples/GeekLearning.Storage.BasicSample/Controllers/SampleController.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,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Text; | ||
|
||
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860 | ||
|
||
namespace GeekLearning.Storage.BasicSample.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class SampleController : Controller | ||
{ | ||
private IStore sharedAssets; | ||
|
||
public SampleController(IStorageFactory storageFactory) | ||
{ | ||
this.sharedAssets = storageFactory.GetStore("SharedAssets"); | ||
} | ||
|
||
// GET: api/values | ||
[HttpGet] | ||
public async Task<IEnumerable<string>> Get() | ||
{ | ||
var summaries = await this.sharedAssets.ListAsync("summaries", "*.txt", recursive: true, withMetadata: false); | ||
return summaries.Select(x => x.Path); | ||
} | ||
|
||
// GET api/values/5 | ||
[HttpGet] | ||
public async Task<string> Get(string path) | ||
{ | ||
var summary = await this.sharedAssets.GetAsync(path); | ||
return await summary.ReadAllTextAsync(); | ||
} | ||
|
||
// PUT api/values/5 | ||
[HttpPut()] | ||
public async Task Put(string path, [FromBody]string value) | ||
{ | ||
await sharedAssets.SaveAsync(Encoding.UTF8.GetBytes(value), path, "text/plain"); | ||
} | ||
|
||
// DELETE api/values/5 | ||
[HttpDelete()] | ||
public async Task Delete(string path) | ||
{ | ||
await sharedAssets.DeleteAsync(path); | ||
} | ||
} | ||
} |
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