From 1f33cea5f250b39d184f01ebbe010ede5a66ebd5 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Thu, 15 Aug 2024 19:46:14 +0200 Subject: [PATCH] TileImageLoader.DefaultCacheFolder --- MapControl/Avalonia/TileImageLoader.Avalonia.cs | 6 ------ MapControl/Shared/ImageFileCache.cs | 16 ++++++++-------- MapControl/Shared/TileImageLoader.cs | 6 ++++++ MapControl/UWP/TileImageLoader.UWP.cs | 6 ------ MapControl/WPF/TileImageLoader.WPF.cs | 7 ------- MapControl/WinUI/TileImageLoader.WinUI.cs | 7 ------- SampleApps/UniversalApp/MainPage.xaml.cs | 3 ++- 7 files changed, 16 insertions(+), 35 deletions(-) diff --git a/MapControl/Avalonia/TileImageLoader.Avalonia.cs b/MapControl/Avalonia/TileImageLoader.Avalonia.cs index 225803b1..dae2df0a 100644 --- a/MapControl/Avalonia/TileImageLoader.Avalonia.cs +++ b/MapControl/Avalonia/TileImageLoader.Avalonia.cs @@ -9,12 +9,6 @@ namespace MapControl { public partial class TileImageLoader { - /// - /// Default folder where the Cache instance may save data, i.e. "C:\ProgramData\MapControl\TileCache". - /// - public static string DefaultCacheFolder => - System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "TileCache"); - private static async Task LoadTileAsync(Tile tile, Func> loadImageFunc) { var image = await loadImageFunc().ConfigureAwait(false); diff --git a/MapControl/Shared/ImageFileCache.cs b/MapControl/Shared/ImageFileCache.cs index 4c9aae2b..7b096c1d 100644 --- a/MapControl/Shared/ImageFileCache.cs +++ b/MapControl/Shared/ImageFileCache.cs @@ -24,18 +24,18 @@ namespace MapControl.Caching private static readonly byte[] expirationTag = Encoding.ASCII.GetBytes("EXPIRES:"); private readonly MemoryDistributedCache memoryCache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions())); - private readonly string rootDirectory; + private readonly string rootPath; - public ImageFileCache(string directory) + public ImageFileCache(string path) { - if (string.IsNullOrEmpty(directory)) + if (string.IsNullOrEmpty(path)) { - throw new ArgumentException($"The {nameof(directory)} argument must not be null or empty.", nameof(directory)); + throw new ArgumentException($"The {nameof(path)} argument must not be null or empty.", nameof(path)); } - rootDirectory = directory; + rootPath = path; - Debug.WriteLine($"ImageFileCache: {rootDirectory}"); + Debug.WriteLine($"ImageFileCache: {rootPath}"); ThreadPool.QueueUserWorkItem(o => Clean()); } @@ -210,7 +210,7 @@ namespace MapControl.Caching public void Clean() { - var deletedFileCount = CleanDirectory(new DirectoryInfo(rootDirectory)); + var deletedFileCount = CleanDirectory(new DirectoryInfo(rootPath)); if (deletedFileCount > 0) { @@ -227,7 +227,7 @@ namespace MapControl.Caching { try { - return Path.Combine(rootDirectory, Path.Combine(key.Split('/'))); + return Path.Combine(rootPath, Path.Combine(key.Split('/'))); } catch (Exception ex) { diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index 99dba720..f8cf1c76 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -44,6 +44,12 @@ namespace MapControl } } + /// + /// Default folder path where a persistent cache implementation may save data, i.e. "C:\ProgramData\MapControl\TileCache". + /// + public static string DefaultCacheFolder => + System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "TileCache"); + /// /// An IDistributedCache implementation used to cache tile images. /// The default value is a MemoryDistributedCache instance. diff --git a/MapControl/UWP/TileImageLoader.UWP.cs b/MapControl/UWP/TileImageLoader.UWP.cs index ee27b03d..7c6fdaa1 100644 --- a/MapControl/UWP/TileImageLoader.UWP.cs +++ b/MapControl/UWP/TileImageLoader.UWP.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; -using Windows.Storage; using Windows.UI.Core; using Windows.UI.Xaml.Media; @@ -12,11 +11,6 @@ namespace MapControl { public partial class TileImageLoader { - /// - /// Default folder where the Cache instance may save data. - /// - public static StorageFolder DefaultCacheFolder => ApplicationData.Current.LocalCacheFolder; - private static async Task LoadTileAsync(Tile tile, Func> loadImageFunc) { var tcs = new TaskCompletionSource(); diff --git a/MapControl/WPF/TileImageLoader.WPF.cs b/MapControl/WPF/TileImageLoader.WPF.cs index 0aacd1a0..1ff25f77 100644 --- a/MapControl/WPF/TileImageLoader.WPF.cs +++ b/MapControl/WPF/TileImageLoader.WPF.cs @@ -3,7 +3,6 @@ // Licensed under the Microsoft Public License (Ms-PL) using System; -using System.IO; using System.Threading.Tasks; using System.Windows.Media; @@ -11,12 +10,6 @@ namespace MapControl { public partial class TileImageLoader { - /// - /// Default folder where the Cache instance may save data, i.e. "C:\ProgramData\MapControl\TileCache". - /// - public static string DefaultCacheFolder => - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "TileCache"); - private static async Task LoadTileAsync(Tile tile, Func> loadImageFunc) { var image = await loadImageFunc().ConfigureAwait(false); diff --git a/MapControl/WinUI/TileImageLoader.WinUI.cs b/MapControl/WinUI/TileImageLoader.WinUI.cs index 135f0909..3fe75d2f 100644 --- a/MapControl/WinUI/TileImageLoader.WinUI.cs +++ b/MapControl/WinUI/TileImageLoader.WinUI.cs @@ -5,19 +5,12 @@ using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml.Media; using System; -using System.IO; using System.Threading.Tasks; namespace MapControl { public partial class TileImageLoader { - /// - /// Default folder where the Cache instance may save data, i.e. "C:\ProgramData\MapControl\TileCache". - /// - public static string DefaultCacheFolder => - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "TileCache"); - private static Task LoadTileAsync(Tile tile, Func> loadImageFunc) { var tcs = new TaskCompletionSource(); diff --git a/SampleApps/UniversalApp/MainPage.xaml.cs b/SampleApps/UniversalApp/MainPage.xaml.cs index 9b06f5ab..2b5f27ed 100644 --- a/SampleApps/UniversalApp/MainPage.xaml.cs +++ b/SampleApps/UniversalApp/MainPage.xaml.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Globalization; using System.Linq; using Windows.Devices.Input; +using Windows.Storage; using Windows.System; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -15,7 +16,7 @@ namespace SampleApplication { static MainPage() { - //TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder); + //TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(ApplicationData.Current.LocalCacheFolder); } public MainPage()