mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Version 4.13.1 Cache "no tile" responses.
This commit is contained in:
parent
576dd8e8e7
commit
219171381f
27 changed files with 200 additions and 338 deletions
|
|
@ -58,6 +58,18 @@ namespace MapControl
|
|||
return image;
|
||||
}
|
||||
|
||||
internal class HttpResponse
|
||||
{
|
||||
public byte[] Buffer { get; }
|
||||
public TimeSpan? MaxAge { get; }
|
||||
|
||||
public HttpResponse(byte[] buffer, TimeSpan? maxAge)
|
||||
{
|
||||
Buffer = buffer;
|
||||
MaxAge = maxAge;
|
||||
}
|
||||
}
|
||||
|
||||
internal static async Task<HttpResponse> GetHttpResponseAsync(Uri uri, bool continueOnCapturedContext = true)
|
||||
{
|
||||
HttpResponse response = null;
|
||||
|
|
@ -65,24 +77,20 @@ namespace MapControl
|
|||
try
|
||||
{
|
||||
using (var responseMessage = await HttpClient
|
||||
.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead)
|
||||
.ConfigureAwait(continueOnCapturedContext))
|
||||
.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(continueOnCapturedContext))
|
||||
{
|
||||
if (responseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
IEnumerable<string> tileInfo;
|
||||
byte[] buffer = null;
|
||||
|
||||
if (responseMessage.Headers.TryGetValues("X-VE-Tile-Info", out tileInfo) &&
|
||||
tileInfo.Contains("no-tile"))
|
||||
if (!responseMessage.Headers.TryGetValues("X-VE-Tile-Info", out tileInfo) ||
|
||||
!tileInfo.Contains("no-tile"))
|
||||
{
|
||||
response = new HttpResponse(null, null); // no tile image
|
||||
}
|
||||
else
|
||||
{
|
||||
response = new HttpResponse(
|
||||
await responseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(continueOnCapturedContext),
|
||||
responseMessage.Headers.CacheControl?.MaxAge);
|
||||
buffer = await responseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(continueOnCapturedContext);
|
||||
}
|
||||
|
||||
response = new HttpResponse(buffer, responseMessage.Headers.CacheControl?.MaxAge);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -97,17 +105,5 @@ namespace MapControl
|
|||
|
||||
return response;
|
||||
}
|
||||
|
||||
internal class HttpResponse
|
||||
{
|
||||
public byte[] Buffer { get; }
|
||||
public TimeSpan? MaxAge { get; }
|
||||
|
||||
public HttpResponse(byte[] buffer, TimeSpan? maxAge)
|
||||
{
|
||||
Buffer = buffer;
|
||||
MaxAge = maxAge;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue