-
-
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.
Abstract file access pattern for DSS provider
This is an intial change to abstract file access using IPlateTilePyramid. This interface provides a single method that will take a plate file name along with the desired level and coordinates and will retrieve the associated image. This change includes two implementations of this: - ConfigurationManagerFilePlateTilePyramid allows for a request to a given plate file and returns a stream for the level and coordinates specified. - AzurePlateTilePyramid retrieves the file from Azure blob storage This new access method has been incorporated into the DSS.aspx page and will surface the content via Azure or local storage via a configuration flag (requires a restart of the service).
- Loading branch information
1 parent
f28d470
commit 745d67a
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