Use Async method name suffix consistently

This commit is contained in:
ClemensFischer 2023-08-19 17:48:52 +02:00
parent f3aad38814
commit adc34b6591
9 changed files with 29 additions and 28 deletions

View file

@ -86,13 +86,13 @@ namespace MapControl
if (File.Exists(worldFilePath)) if (File.Exists(worldFilePath))
{ {
geoBitmap = await ReadWorldFileImage(sourcePath, worldFilePath); geoBitmap = await ReadWorldFileImageAsync(sourcePath, worldFilePath);
} }
} }
if (geoBitmap == null) if (geoBitmap == null)
{ {
geoBitmap = await ReadGeoTiff(sourcePath); geoBitmap = await ReadGeoTiffAsync(sourcePath);
} }
image = new Image image = new Image
@ -136,7 +136,7 @@ namespace MapControl
MapPanel.SetBoundingBox(this, boundingBox); MapPanel.SetBoundingBox(this, boundingBox);
} }
private static async Task<GeoBitmap> ReadWorldFileImage(string sourcePath, string worldFilePath) private static async Task<GeoBitmap> ReadWorldFileImageAsync(string sourcePath, string worldFilePath)
{ {
var bitmap = (BitmapSource)await ImageLoader.LoadImageAsync(sourcePath); var bitmap = (BitmapSource)await ImageLoader.LoadImageAsync(sourcePath);

View file

@ -56,8 +56,7 @@ namespace MapControl
} }
public static readonly DependencyProperty SourcePathProperty = DependencyProperty.Register( public static readonly DependencyProperty SourcePathProperty = DependencyProperty.Register(
nameof(SourcePath), typeof(string), typeof(GroundOverlay), nameof(SourcePath), typeof(string), typeof(GroundOverlay), new PropertyMetadata(null, SourcePathPropertyChanged));
new PropertyMetadata(null, async (o, e) => await ((GroundOverlay)o).SourcePathPropertyChanged((string)e.NewValue)));
public string SourcePath public string SourcePath
{ {
@ -65,8 +64,10 @@ namespace MapControl
set => SetValue(SourcePathProperty, value); 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<ImageOverlay> imageOverlays = null; IEnumerable<ImageOverlay> imageOverlays = null;
if (!string.IsNullOrEmpty(sourcePath)) if (!string.IsNullOrEmpty(sourcePath))
@ -90,11 +91,11 @@ namespace MapControl
} }
} }
Children.Clear(); groundOverlay.Children.Clear();
if (imageOverlays != null) if (imageOverlays != null)
{ {
AddImageOverlays(imageOverlays); groundOverlay.AddImageOverlays(imageOverlays);
} }
} }

View file

@ -25,7 +25,7 @@ namespace MapControl
{ {
public interface ITileImageLoader public interface ITileImageLoader
{ {
Task LoadTiles(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName, IProgress<double> progress); Task LoadTilesAsync(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName, IProgress<double> progress);
} }
public abstract class MapTileLayerBase : Panel, IMapLayer public abstract class MapTileLayerBase : Panel, IMapLayer
@ -195,7 +195,7 @@ namespace MapControl
protected Task LoadTiles(IEnumerable<Tile> tiles, string cacheName) protected Task LoadTiles(IEnumerable<Tile> tiles, string cacheName)
{ {
return TileImageLoader.LoadTiles(tiles, TileSource, cacheName, loadingProgress); return TileImageLoader.LoadTilesAsync(tiles, TileSource, cacheName, loadingProgress);
} }
private Task Update(bool tileSourceChanged) private Task Update(bool tileSourceChanged)

View file

@ -62,7 +62,7 @@ namespace MapControl
/// If tileSource.UriFormat starts with "http" and cacheName is a non-empty string, /// 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. /// tile images will be cached in the TileImageLoader's Cache - if that is not null.
/// </summary> /// </summary>
public Task LoadTiles(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName, IProgress<double> progress) public Task LoadTilesAsync(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName, IProgress<double> progress)
{ {
pendingTiles?.Clear(); pendingTiles?.Clear();
@ -85,7 +85,7 @@ namespace MapControl
var tileQueue = pendingTiles; // pendingTiles may change while tasks are running var tileQueue = pendingTiles; // pendingTiles may change while tasks are running
var tasks = new Task[taskCount]; var tasks = new Task[taskCount];
async Task LoadTilesFromQueue() async Task LoadTilesFromQueueAsync()
{ {
while (tileQueue.TryDequeue(out var tile)) while (tileQueue.TryDequeue(out var tile))
{ {
@ -93,7 +93,7 @@ namespace MapControl
try try
{ {
await LoadTile(tile, tileSource, cacheName).ConfigureAwait(false); await LoadTileAsync(tile, tileSource, cacheName).ConfigureAwait(false);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -104,7 +104,7 @@ namespace MapControl
for (int i = 0; i < taskCount; i++) for (int i = 0; i < taskCount; i++)
{ {
tasks[i] = Task.Run(LoadTilesFromQueue); tasks[i] = Task.Run(LoadTilesFromQueueAsync);
} }
return Task.WhenAll(tasks); return Task.WhenAll(tasks);
@ -114,11 +114,11 @@ namespace MapControl
return Task.CompletedTask; 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)) 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); var uri = tileSource.GetUri(tile.Column, tile.Row, tile.ZoomLevel);
@ -135,7 +135,7 @@ namespace MapControl
var cacheKey = string.Format(CultureInfo.InvariantCulture, var cacheKey = string.Format(CultureInfo.InvariantCulture,
"{0}/{1}/{2}/{3}{4}", cacheName, tile.ZoomLevel, tile.Column, tile.Row, extension); "{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; return Task.CompletedTask;

View file

@ -33,7 +33,7 @@ namespace MapControl
public static Caching.IImageCache Cache { get; set; } 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 cacheItem = await Cache.GetAsync(cacheKey).ConfigureAwait(false);
var buffer = cacheItem?.Item1; var buffer = cacheItem?.Item1;
@ -53,11 +53,11 @@ namespace MapControl
if (buffer != null && buffer.Length > 0) 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<Task<ImageSource>> loadImageFunc) private static async Task LoadTileAsync(Tile tile, Func<Task<ImageSource>> loadImageFunc)
{ {
var tcs = new TaskCompletionSource<object>(); var tcs = new TaskCompletionSource<object>();

View file

@ -13,7 +13,7 @@ namespace MapControl
{ {
public partial class GeoImage public partial class GeoImage
{ {
private static async Task<GeoBitmap> ReadGeoTiff(string sourcePath) private static async Task<GeoBitmap> ReadGeoTiffAsync(string sourcePath)
{ {
return await Task.Run(() => return await Task.Run(() =>
{ {

View file

@ -24,7 +24,7 @@ namespace MapControl
public static ObjectCache Cache { get; set; } = MemoryCache.Default; 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<byte[], DateTime>; var cacheItem = Cache.Get(cacheKey) as Tuple<byte[], DateTime>;
var buffer = cacheItem?.Item1; var buffer = cacheItem?.Item1;
@ -46,11 +46,11 @@ namespace MapControl
if (buffer != null && buffer.Length > 0) 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<Task<ImageSource>> loadImageFunc) private static async Task LoadTileAsync(Tile tile, Func<Task<ImageSource>> loadImageFunc)
{ {
var image = await loadImageFunc().ConfigureAwait(false); var image = await loadImageFunc().ConfigureAwait(false);

View file

@ -11,7 +11,7 @@ namespace MapControl
{ {
public partial class GeoImage public partial class GeoImage
{ {
private static async Task<GeoBitmap> ReadGeoTiff(string sourcePath) private static async Task<GeoBitmap> ReadGeoTiffAsync(string sourcePath)
{ {
var file = await StorageFile.GetFileFromPathAsync(FilePath.GetFullPath(sourcePath)); var file = await StorageFile.GetFileFromPathAsync(FilePath.GetFullPath(sourcePath));

View file

@ -34,7 +34,7 @@ namespace MapControl
public static Caching.IImageCache Cache { get; set; } 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 cacheItem = await Cache.GetAsync(cacheKey).ConfigureAwait(false);
var buffer = cacheItem?.Item1; var buffer = cacheItem?.Item1;
@ -54,11 +54,11 @@ namespace MapControl
if (buffer != null && buffer.Length > 0) 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<Task<ImageSource>> loadImageFunc) private static Task LoadTileAsync(Tile tile, Func<Task<ImageSource>> loadImageFunc)
{ {
var tcs = new TaskCompletionSource(); var tcs = new TaskCompletionSource();