Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
manjunathg88 authored Jan 9, 2024
1 parent 3b3a561 commit 1b6447a
Show file tree
Hide file tree
Showing 74 changed files with 15,333 additions and 0 deletions.
13 changes: 13 additions & 0 deletions AzureBlobUtilitySolution/AzureBlobUtility/AzureBlobUtility.csproj
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 AzureBlobUtilitySolution/AzureBlobUtility/AzureBlobUtility.sln
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
80 changes: 80 additions & 0 deletions AzureBlobUtilitySolution/AzureBlobUtility/BlobUtility.cs
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);
}
}
}
9 changes: 9 additions & 0 deletions AzureBlobUtilitySolution/AzureBlobUtility/IBlobUtility.cs
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);
}
}
Loading

0 comments on commit 1b6447a

Please sign in to comment.