forked from Azure/azure-sdk-tools
-
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.
Milestone step for Azure#285: Capability to upload via file or text i…
…nput, and remove samples.
- Loading branch information
1 parent
606684d
commit 761a60e
Showing
10 changed files
with
181 additions
and
102 deletions.
There are no files selected for viewing
47 changes: 0 additions & 47 deletions
47
src/dotnet/APIView/APIViewWeb/Controllers/UsageSampleController.cs
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
src/dotnet/APIView/APIViewWeb/Models/UsageSampleFileModel.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,14 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
||
namespace APIViewWeb | ||
{ | ||
public class UsageSampleFileModel | ||
{ | ||
public string UsageSampleFileId { get; set; } = IdHelper.GenerateId(); | ||
|
||
public DateTime CreationDate { get; set; } = DateTime.Now; | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/dotnet/APIView/APIViewWeb/Models/UsageSampleUploadModel.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 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace APIViewWeb.Pages.Assemblies | ||
{ | ||
public class UsageSampleUploadModel | ||
{ | ||
[BindProperty] | ||
public string sampleString { get; set; } | ||
|
||
[BindProperty] | ||
public string ReviewId { get; set; } | ||
|
||
[BindProperty] | ||
public IFormFile File { get; set; } | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
src/dotnet/APIView/APIViewWeb/Repositories/BlobUsageSampleRepository.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 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Azure.Storage.Blobs; | ||
using Microsoft.Extensions.Configuration; | ||
using System.Text; | ||
|
||
namespace APIViewWeb | ||
{ | ||
public class BlobUsageSampleRepository | ||
{ | ||
private BlobContainerClient _container; | ||
|
||
public BlobUsageSampleRepository(IConfiguration configuration) | ||
{ | ||
var connectionString = configuration["Blob:ConnectionString"]; | ||
_container = new BlobContainerClient(connectionString, "usagesamples"); | ||
} | ||
|
||
public async Task<Stream> GetUsageSampleAsync(string sampleFileId) | ||
{ | ||
try | ||
{ | ||
var info = await GetBlobClient(sampleFileId).DownloadAsync(); | ||
return info.Value.Content; | ||
} | ||
catch | ||
{ | ||
await UploadUsageSampleAsync(sampleFileId, new MemoryStream(Encoding.UTF8.GetBytes("No Sample."))); | ||
var info = await GetBlobClient(sampleFileId).DownloadAsync(); | ||
return info.Value.Content; | ||
} | ||
} | ||
|
||
private BlobClient GetBlobClient(string sampleFileId) | ||
{ | ||
return _container.GetBlobClient(sampleFileId); | ||
} | ||
|
||
public async Task UploadUsageSampleAsync(string sampleFileId, Stream stream) | ||
{ | ||
await GetBlobClient(sampleFileId).UploadAsync(stream, overwrite:true); | ||
} | ||
|
||
public async Task DeleteUsageSampleAsync (string sampleFileId) | ||
{ | ||
await GetBlobClient(sampleFileId).DeleteAsync(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.