-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from twsouthwick/DSS-provider
Abstract file access pattern for DSS provider
- Loading branch information
Showing
11 changed files
with
175 additions
and
48 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Azure.Core; | ||
using Azure.Storage.Blobs; | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace WWTWebservices.Azure | ||
{ | ||
public class AzurePlateTilePyramid : IPlateTilePyramid | ||
{ | ||
private readonly Dictionary<string, (string container, string blob)> _plateNameMapping = new Dictionary<string, (string, string)>(StringComparer.OrdinalIgnoreCase) | ||
{ | ||
{ "dssterrapixel.plate", ("dss", "DSSTerraPixelL{0}X{1}Y{2}.png") } | ||
}; | ||
|
||
private readonly BlobServiceClient _service; | ||
private readonly ConcurrentDictionary<string, BlobContainerClient> _containers; | ||
|
||
public AzurePlateTilePyramid(string storageUri, TokenCredential credentials) | ||
{ | ||
_service = new BlobServiceClient(new Uri(storageUri), credentials); | ||
_containers = new ConcurrentDictionary<string, BlobContainerClient>(); | ||
} | ||
|
||
public Stream GetStream(string pathPrefix, string plateName, int level, int x, int y) | ||
{ | ||
var container = _containers.GetOrAdd(plateName, p => | ||
{ | ||
var name = GetBlobContainerName(plateName); | ||
return _service.GetBlobContainerClient(name); | ||
}); | ||
|
||
var blobName = GetBlobName(plateName, level, x, y); | ||
var client = container.GetBlobClient(blobName); | ||
var download = client.Download(); | ||
|
||
return download.Value.Content; | ||
} | ||
|
||
private string GetBlobContainerName(string plateName) | ||
{ | ||
if (_plateNameMapping.TryGetValue(plateName, out var info)) | ||
{ | ||
return info.container; | ||
} | ||
|
||
return Path.GetFileNameWithoutExtension(plateName).ToLowerInvariant(); | ||
} | ||
|
||
private string GetBlobName(string plateName, int level, int x, int y) | ||
{ | ||
var blobFormat = "L{0}X{1}Y{2}.png"; | ||
|
||
if (_plateNameMapping.TryGetValue(plateName, out var info)) | ||
{ | ||
blobFormat = info.blob; | ||
} | ||
|
||
return string.Format(blobFormat, level, x, y); | ||
} | ||
} | ||
} |
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net48</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.Storage.Blobs" Version="12.6.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\WWTWebservices\WWTWebservices.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.Configuration" /> | ||
</ItemGroup> | ||
|
||
</Project> |
17 changes: 17 additions & 0 deletions
17
WWTWebservices/ConfigurationManagerFilePlateTilePyramid.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,17 @@ | ||
using System.IO; | ||
|
||
namespace WWTWebservices | ||
{ | ||
public class ConfigurationManagerFilePlateTilePyramid : IPlateTilePyramid | ||
{ | ||
public Stream GetStream(string pathPrefix, string plateName, int level, int x, int y) | ||
{ | ||
if (string.IsNullOrEmpty(pathPrefix)) | ||
{ | ||
throw new System.ArgumentException($"'{nameof(pathPrefix)}' cannot be null or empty", nameof(pathPrefix)); | ||
} | ||
|
||
return PlateTilePyramid.GetFileStream(Path.Combine(pathPrefix, plateName), level, x, y); | ||
} | ||
} | ||
} |
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 @@ | ||
using System.IO; | ||
|
||
namespace WWTWebservices | ||
{ | ||
public interface IPlateTilePyramid | ||
{ | ||
Stream GetStream(string pathPrefix, string plateName, int level, int x, int y); | ||
} | ||
} |
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
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