-
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.
- Loading branch information
1 parent
3b3a561
commit 1b6447a
Showing
74 changed files
with
15,333 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
AzureBlobUtilitySolution/AzureBlobUtility/AzureBlobUtility.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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
31 changes: 31 additions & 0 deletions
31
AzureBlobUtilitySolution/AzureBlobUtility/AzureBlobUtility.sln
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,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.9.34414.90 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureBlobUtility", "AzureBlobUtility.csproj", "{5B0A4DBB-33D2-4DC0-A2F2-853DCAD79B67}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlobUtilityTest", "..\BlobUtilityTest\BlobUtilityTest.csproj", "{45F21C87-F539-4725-98F7-22C6DBD2F484}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5B0A4DBB-33D2-4DC0-A2F2-853DCAD79B67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5B0A4DBB-33D2-4DC0-A2F2-853DCAD79B67}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5B0A4DBB-33D2-4DC0-A2F2-853DCAD79B67}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5B0A4DBB-33D2-4DC0-A2F2-853DCAD79B67}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{45F21C87-F539-4725-98F7-22C6DBD2F484}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{45F21C87-F539-4725-98F7-22C6DBD2F484}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{45F21C87-F539-4725-98F7-22C6DBD2F484}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{45F21C87-F539-4725-98F7-22C6DBD2F484}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {20FB6F86-5B1D-421B-BBDA-B4300DEFB8E4} | ||
EndGlobalSection | ||
EndGlobal |
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,80 @@ | ||
using Microsoft.WindowsAzure.Storage.Blob; | ||
|
||
namespace AzureBlobUtility | ||
{ | ||
public class BlobUtility : IBlobUtility | ||
{ | ||
private readonly CloudBlobClient _cloudBlobClient; | ||
|
||
public BlobUtility(CloudBlobClient cloudBlobClient) | ||
{ | ||
_cloudBlobClient = cloudBlobClient; | ||
} | ||
|
||
public async Task<string> GetContent(string blobName, string container) | ||
{ | ||
string content = string.Empty; | ||
try | ||
{ | ||
var blobReference = GetContainerReference(blobName, container); | ||
|
||
if (blobReference != null) | ||
content = await blobReference.DownloadTextAsync(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw ex; | ||
} | ||
|
||
return content; | ||
} | ||
|
||
public async Task<bool> SaveContent(string blobName, string container, string content) | ||
{ | ||
try | ||
{ | ||
var blobReference = GetContainerReference(blobName, container); | ||
|
||
await blobReference.DeleteIfExistsAsync(); | ||
|
||
if (blobReference != null) | ||
await blobReference.UploadTextAsync(content); | ||
|
||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public async Task<List<string>> GetFileNames(string container, string path) | ||
{ | ||
var fileList = new List<string>(); | ||
|
||
try | ||
{ | ||
CloudBlobContainer containerReference = _cloudBlobClient.GetContainerReference(container); | ||
BlobResultSegment resultSegment = await containerReference.ListBlobsSegmentedAsync(path, true, new BlobListingDetails(), null, null, null, null); | ||
IEnumerable<IListBlobItem> files = resultSegment.Results; | ||
|
||
foreach (var file in files) | ||
{ | ||
fileList.Add(string.Concat(path + "/" + file.Uri.Segments.Last())); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw ex; | ||
} | ||
|
||
return fileList; | ||
} | ||
|
||
private CloudAppendBlob GetContainerReference(string blobName, string container) | ||
{ | ||
var containerReference = _cloudBlobClient.GetContainerReference(container); | ||
return containerReference.GetAppendBlobReference(blobName); | ||
} | ||
} | ||
} |
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,9 @@ | ||
namespace AzureBlobUtility | ||
{ | ||
public interface IBlobUtility | ||
{ | ||
Task<string> GetContent(string blobName, string container); | ||
Task<bool> SaveContent(string blobName, string container, string content); | ||
Task<List<string>> GetFileNames(string container, string path); | ||
} | ||
} |
Oops, something went wrong.