From adc34b65914df6143523c329d9c4e85078ce6b51 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Sat, 19 Aug 2023 17:48:52 +0200 Subject: [PATCH] Use Async method name suffix consistently --- MapControl/Shared/GeoImage.cs | 6 +++--- MapControl/Shared/GroundOverlay.cs | 11 ++++++----- MapControl/Shared/MapTileLayerBase.cs | 4 ++-- MapControl/Shared/TileImageLoader.cs | 14 +++++++------- MapControl/UWP/TileImageLoader.UWP.cs | 6 +++--- MapControl/WPF/GeoImage.WPF.cs | 2 +- MapControl/WPF/TileImageLoader.WPF.cs | 6 +++--- MapControl/WinUI/GeoImage.WinUI.cs | 2 +- MapControl/WinUI/TileImageLoader.WinUI.cs | 6 +++--- 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/MapControl/Shared/GeoImage.cs b/MapControl/Shared/GeoImage.cs index 2da4be11..a007d3c7 100644 --- a/MapControl/Shared/GeoImage.cs +++ b/MapControl/Shared/GeoImage.cs @@ -86,13 +86,13 @@ namespace MapControl if (File.Exists(worldFilePath)) { - geoBitmap = await ReadWorldFileImage(sourcePath, worldFilePath); + geoBitmap = await ReadWorldFileImageAsync(sourcePath, worldFilePath); } } if (geoBitmap == null) { - geoBitmap = await ReadGeoTiff(sourcePath); + geoBitmap = await ReadGeoTiffAsync(sourcePath); } image = new Image @@ -136,7 +136,7 @@ namespace MapControl MapPanel.SetBoundingBox(this, boundingBox); } - private static async Task ReadWorldFileImage(string sourcePath, string worldFilePath) + private static async Task ReadWorldFileImageAsync(string sourcePath, string worldFilePath) { var bitmap = (BitmapSource)await ImageLoader.LoadImageAsync(sourcePath); diff --git a/MapControl/Shared/GroundOverlay.cs b/MapControl/Shared/GroundOverlay.cs index dff719a8..114bee03 100644 --- a/MapControl/Shared/GroundOverlay.cs +++ b/MapControl/Shared/GroundOverlay.cs @@ -56,8 +56,7 @@ namespace MapControl } public static readonly DependencyProperty SourcePathProperty = DependencyProperty.Register( - nameof(SourcePath), typeof(string), typeof(GroundOverlay), - new PropertyMetadata(null, async (o, e) => await ((GroundOverlay)o).SourcePathPropertyChanged((string)e.NewValue))); + nameof(SourcePath), typeof(string), typeof(GroundOverlay), new PropertyMetadata(null, SourcePathPropertyChanged)); public string SourcePath { @@ -65,8 +64,10 @@ namespace MapControl set => SetValue(SourcePathProperty, value); } - private async Task SourcePathPropertyChanged(string sourcePath) + private static async void SourcePathPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { + var groundOverlay = (GroundOverlay)obj; + var sourcePath = (string)e.NewValue; IEnumerable imageOverlays = null; if (!string.IsNullOrEmpty(sourcePath)) @@ -90,11 +91,11 @@ namespace MapControl } } - Children.Clear(); + groundOverlay.Children.Clear(); if (imageOverlays != null) { - AddImageOverlays(imageOverlays); + groundOverlay.AddImageOverlays(imageOverlays); } } diff --git a/MapControl/Shared/MapTileLayerBase.cs b/MapControl/Shared/MapTileLayerBase.cs index 4aae48dd..4fcd173f 100644 --- a/MapControl/Shared/MapTileLayerBase.cs +++ b/MapControl/Shared/MapTileLayerBase.cs @@ -25,7 +25,7 @@ namespace MapControl { public interface ITileImageLoader { - Task LoadTiles(IEnumerable tiles, TileSource tileSource, string cacheName, IProgress progress); + Task LoadTilesAsync(IEnumerable tiles, TileSource tileSource, string cacheName, IProgress progress); } public abstract class MapTileLayerBase : Panel, IMapLayer @@ -195,7 +195,7 @@ namespace MapControl protected Task LoadTiles(IEnumerable tiles, string cacheName) { - return TileImageLoader.LoadTiles(tiles, TileSource, cacheName, loadingProgress); + return TileImageLoader.LoadTilesAsync(tiles, TileSource, cacheName, loadingProgress); } private Task Update(bool tileSourceChanged) diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index 861cfe29..31bee072 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -62,7 +62,7 @@ namespace MapControl /// If tileSource.UriFormat starts with "http" and cacheName is a non-empty string, /// tile images will be cached in the TileImageLoader's Cache - if that is not null. /// - public Task LoadTiles(IEnumerable tiles, TileSource tileSource, string cacheName, IProgress progress) + public Task LoadTilesAsync(IEnumerable tiles, TileSource tileSource, string cacheName, IProgress progress) { pendingTiles?.Clear(); @@ -85,7 +85,7 @@ namespace MapControl var tileQueue = pendingTiles; // pendingTiles may change while tasks are running var tasks = new Task[taskCount]; - async Task LoadTilesFromQueue() + async Task LoadTilesFromQueueAsync() { while (tileQueue.TryDequeue(out var tile)) { @@ -93,7 +93,7 @@ namespace MapControl try { - await LoadTile(tile, tileSource, cacheName).ConfigureAwait(false); + await LoadTileAsync(tile, tileSource, cacheName).ConfigureAwait(false); } catch (Exception ex) { @@ -104,7 +104,7 @@ namespace MapControl for (int i = 0; i < taskCount; i++) { - tasks[i] = Task.Run(LoadTilesFromQueue); + tasks[i] = Task.Run(LoadTilesFromQueueAsync); } return Task.WhenAll(tasks); @@ -114,11 +114,11 @@ namespace MapControl return Task.CompletedTask; } - private static Task LoadTile(Tile tile, TileSource tileSource, string cacheName) + private static Task LoadTileAsync(Tile tile, TileSource tileSource, string cacheName) { if (string.IsNullOrEmpty(cacheName)) { - return LoadTile(tile, () => tileSource.LoadImageAsync(tile.Column, tile.Row, tile.ZoomLevel)); + return LoadTileAsync(tile, () => tileSource.LoadImageAsync(tile.Column, tile.Row, tile.ZoomLevel)); } var uri = tileSource.GetUri(tile.Column, tile.Row, tile.ZoomLevel); @@ -135,7 +135,7 @@ namespace MapControl var cacheKey = string.Format(CultureInfo.InvariantCulture, "{0}/{1}/{2}/{3}{4}", cacheName, tile.ZoomLevel, tile.Column, tile.Row, extension); - return LoadCachedTile(tile, uri, cacheKey); + return LoadCachedTileAsync(tile, uri, cacheKey); } return Task.CompletedTask; diff --git a/MapControl/UWP/TileImageLoader.UWP.cs b/MapControl/UWP/TileImageLoader.UWP.cs index 4536b465..cbff898a 100644 --- a/MapControl/UWP/TileImageLoader.UWP.cs +++ b/MapControl/UWP/TileImageLoader.UWP.cs @@ -33,7 +33,7 @@ namespace MapControl public static Caching.IImageCache Cache { get; set; } - private static async Task LoadCachedTile(Tile tile, Uri uri, string cacheKey) + private static async Task LoadCachedTileAsync(Tile tile, Uri uri, string cacheKey) { var cacheItem = await Cache.GetAsync(cacheKey).ConfigureAwait(false); var buffer = cacheItem?.Item1; @@ -53,11 +53,11 @@ namespace MapControl if (buffer != null && buffer.Length > 0) { - await LoadTile(tile, () => ImageLoader.LoadImageAsync(buffer)).ConfigureAwait(false); + await LoadTileAsync(tile, () => ImageLoader.LoadImageAsync(buffer)).ConfigureAwait(false); } } - private static async Task LoadTile(Tile tile, Func> loadImageFunc) + private static async Task LoadTileAsync(Tile tile, Func> loadImageFunc) { var tcs = new TaskCompletionSource(); diff --git a/MapControl/WPF/GeoImage.WPF.cs b/MapControl/WPF/GeoImage.WPF.cs index 6c06cb12..f9c90aa7 100644 --- a/MapControl/WPF/GeoImage.WPF.cs +++ b/MapControl/WPF/GeoImage.WPF.cs @@ -13,7 +13,7 @@ namespace MapControl { public partial class GeoImage { - private static async Task ReadGeoTiff(string sourcePath) + private static async Task ReadGeoTiffAsync(string sourcePath) { return await Task.Run(() => { diff --git a/MapControl/WPF/TileImageLoader.WPF.cs b/MapControl/WPF/TileImageLoader.WPF.cs index 195ea795..3ac99767 100644 --- a/MapControl/WPF/TileImageLoader.WPF.cs +++ b/MapControl/WPF/TileImageLoader.WPF.cs @@ -24,7 +24,7 @@ namespace MapControl public static ObjectCache Cache { get; set; } = MemoryCache.Default; - private static async Task LoadCachedTile(Tile tile, Uri uri, string cacheKey) + private static async Task LoadCachedTileAsync(Tile tile, Uri uri, string cacheKey) { var cacheItem = Cache.Get(cacheKey) as Tuple; var buffer = cacheItem?.Item1; @@ -46,11 +46,11 @@ namespace MapControl if (buffer != null && buffer.Length > 0) { - await LoadTile(tile, () => ImageLoader.LoadImageAsync(buffer)).ConfigureAwait(false); + await LoadTileAsync(tile, () => ImageLoader.LoadImageAsync(buffer)).ConfigureAwait(false); } } - private static async Task LoadTile(Tile tile, Func> loadImageFunc) + private static async Task LoadTileAsync(Tile tile, Func> loadImageFunc) { var image = await loadImageFunc().ConfigureAwait(false); diff --git a/MapControl/WinUI/GeoImage.WinUI.cs b/MapControl/WinUI/GeoImage.WinUI.cs index ceef7aac..5678a9e6 100644 --- a/MapControl/WinUI/GeoImage.WinUI.cs +++ b/MapControl/WinUI/GeoImage.WinUI.cs @@ -11,7 +11,7 @@ namespace MapControl { public partial class GeoImage { - private static async Task ReadGeoTiff(string sourcePath) + private static async Task ReadGeoTiffAsync(string sourcePath) { var file = await StorageFile.GetFileFromPathAsync(FilePath.GetFullPath(sourcePath)); diff --git a/MapControl/WinUI/TileImageLoader.WinUI.cs b/MapControl/WinUI/TileImageLoader.WinUI.cs index aa8848d3..91edf88a 100644 --- a/MapControl/WinUI/TileImageLoader.WinUI.cs +++ b/MapControl/WinUI/TileImageLoader.WinUI.cs @@ -34,7 +34,7 @@ namespace MapControl public static Caching.IImageCache Cache { get; set; } - private static async Task LoadCachedTile(Tile tile, Uri uri, string cacheKey) + private static async Task LoadCachedTileAsync(Tile tile, Uri uri, string cacheKey) { var cacheItem = await Cache.GetAsync(cacheKey).ConfigureAwait(false); var buffer = cacheItem?.Item1; @@ -54,11 +54,11 @@ namespace MapControl if (buffer != null && buffer.Length > 0) { - await LoadTile(tile, () => ImageLoader.LoadImageAsync(buffer)).ConfigureAwait(false); + await LoadTileAsync(tile, () => ImageLoader.LoadImageAsync(buffer)).ConfigureAwait(false); } } - private static Task LoadTile(Tile tile, Func> loadImageFunc) + private static Task LoadTileAsync(Tile tile, Func> loadImageFunc) { var tcs = new TaskCompletionSource();