mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Dropped UWP ImageFileCache
This commit is contained in:
parent
f99fc777f2
commit
6ea58c9dd3
|
|
@ -37,6 +37,7 @@ namespace MapControl.Caching
|
||||||
}
|
}
|
||||||
|
|
||||||
rootDirectory = new DirectoryInfo(path);
|
rootDirectory = new DirectoryInfo(path);
|
||||||
|
rootDirectory.Create();
|
||||||
|
|
||||||
Debug.WriteLine($"{nameof(ImageFileCache)}: {rootDirectory.FullName}");
|
Debug.WriteLine($"{nameof(ImageFileCache)}: {rootDirectory.FullName}");
|
||||||
|
|
||||||
|
|
@ -133,10 +134,14 @@ namespace MapControl.Caching
|
||||||
{
|
{
|
||||||
if (file != null && buffer?.Length > 0)
|
if (file != null && buffer?.Length > 0)
|
||||||
{
|
{
|
||||||
using (var stream = CreateFile(file, options))
|
file.Directory.Create();
|
||||||
|
|
||||||
|
using (var stream = file.Create())
|
||||||
{
|
{
|
||||||
stream.Write(buffer, 0, buffer.Length);
|
stream.Write(buffer, 0, buffer.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetExpiration(file, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -155,10 +160,14 @@ namespace MapControl.Caching
|
||||||
{
|
{
|
||||||
if (file != null && buffer?.Length > 0 && !token.IsCancellationRequested)
|
if (file != null && buffer?.Length > 0 && !token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
using (var stream = CreateFile(file, options))
|
file.Directory.Create();
|
||||||
|
|
||||||
|
using (var stream = file.Create())
|
||||||
{
|
{
|
||||||
await stream.WriteAsync(buffer, 0, buffer.Length, token).ConfigureAwait(false);
|
await stream.WriteAsync(buffer, 0, buffer.Length, token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetExpiration(file, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -254,24 +263,11 @@ namespace MapControl.Caching
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FileStream CreateFile(FileInfo file, DistributedCacheEntryOptions options)
|
private static void SetExpiration(FileInfo file, DistributedCacheEntryOptions options)
|
||||||
{
|
{
|
||||||
file.Directory.Create();
|
file.CreationTime = options.AbsoluteExpiration.HasValue
|
||||||
|
? options.AbsoluteExpiration.Value.LocalDateTime
|
||||||
var stream = file.Create();
|
: DateTime.Now.Add(options.AbsoluteExpirationRelativeToNow ?? (options.SlidingExpiration ?? TimeSpan.FromDays(1)));
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
file.CreationTime = options.AbsoluteExpiration.HasValue
|
|
||||||
? options.AbsoluteExpiration.Value.LocalDateTime
|
|
||||||
: DateTime.Now.Add(options.AbsoluteExpirationRelativeToNow ?? (options.SlidingExpiration ?? TimeSpan.FromDays(1)));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Debug.WriteLine($"{nameof(ImageFileCache)}: Failed setting creation time of {file.FullName}: {ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return stream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int CleanDirectory(DirectoryInfo directory)
|
private static int CleanDirectory(DirectoryInfo directory)
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,11 @@ namespace MapControl
|
||||||
/// Default folder path where a persistent cache implementation may save data, i.e. "C:\ProgramData\MapControl\TileCache".
|
/// Default folder path where a persistent cache implementation may save data, i.e. "C:\ProgramData\MapControl\TileCache".
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string DefaultCacheFolder =>
|
public static string DefaultCacheFolder =>
|
||||||
|
#if UWP
|
||||||
|
Path.Combine(Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path, "TileCache");
|
||||||
|
#else
|
||||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "TileCache");
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "TileCache");
|
||||||
|
#endif
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An IDistributedCache implementation used to cache tile images.
|
/// An IDistributedCache implementation used to cache tile images.
|
||||||
/// The default value is a MemoryDistributedCache instance.
|
/// The default value is a MemoryDistributedCache instance.
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,9 @@
|
||||||
<Compile Include="..\Shared\GroundOverlay.cs">
|
<Compile Include="..\Shared\GroundOverlay.cs">
|
||||||
<Link>GroundOverlay.cs</Link>
|
<Link>GroundOverlay.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="..\Shared\ImageFileCache.cs">
|
||||||
|
<Link>ImageFileCache.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="..\Shared\ImageLoader.cs">
|
<Compile Include="..\Shared\ImageLoader.cs">
|
||||||
<Link>ImageLoader.cs</Link>
|
<Link>ImageLoader.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
@ -275,7 +278,6 @@
|
||||||
<Compile Include="..\WinUI\Tile.WinUI.cs">
|
<Compile Include="..\WinUI\Tile.WinUI.cs">
|
||||||
<Link>Tile.WinUI.cs</Link>
|
<Link>Tile.WinUI.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="ImageFileCache.UWP.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TileImageLoader.UWP.cs" />
|
<Compile Include="TileImageLoader.UWP.cs" />
|
||||||
<EmbeddedResource Include="Properties\MapControl.UWP.rd.xml" />
|
<EmbeddedResource Include="Properties\MapControl.UWP.rd.xml" />
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace SampleApplication
|
||||||
static MainPage()
|
static MainPage()
|
||||||
{
|
{
|
||||||
//MapProjectionFactory.Instance = new MapControl.Projections.GeoApiProjectionFactory();
|
//MapProjectionFactory.Instance = new MapControl.Projections.GeoApiProjectionFactory();
|
||||||
//TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(ApplicationData.Current.LocalCacheFolder);
|
//TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MainPage()
|
public MainPage()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue