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.Create();
|
||||
|
||||
Debug.WriteLine($"{nameof(ImageFileCache)}: {rootDirectory.FullName}");
|
||||
|
||||
|
|
@ -133,10 +134,14 @@ namespace MapControl.Caching
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
||||
SetExpiration(file, options);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -155,10 +160,14 @@ namespace MapControl.Caching
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
||||
SetExpiration(file, options);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -254,25 +263,12 @@ namespace MapControl.Caching
|
|||
return null;
|
||||
}
|
||||
|
||||
private static FileStream CreateFile(FileInfo file, DistributedCacheEntryOptions options)
|
||||
{
|
||||
file.Directory.Create();
|
||||
|
||||
var stream = file.Create();
|
||||
|
||||
try
|
||||
private static void SetExpiration(FileInfo file, DistributedCacheEntryOptions options)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,8 +29,11 @@ namespace MapControl
|
|||
/// Default folder path where a persistent cache implementation may save data, i.e. "C:\ProgramData\MapControl\TileCache".
|
||||
/// </summary>
|
||||
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");
|
||||
|
||||
#endif
|
||||
/// <summary>
|
||||
/// An IDistributedCache implementation used to cache tile images.
|
||||
/// The default value is a MemoryDistributedCache instance.
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@
|
|||
<Compile Include="..\Shared\GroundOverlay.cs">
|
||||
<Link>GroundOverlay.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\ImageFileCache.cs">
|
||||
<Link>ImageFileCache.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\ImageLoader.cs">
|
||||
<Link>ImageLoader.cs</Link>
|
||||
</Compile>
|
||||
|
|
@ -275,7 +278,6 @@
|
|||
<Compile Include="..\WinUI\Tile.WinUI.cs">
|
||||
<Link>Tile.WinUI.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="ImageFileCache.UWP.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TileImageLoader.UWP.cs" />
|
||||
<EmbeddedResource Include="Properties\MapControl.UWP.rd.xml" />
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace SampleApplication
|
|||
static MainPage()
|
||||
{
|
||||
//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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue