From 7cdb4ca54d4569f9a6bf6787b647e4d36051a8d7 Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Wed, 25 Sep 2024 02:03:16 -0700 Subject: [PATCH 01/13] Refactor URLs and improve logging consistency - Use string interpolation for URLs in various methods. - Add default values for `CancellationToken` in `LoadViewAsync`. - Update logging placeholders for consistent casing in `MediaElementPage.xaml.cs`. - Switch to `Trace.TraceInformation` in `OnRowTapped`. - Enhance exception logging in `DownloadDotNetBotImage`. - Improve code readability and maintainability. --- .../Pages/Views/Expander/ExpanderPageCS.cs | 2 +- .../Pages/Views/LazyView/CustomLazyView.cs | 2 +- .../Pages/Views/LazyView/MyViewLazyView.cs | 2 +- .../Pages/Views/MediaElement/MediaElementPage.xaml.cs | 10 +++++----- ...BehaviorCollectionViewMultipleSelectionViewModel.cs | 2 +- .../ByteArrayToImageSourceConverterViewModel.cs | 4 ++-- .../ViewModels/Essentials/FileSaverViewModel.cs | 2 +- .../Views/MediaElementCarouselViewViewModel.cs | 6 +++--- .../Views/MediaElementCollectionViewViewModel.cs | 6 +++--- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs index 44b604e06d..0f69de999d 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs @@ -46,7 +46,7 @@ public ExpanderPageCS() new Button() .Text("Learn more") - .Invoke(button => button.Clicked += async (s, e) => await Launcher.OpenAsync("https://dot.net/maui")) + .Invoke(button => button.Clicked += async (s, e) => await Launcher.OpenAsync($"https://dot.net/maui")) }.Padding(10) diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/LazyView/CustomLazyView.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/LazyView/CustomLazyView.cs index 2a2fa8c2bb..8d1ef1e28f 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/LazyView/CustomLazyView.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/LazyView/CustomLazyView.cs @@ -4,7 +4,7 @@ namespace CommunityToolkit.Maui.Sample.Pages.Views.LazyView; public class CustomLazyView : Maui.Views.LazyView where TView : View, new() { - public override async ValueTask LoadViewAsync(CancellationToken token) + public override async ValueTask LoadViewAsync(CancellationToken token = default) { // display a loading indicator Content = new ActivityIndicator { IsRunning = true }.Center(); diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/LazyView/MyViewLazyView.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/LazyView/MyViewLazyView.cs index e8d274ba83..c71ea68ae7 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/LazyView/MyViewLazyView.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/LazyView/MyViewLazyView.cs @@ -4,7 +4,7 @@ namespace CommunityToolkit.Maui.Sample.Pages.Views.LazyView; class MyViewLazyView : LazyView { - public override async ValueTask LoadViewAsync(CancellationToken token) + public override async ValueTask LoadViewAsync(CancellationToken token = default) { await base.LoadViewAsync(token); } diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs index b910267cef..156486f791 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs @@ -28,7 +28,7 @@ void MediaElement_PropertyChanged(object? sender, PropertyChangedEventArgs e) { if (e.PropertyName == CommunityToolkit.Maui.Views.MediaElement.DurationProperty.PropertyName) { - logger.LogInformation("Duration: {newDuration}", MediaElement.Duration); + logger.LogInformation("Duration: {NewDuration}", MediaElement.Duration); PositionSlider.Maximum = MediaElement.Duration.TotalSeconds; } } @@ -44,7 +44,7 @@ void OnStateChanged(object? sender, MediaStateChangedEventArgs e) => void OnPositionChanged(object? sender, MediaPositionChangedEventArgs e) { - logger.LogInformation("Position changed to {position}", e.Position); + logger.LogInformation("Position changed to {Position}", e.Position); PositionSlider.Value = e.Position.TotalSeconds; } @@ -165,7 +165,7 @@ async void ChangeSourceClicked(Object sender, EventArgs e) MediaElement.MetadataArtist = "Big Buck Bunny Album"; MediaElement.Source = MediaSource.FromUri( - "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"); + $"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"); return; case loadHls: @@ -174,7 +174,7 @@ async void ChangeSourceClicked(Object sender, EventArgs e) MediaElement.MetadataTitle = "HLS Title"; MediaElement.Source = MediaSource.FromUri( - "https://mtoczko.github.io/hls-test-streams/test-gap/playlist.m3u8"); + $"https://mtoczko.github.io/hls-test-streams/test-gap/playlist.m3u8"); return; case resetSource: @@ -208,7 +208,7 @@ async void ChangeSourceClicked(Object sender, EventArgs e) MediaElement.MetadataTitle = "HAL 9000"; MediaElement.MetadataArtist = "HAL 9000 Album"; MediaElement.MetadataArtworkUrl = "https://lh3.googleusercontent.com/pw/AP1GczNRrebWCJvfdIau1EbsyyYiwAfwHS0JXjbioXvHqEwYIIdCzuLodQCZmA57GADIo5iB3yMMx3t_vsefbfoHwSg0jfUjIXaI83xpiih6d-oT7qD_slR0VgNtfAwJhDBU09kS5V2T5ZML-WWZn8IrjD4J-g=w1792-h1024-s-no-gm"; - MediaElement.Source = MediaSource.FromUri("https://github.com/prof3ssorSt3v3/media-sample-files/raw/master/hal-9000.mp3"); + MediaElement.Source = MediaSource.FromUri($"https://github.com/prof3ssorSt3v3/media-sample-files/raw/master/hal-9000.mp3"); return; } } diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/TouchBehavior/TouchBehaviorCollectionViewMultipleSelectionViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/TouchBehavior/TouchBehaviorCollectionViewMultipleSelectionViewModel.cs index 9f362c391b..89178c70d3 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/TouchBehavior/TouchBehaviorCollectionViewMultipleSelectionViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/TouchBehavior/TouchBehaviorCollectionViewMultipleSelectionViewModel.cs @@ -11,6 +11,6 @@ public partial class TouchBehaviorCollectionViewMultipleSelectionViewModel : Bas [RelayCommand] void OnRowTapped(ContentCreator creatorTapped) { - Trace.WriteLine($"{creatorTapped.Name} Tapped"); + Trace.TraceInformation($"{creatorTapped.Name} Tapped"); } } \ No newline at end of file diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs index 83b4b90529..d7a7eb93cb 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs @@ -50,7 +50,7 @@ async Task DownloadDotNetBotImage(CancellationToken token) try { - DotNetBotImageByteArray = await client.GetByteArrayAsync("https://user-images.githubusercontent.com/13558917/137551073-ac8958bf-83e3-4ae3-8623-4db6dce49d02.png", maximumDownloadTimeCTS.Token).WaitAsync(token).ConfigureAwait(false); + DotNetBotImageByteArray = await client.GetByteArrayAsync($"https://user-images.githubusercontent.com/13558917/137551073-ac8958bf-83e3-4ae3-8623-4db6dce49d02.png", maximumDownloadTimeCTS.Token).WaitAsync(token).ConfigureAwait(false); await minimumDownloadTimeTask.ConfigureAwait(false); @@ -58,7 +58,7 @@ async Task DownloadDotNetBotImage(CancellationToken token) } catch (Exception e) { - Trace.WriteLine(e); + Trace.TraceInformation(e.Message); OnImageDownloadFailed(e.Message); } finally diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs index a21c51d494..1580d76fe1 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs @@ -48,7 +48,7 @@ async Task SaveFileStatic(CancellationToken cancellationToken) async Task SaveFileInstance(CancellationToken cancellationToken) { using var client = new HttpClient(); - await using var stream = await client.GetStreamAsync("https://www.nuget.org/api/v2/package/CommunityToolkit.Maui/5.0.0", cancellationToken); + await using var stream = await client.GetStreamAsync($"https://www.nuget.org/api/v2/package/CommunityToolkit.Maui/5.0.0", cancellationToken); try { var fileSaverInstance = new FileSaverImplementation(); diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs index 27ed35b468..b2d580b7ac 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs @@ -5,9 +5,9 @@ public partial class MediaElementCarouselViewViewModel : BaseViewModel { public ObservableCollection ItemSource { get; } = [ - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), "Buck Bunny", 720, 1280), - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"), "Elephants Dream", 720, 1280), - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"), "Sintel", 546, 1280) + new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), "Buck Bunny", 720, 1280), + new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"), "Elephants Dream", 720, 1280), + new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"), "Sintel", 546, 1280) ]; } diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs index c12760a12f..3f1358e1b2 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs @@ -5,8 +5,8 @@ public partial class MediaElementCollectionViewViewModel : BaseViewModel { public ObservableCollection ItemSource { get; } = [ - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), "Buck Bunny", 720, 1280), - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"), "Elephants Dream", 720, 1280), - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"), "Sintel", 546, 1280) + new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), "Buck Bunny", 720, 1280), + new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"), "Elephants Dream", 720, 1280), + new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"), "Sintel", 546, 1280) ]; } \ No newline at end of file From 834e12aa0656efd5a9cb884215240d1417731a31 Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Wed, 25 Sep 2024 02:19:25 -0700 Subject: [PATCH 02/13] Fix strack trace issue --- .../Converters/ByteArrayToImageSourceConverterViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs index d7a7eb93cb..47587d5af5 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs @@ -58,7 +58,7 @@ async Task DownloadDotNetBotImage(CancellationToken token) } catch (Exception e) { - Trace.TraceInformation(e.Message); + Trace.TraceInformation(e.StackTrace); OnImageDownloadFailed(e.Message); } finally From b9cadee93b1e8f6e24abddcf7a02e0a3c1fa0139 Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Wed, 25 Sep 2024 02:48:34 -0700 Subject: [PATCH 03/13] Switch to Trace.TraceError for error logging Updated the logging mechanism for handling exceptions across multiple files. Replaced `Trace.WriteLine` with `Trace.TraceError` in the following methods and classes: - `async Task OnAnimate(CancellationToken token)` in `AnimationBehavior.shared.cs` - `protected void OnViewPropertyChanged(object? sender, PropertyChangedEventArgs e)` in `ICommunityToolkitBehavior.shared.cs` - `protected override void OnDetachingFrom(Grid bindable)` in `ImpliedOrderGridBehavior.shared.cs` - `internal async Task ForceUpdateState(CancellationToken token, bool animated = true)` in `TouchBehavior.methods.shared.cs` - `void OnChildrenCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)` in `MultiValidationBehavior.shared.cs` - `async ValueTask UpdateStateAsync(VisualElement? view, ValidationFlags flags, bool isValid)` in `ValidationBehavior.shared.cs` - `public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]>` in `BaseConverter.shared.cs` (multiple methods) --- .../Behaviors/AnimationBehavior.shared.cs | 2 +- .../Behaviors/ICommunityToolkitBehavior.shared.cs | 2 +- .../Behaviors/ImpliedOrderGridBehavior.shared.cs | 2 +- .../Touch/TouchBehavior.methods.shared.cs | 2 +- .../Validators/MultiValidationBehavior.shared.cs | 2 +- .../Behaviors/Validators/ValidationBehavior.shared.cs | 2 +- .../Converters/BaseConverter.shared.cs | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs index fb50a1cdc1..a89c5f7938 100644 --- a/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs @@ -115,7 +115,7 @@ async Task OnAnimate(CancellationToken token) } catch (Exception ex) when (Options.ShouldSuppressExceptionsInAnimations) { - Trace.WriteLine(ex); + Trace.TraceError(ex.StackTrace); } } } \ No newline at end of file diff --git a/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs index 0df155889f..942c871e66 100644 --- a/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs @@ -89,7 +89,7 @@ protected void OnViewPropertyChanged(object? sender, PropertyChangedEventArgs e) } catch (Exception ex) when (Options.ShouldSuppressExceptionsInBehaviors) { - Trace.WriteLine(ex); + Trace.TraceError(ex.StackTrace); } } diff --git a/src/CommunityToolkit.Maui/Behaviors/ImpliedOrderGridBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/ImpliedOrderGridBehavior.shared.cs index e86b5d4496..4ee8fd8cc8 100644 --- a/src/CommunityToolkit.Maui/Behaviors/ImpliedOrderGridBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/ImpliedOrderGridBehavior.shared.cs @@ -34,7 +34,7 @@ protected override void OnDetachingFrom(Grid bindable) static void LogWarning(string warning, bool shouldThrowException) { - System.Diagnostics.Trace.WriteLine(warning); + System.Diagnostics.Trace.TraceWarning(warning); if (shouldThrowException) { diff --git a/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs b/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs index 026e9cc10b..72691c9fde 100644 --- a/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs @@ -63,7 +63,7 @@ internal async Task ForceUpdateState(CancellationToken token, bool animated = tr } catch (TaskCanceledException ex) { - Trace.WriteLine(ex); + Trace.TraceError(ex.StackTrace); } } diff --git a/src/CommunityToolkit.Maui/Behaviors/Validators/MultiValidationBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/Validators/MultiValidationBehavior.shared.cs index 8296ab05cc..ea1c3651b0 100644 --- a/src/CommunityToolkit.Maui/Behaviors/Validators/MultiValidationBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/Validators/MultiValidationBehavior.shared.cs @@ -91,7 +91,7 @@ void OnChildrenCollectionChanged(object? sender, NotifyCollectionChangedEventArg var isSuccessful = ((ICommunityToolkitBehavior)child).TrySetBindingContextToAttachedViewBindingContext(); if (!isSuccessful) { - Trace.WriteLine($"Setting {nameof(BindingContext)} for {child.GetType()} failed"); + Trace.TraceError($"Setting {nameof(BindingContext)} for {child.GetType()} failed"); } } } diff --git a/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs index a9f324ad00..88230b0a38 100644 --- a/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs @@ -397,7 +397,7 @@ async ValueTask UpdateStateAsync(VisualElement? view, ValidationFlags flags, boo IsValid = false; IsRunning = false; - Trace.WriteLine(ex); + Trace.TraceError(ex.StackTrace); } } diff --git a/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs b/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs index 6bc8e7c9ca..823e50c0d2 100644 --- a/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs +++ b/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs @@ -73,7 +73,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.WriteLine(ex); + Trace.TraceError(ex.StackTrace); return DefaultConvertBackReturnValue; } } @@ -92,7 +92,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.WriteLine(ex); + Trace.TraceError(ex.StackTrace); return DefaultConvertReturnValue; } } @@ -157,7 +157,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.WriteLine(ex); + Trace.TraceError(ex.StackTrace); return DefaultConvertBackReturnValue; } } @@ -175,7 +175,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.WriteLine(ex); + Trace.TraceError(ex.StackTrace); return DefaultConvertReturnValue; } } From 8df5f5535f14f029c5abbee295e21e102bf85270 Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Wed, 25 Sep 2024 02:59:45 -0700 Subject: [PATCH 04/13] Refactor hardcoded URIs to direct strings Disabled and restored S1075 warning across multiple files. Refactored hardcoded URIs to be directly passed as strings: - ExpanderPageCS.cs: `Launcher.OpenAsync` method - MediaElementPage.xaml.cs: media sources - FileSaverViewModel.cs: `GetStreamAsync` method - MediaElementCarouselViewViewModel.cs and MediaElementCollectionViewViewModel.cs: `ObservableCollection` initialization --- .../Pages/Views/Expander/ExpanderPageCS.cs | 4 +++- .../Pages/Views/MediaElement/MediaElementPage.xaml.cs | 6 ++++-- .../ViewModels/Essentials/FileSaverViewModel.cs | 4 +++- .../ViewModels/Views/MediaElementCarouselViewViewModel.cs | 8 +++++--- .../Views/MediaElementCollectionViewViewModel.cs | 8 +++++--- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs index 0f69de999d..2a103f4ddb 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs @@ -11,6 +11,7 @@ public ExpanderPageCS() { Title = "Expander Page, C# UI"; +#pragma warning disable S1075 // URIs should not be hardcoded Content = new VerticalStackLayout() { Spacing = 12, @@ -46,7 +47,7 @@ public ExpanderPageCS() new Button() .Text("Learn more") - .Invoke(button => button.Clicked += async (s, e) => await Launcher.OpenAsync($"https://dot.net/maui")) + .Invoke(button => button.Clicked += async (s, e) => await Launcher.OpenAsync("https://dot.net/maui")) }.Padding(10) @@ -57,5 +58,6 @@ public ExpanderPageCS() convert: (int selectedIndex) => Enum.IsDefined(typeof(ExpandDirection), selectedIndex) ? (ExpandDirection)selectedIndex : default) } }; +#pragma warning restore S1075 // URIs should not be hardcoded } } \ No newline at end of file diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs index 156486f791..56e6c38460 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs @@ -163,9 +163,10 @@ async void ChangeSourceClicked(Object sender, EventArgs e) MediaElement.MetadataTitle = "Big Buck Bunny"; MediaElement.MetadataArtworkUrl = "https://lh3.googleusercontent.com/pw/AP1GczNRrebWCJvfdIau1EbsyyYiwAfwHS0JXjbioXvHqEwYIIdCzuLodQCZmA57GADIo5iB3yMMx3t_vsefbfoHwSg0jfUjIXaI83xpiih6d-oT7qD_slR0VgNtfAwJhDBU09kS5V2T5ZML-WWZn8IrjD4J-g=w1792-h1024-s-no-gm"; MediaElement.MetadataArtist = "Big Buck Bunny Album"; +#pragma warning disable S1075 // URIs should not be hardcoded MediaElement.Source = MediaSource.FromUri( - $"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"); + "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"); return; case loadHls: @@ -174,7 +175,8 @@ async void ChangeSourceClicked(Object sender, EventArgs e) MediaElement.MetadataTitle = "HLS Title"; MediaElement.Source = MediaSource.FromUri( - $"https://mtoczko.github.io/hls-test-streams/test-gap/playlist.m3u8"); + "https://mtoczko.github.io/hls-test-streams/test-gap/playlist.m3u8"); +#pragma warning restore S1075 // URIs should not be hardcoded return; case resetSource: diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs index 1580d76fe1..4f6aec4a1e 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs @@ -48,7 +48,9 @@ async Task SaveFileStatic(CancellationToken cancellationToken) async Task SaveFileInstance(CancellationToken cancellationToken) { using var client = new HttpClient(); - await using var stream = await client.GetStreamAsync($"https://www.nuget.org/api/v2/package/CommunityToolkit.Maui/5.0.0", cancellationToken); +#pragma warning disable S1075 // URIs should not be hardcoded + await using var stream = await client.GetStreamAsync("https://www.nuget.org/api/v2/package/CommunityToolkit.Maui/5.0.0", cancellationToken); +#pragma warning restore S1075 // URIs should not be hardcoded try { var fileSaverInstance = new FileSaverImplementation(); diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs index b2d580b7ac..015429590f 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs @@ -5,9 +5,11 @@ public partial class MediaElementCarouselViewViewModel : BaseViewModel { public ObservableCollection ItemSource { get; } = [ - new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), "Buck Bunny", 720, 1280), - new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"), "Elephants Dream", 720, 1280), - new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"), "Sintel", 546, 1280) +#pragma warning disable S1075 // URIs should not be hardcoded + new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), "Buck Bunny", 720, 1280), + new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"), "Elephants Dream", 720, 1280), + new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"), "Sintel", 546, 1280) +#pragma warning restore S1075 // URIs should not be hardcoded ]; } diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs index 3f1358e1b2..8c0aaa7c4f 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs @@ -5,8 +5,10 @@ public partial class MediaElementCollectionViewViewModel : BaseViewModel { public ObservableCollection ItemSource { get; } = [ - new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), "Buck Bunny", 720, 1280), - new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"), "Elephants Dream", 720, 1280), - new(new Uri($"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"), "Sintel", 546, 1280) +#pragma warning disable S1075 // URIs should not be hardcoded + new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), "Buck Bunny", 720, 1280), + new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"), "Elephants Dream", 720, 1280), + new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"), "Sintel", 546, 1280) +#pragma warning restore S1075 // URIs should not be hardcoded ]; } \ No newline at end of file From a073f15333d3799641bdee7c43713b390bc1575b Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Wed, 25 Sep 2024 15:23:32 -0700 Subject: [PATCH 05/13] Missed one $ --- .../Pages/Views/MediaElement/MediaElementPage.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs index 56e6c38460..8b27478832 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs @@ -176,7 +176,6 @@ async void ChangeSourceClicked(Object sender, EventArgs e) MediaElement.Source = MediaSource.FromUri( "https://mtoczko.github.io/hls-test-streams/test-gap/playlist.m3u8"); -#pragma warning restore S1075 // URIs should not be hardcoded return; case resetSource: @@ -210,7 +209,8 @@ async void ChangeSourceClicked(Object sender, EventArgs e) MediaElement.MetadataTitle = "HAL 9000"; MediaElement.MetadataArtist = "HAL 9000 Album"; MediaElement.MetadataArtworkUrl = "https://lh3.googleusercontent.com/pw/AP1GczNRrebWCJvfdIau1EbsyyYiwAfwHS0JXjbioXvHqEwYIIdCzuLodQCZmA57GADIo5iB3yMMx3t_vsefbfoHwSg0jfUjIXaI83xpiih6d-oT7qD_slR0VgNtfAwJhDBU09kS5V2T5ZML-WWZn8IrjD4J-g=w1792-h1024-s-no-gm"; - MediaElement.Source = MediaSource.FromUri($"https://github.com/prof3ssorSt3v3/media-sample-files/raw/master/hal-9000.mp3"); + MediaElement.Source = MediaSource.FromUri("https://github.com/prof3ssorSt3v3/media-sample-files/raw/master/hal-9000.mp3"); +#pragma warning restore S1075 // URIs should not be hardcoded return; } } From 1769b57eb4f56eed5738eeee45ecbbd03b3473c8 Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Wed, 25 Sep 2024 15:37:39 -0700 Subject: [PATCH 06/13] fix Suppresion --- .../Converters/ByteArrayToImageSourceConverterViewModel.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs index 47587d5af5..e17723f420 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs @@ -50,7 +50,9 @@ async Task DownloadDotNetBotImage(CancellationToken token) try { - DotNetBotImageByteArray = await client.GetByteArrayAsync($"https://user-images.githubusercontent.com/13558917/137551073-ac8958bf-83e3-4ae3-8623-4db6dce49d02.png", maximumDownloadTimeCTS.Token).WaitAsync(token).ConfigureAwait(false); +#pragma warning disable S1075 // URIs should not be hardcoded + DotNetBotImageByteArray = await client.GetByteArrayAsync("https://user-images.githubusercontent.com/13558917/137551073-ac8958bf-83e3-4ae3-8623-4db6dce49d02.png", maximumDownloadTimeCTS.Token).WaitAsync(token).ConfigureAwait(false); +#pragma warning restore S1075 // URIs should not be hardcoded await minimumDownloadTimeTask.ConfigureAwait(false); From d0369358662cd3c9f0a8877c6d4bed3ba7637cae Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Fri, 27 Sep 2024 13:52:09 -0700 Subject: [PATCH 07/13] Improve exception logging format across multiple methods Updated logging to use formatted messages with exception details instead of directly logging stack traces. This change affects methods in ByteArrayToImageSourceConverterViewModel.cs, AnimationBehavior.shared.cs, ICommunityToolkitBehavior.shared.cs, TouchBehavior.methods.shared.cs, ValidationBehavior.shared.cs, and BaseConverter.shared.cs. Enhances log readability and debugging efficiency. --- .../ByteArrayToImageSourceConverterViewModel.cs | 2 +- .../Behaviors/AnimationBehavior.shared.cs | 2 +- .../Behaviors/ICommunityToolkitBehavior.shared.cs | 2 +- .../Touch/TouchBehavior.methods.shared.cs | 2 +- .../Behaviors/Validators/ValidationBehavior.shared.cs | 2 +- .../Converters/BaseConverter.shared.cs | 8 ++++---- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs index e17723f420..f7f76a6b57 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs @@ -60,7 +60,7 @@ async Task DownloadDotNetBotImage(CancellationToken token) } catch (Exception e) { - Trace.TraceInformation(e.StackTrace); + Trace.TraceError("Error downloading image: {0}", e); OnImageDownloadFailed(e.Message); } finally diff --git a/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs index a89c5f7938..8983faa62d 100644 --- a/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs @@ -115,7 +115,7 @@ async Task OnAnimate(CancellationToken token) } catch (Exception ex) when (Options.ShouldSuppressExceptionsInAnimations) { - Trace.TraceError(ex.StackTrace); + Trace.TraceError("{0}", ex); } } } \ No newline at end of file diff --git a/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs index 942c871e66..ecb0d49bd9 100644 --- a/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs @@ -89,7 +89,7 @@ protected void OnViewPropertyChanged(object? sender, PropertyChangedEventArgs e) } catch (Exception ex) when (Options.ShouldSuppressExceptionsInBehaviors) { - Trace.TraceError(ex.StackTrace); + Trace.TraceError("{0}", ex); } } diff --git a/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs b/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs index 72691c9fde..ccf29d1673 100644 --- a/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs @@ -63,7 +63,7 @@ internal async Task ForceUpdateState(CancellationToken token, bool animated = tr } catch (TaskCanceledException ex) { - Trace.TraceError(ex.StackTrace); + Trace.TraceError("{0}", ex); } } diff --git a/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs index 88230b0a38..a821e55c16 100644 --- a/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs @@ -397,7 +397,7 @@ async ValueTask UpdateStateAsync(VisualElement? view, ValidationFlags flags, boo IsValid = false; IsRunning = false; - Trace.TraceError(ex.StackTrace); + Trace.TraceError("{0}", ex); } } diff --git a/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs b/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs index 823e50c0d2..575084bf1e 100644 --- a/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs +++ b/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs @@ -73,7 +73,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.TraceError(ex.StackTrace); + Trace.TraceError("{0}", ex); return DefaultConvertBackReturnValue; } } @@ -92,7 +92,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.TraceError(ex.StackTrace); + Trace.TraceError("{0}", ex); return DefaultConvertReturnValue; } } @@ -157,7 +157,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.TraceError(ex.StackTrace); + Trace.TraceError("{0}", ex); return DefaultConvertBackReturnValue; } } @@ -175,7 +175,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.TraceError(ex.StackTrace); + Trace.TraceError("{0}", ex); return DefaultConvertReturnValue; } } From e0917f77ca6126bab3f9755c73693c99266730ae Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Mon, 30 Sep 2024 16:20:03 -0700 Subject: [PATCH 08/13] Define URLs as constant --- .../Pages/Views/Expander/ExpanderPageCS.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs index 2a103f4ddb..aaec91a379 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs @@ -9,9 +9,11 @@ public class ExpanderPageCS : ContentPage { public ExpanderPageCS() { + const string dotnetBotUrl = "https://avatars.githubusercontent.com/u/9011267?v=4"; + const string dotnetMauiUrl = "https://dot.net/maui"; + Title = "Expander Page, C# UI"; - -#pragma warning disable S1075 // URIs should not be hardcoded + Content = new VerticalStackLayout() { Spacing = 12, @@ -37,7 +39,7 @@ public ExpanderPageCS() Content = new VerticalStackLayout() { new Image() - .Source("https://avatars.githubusercontent.com/u/9011267?v=4") + .Source(dotnetBotUrl) .Size(120) .Aspect(Aspect.AspectFit), @@ -47,7 +49,7 @@ public ExpanderPageCS() new Button() .Text("Learn more") - .Invoke(button => button.Clicked += async (s, e) => await Launcher.OpenAsync("https://dot.net/maui")) + .Invoke(button => button.Clicked += static async (_, _) => await Launcher.OpenAsync(dotnetMauiUrl)) }.Padding(10) @@ -58,6 +60,5 @@ public ExpanderPageCS() convert: (int selectedIndex) => Enum.IsDefined(typeof(ExpandDirection), selectedIndex) ? (ExpandDirection)selectedIndex : default) } }; -#pragma warning restore S1075 // URIs should not be hardcoded } } \ No newline at end of file From 1aa7438a2235a409fde64a51281aaa35382221a6 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Mon, 30 Sep 2024 16:26:18 -0700 Subject: [PATCH 09/13] Define URLs as constants --- .../MediaElement/MediaElementPage.xaml.cs | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs index 8b27478832..960a5fded9 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs @@ -10,12 +10,18 @@ namespace CommunityToolkit.Maui.Sample.Pages.Views; public partial class MediaElementPage : BasePage { readonly ILogger logger; + const string loadOnlineMp4 = "Load Online MP4"; const string loadHls = "Load HTTP Live Stream (HLS)"; const string loadLocalResource = "Load Local Resource"; const string resetSource = "Reset Source to null"; const string loadMusic = "Load Music"; + const string buckBunnyMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; + const string botImageUrl = "https://lh3.googleusercontent.com/pw/AP1GczNRrebWCJvfdIau1EbsyyYiwAfwHS0JXjbioXvHqEwYIIdCzuLodQCZmA57GADIo5iB3yMMx3t_vsefbfoHwSg0jfUjIXaI83xpiih6d-oT7qD_slR0VgNtfAwJhDBU09kS5V2T5ZML-WWZn8IrjD4J-g=w1792-h1024-s-no-gm"; + const string hlsStreamTestUrl = "https://mtoczko.github.io/hls-test-streams/test-gap/playlist.m3u8"; + const string hal9000AudioUrl = "https://github.com/prof3ssorSt3v3/media-sample-files/raw/master/hal-9000.mp3"; + public MediaElementPage(MediaElementViewModel viewModel, ILogger logger) : base(viewModel) { InitializeComponent(); @@ -26,7 +32,7 @@ public MediaElementPage(MediaElementViewModel viewModel, ILogger Date: Mon, 30 Sep 2024 16:34:57 -0700 Subject: [PATCH 10/13] Use `const` to define URLs --- .../ByteArrayToImageSourceConverterViewModel.cs | 7 +++---- .../ViewModels/Essentials/FileSaverViewModel.cs | 6 +++--- .../Views/MediaElementCarouselViewViewModel.cs | 12 +++++++----- .../Views/MediaElementCollectionViewViewModel.cs | 12 +++++++----- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs index f7f76a6b57..d6cc7e7809 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ByteArrayToImageSourceConverterViewModel.cs @@ -44,15 +44,14 @@ async Task DownloadDotNetBotImage(CancellationToken token) var maximumDownloadTime = TimeSpan.FromSeconds(5); var maximumDownloadTimeCTS = new CancellationTokenSource(maximumDownloadTime); - // Ensure Activity Indicator appears on screen for a minumum of 1.5 seconds when the user taps the Download Button + // Ensure Activity Indicator appears on screen for a minimum of 1.5 seconds when the user taps the Download Button var minimumDownloadTime = TimeSpan.FromSeconds(1.5); var minimumDownloadTimeTask = Task.Delay(minimumDownloadTime, maximumDownloadTimeCTS.Token).WaitAsync(token); try { -#pragma warning disable S1075 // URIs should not be hardcoded - DotNetBotImageByteArray = await client.GetByteArrayAsync("https://user-images.githubusercontent.com/13558917/137551073-ac8958bf-83e3-4ae3-8623-4db6dce49d02.png", maximumDownloadTimeCTS.Token).WaitAsync(token).ConfigureAwait(false); -#pragma warning restore S1075 // URIs should not be hardcoded + const string dotnetBotImageUrl = "https://user-images.githubusercontent.com/13558917/137551073-ac8958bf-83e3-4ae3-8623-4db6dce49d02.png"; + DotNetBotImageByteArray = await client.GetByteArrayAsync(dotnetBotImageUrl, maximumDownloadTimeCTS.Token).WaitAsync(token).ConfigureAwait(false); await minimumDownloadTimeTask.ConfigureAwait(false); diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs index 4f6aec4a1e..5734a5255f 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs @@ -48,9 +48,9 @@ async Task SaveFileStatic(CancellationToken cancellationToken) async Task SaveFileInstance(CancellationToken cancellationToken) { using var client = new HttpClient(); -#pragma warning disable S1075 // URIs should not be hardcoded - await using var stream = await client.GetStreamAsync("https://www.nuget.org/api/v2/package/CommunityToolkit.Maui/5.0.0", cancellationToken); -#pragma warning restore S1075 // URIs should not be hardcoded + + const string communityToolkitNuGetUrl = "https://www.nuget.org/api/v2/package/CommunityToolkit.Maui/5.0.0" + await using var stream = await client.GetStreamAsync(communityToolkitNuGetUrl, cancellationToken); try { var fileSaverInstance = new FileSaverImplementation(); diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs index 015429590f..7c09970452 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs @@ -3,13 +3,15 @@ namespace CommunityToolkit.Maui.Sample.ViewModels.Views; public partial class MediaElementCarouselViewViewModel : BaseViewModel { + const string buckBunnyMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; + const string elephantsDreamMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"; + const string sintelMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"; + public ObservableCollection ItemSource { get; } = [ -#pragma warning disable S1075 // URIs should not be hardcoded - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), "Buck Bunny", 720, 1280), - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"), "Elephants Dream", 720, 1280), - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"), "Sintel", 546, 1280) -#pragma warning restore S1075 // URIs should not be hardcoded + new(new Uri(buckBunnyMp4Url), "Buck Bunny", 720, 1280), + new(new Uri(elephantsDreamMp4Url), "Elephants Dream", 720, 1280), + new(new Uri(sintelMp4Url), "Sintel", 546, 1280) ]; } diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs index 8c0aaa7c4f..8cc9ffae1a 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs @@ -3,12 +3,14 @@ namespace CommunityToolkit.Maui.Sample.ViewModels.Views; public partial class MediaElementCollectionViewViewModel : BaseViewModel { + const string buckBunnyMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; + const string elephantsDreamMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"; + const string sintelMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"; + public ObservableCollection ItemSource { get; } = [ -#pragma warning disable S1075 // URIs should not be hardcoded - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), "Buck Bunny", 720, 1280), - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"), "Elephants Dream", 720, 1280), - new(new Uri("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"), "Sintel", 546, 1280) -#pragma warning restore S1075 // URIs should not be hardcoded + new(new Uri(buckBunnyMp4Url), "Buck Bunny", 720, 1280), + new(new Uri(elephantsDreamMp4Url), "Elephants Dream", 720, 1280), + new(new Uri(sintelMp4Url), "Sintel", 546, 1280) ]; } \ No newline at end of file From a085b19aa39d26b381b619c0e1d7dffafa084625 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Mon, 30 Sep 2024 16:35:12 -0700 Subject: [PATCH 11/13] Replace `TraceError` with `TraceInformation` --- .../Behaviors/AnimationBehavior.shared.cs | 2 +- .../Behaviors/ICommunityToolkitBehavior.shared.cs | 2 +- .../Touch/TouchBehavior.methods.shared.cs | 2 +- .../Validators/MultiValidationBehavior.shared.cs | 8 ++++---- .../Behaviors/Validators/ValidationBehavior.shared.cs | 2 +- .../Converters/BaseConverter.shared.cs | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs index 8983faa62d..87247e8ea2 100644 --- a/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs @@ -115,7 +115,7 @@ async Task OnAnimate(CancellationToken token) } catch (Exception ex) when (Options.ShouldSuppressExceptionsInAnimations) { - Trace.TraceError("{0}", ex); + Trace.TraceInformation("{0}", ex); } } } \ No newline at end of file diff --git a/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs index ecb0d49bd9..05fcf3ce51 100644 --- a/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/ICommunityToolkitBehavior.shared.cs @@ -89,7 +89,7 @@ protected void OnViewPropertyChanged(object? sender, PropertyChangedEventArgs e) } catch (Exception ex) when (Options.ShouldSuppressExceptionsInBehaviors) { - Trace.TraceError("{0}", ex); + Trace.TraceInformation("{0}", ex); } } diff --git a/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs b/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs index ccf29d1673..5f85cd6811 100644 --- a/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs @@ -63,7 +63,7 @@ internal async Task ForceUpdateState(CancellationToken token, bool animated = tr } catch (TaskCanceledException ex) { - Trace.TraceError("{0}", ex); + Trace.TraceInformation("{0}", ex); } } diff --git a/src/CommunityToolkit.Maui/Behaviors/Validators/MultiValidationBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/Validators/MultiValidationBehavior.shared.cs index ea1c3651b0..5275c32094 100644 --- a/src/CommunityToolkit.Maui/Behaviors/Validators/MultiValidationBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/Validators/MultiValidationBehavior.shared.cs @@ -66,9 +66,9 @@ await Task.WhenAll(children.Select(c => return c.ValidateNestedAsync(token).AsTask(); })).ConfigureAwait(false); - var errors = children.Where(c => c.IsNotValid).Select(GetError).ToList(); + var errors = children.Where(static c => c.IsNotValid).Select(GetError).ToList(); - if (!errors.Any()) + if (errors.Count is 0) { Errors = null; return true; @@ -82,7 +82,7 @@ await Task.WhenAll(children.Select(c => return false; } - void OnChildrenCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + static void OnChildrenCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems is not null) { @@ -91,7 +91,7 @@ void OnChildrenCollectionChanged(object? sender, NotifyCollectionChangedEventArg var isSuccessful = ((ICommunityToolkitBehavior)child).TrySetBindingContextToAttachedViewBindingContext(); if (!isSuccessful) { - Trace.TraceError($"Setting {nameof(BindingContext)} for {child.GetType()} failed"); + Trace.TraceInformation($"Setting {nameof(BindingContext)} for {child.GetType()} failed"); } } } diff --git a/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs b/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs index a821e55c16..4a22bb6e4e 100644 --- a/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs +++ b/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs @@ -397,7 +397,7 @@ async ValueTask UpdateStateAsync(VisualElement? view, ValidationFlags flags, boo IsValid = false; IsRunning = false; - Trace.TraceError("{0}", ex); + Trace.TraceInformation("{0}", ex); } } diff --git a/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs b/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs index 575084bf1e..cf020e530b 100644 --- a/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs +++ b/src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs @@ -73,7 +73,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.TraceError("{0}", ex); + Trace.TraceInformation("{0}", ex); return DefaultConvertBackReturnValue; } } @@ -92,7 +92,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.TraceError("{0}", ex); + Trace.TraceInformation("{0}", ex); return DefaultConvertReturnValue; } } @@ -157,7 +157,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.TraceError("{0}", ex); + Trace.TraceInformation("{0}", ex); return DefaultConvertBackReturnValue; } } @@ -175,7 +175,7 @@ public abstract class BaseConverter<[DynamicallyAccessedMembers(DynamicallyAcces } catch (Exception ex) when (Options.ShouldSuppressExceptionsInConverters) { - Trace.TraceError("{0}", ex); + Trace.TraceInformation("{0}", ex); return DefaultConvertReturnValue; } } From a35eee0e0a9d7e2ae82e9d037c6d1219f64d6a2a Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Mon, 30 Sep 2024 16:45:28 -0700 Subject: [PATCH 12/13] Add missing `;` --- .../ViewModels/Essentials/FileSaverViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs index 5734a5255f..e3d701bac3 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/FileSaverViewModel.cs @@ -48,8 +48,8 @@ async Task SaveFileStatic(CancellationToken cancellationToken) async Task SaveFileInstance(CancellationToken cancellationToken) { using var client = new HttpClient(); - - const string communityToolkitNuGetUrl = "https://www.nuget.org/api/v2/package/CommunityToolkit.Maui/5.0.0" + + const string communityToolkitNuGetUrl = "https://www.nuget.org/api/v2/package/CommunityToolkit.Maui/5.0.0"; await using var stream = await client.GetStreamAsync(communityToolkitNuGetUrl, cancellationToken); try { From 7e562f988e39a8ca146d4286d3e3a0e63b292ab0 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Mon, 30 Sep 2024 16:46:22 -0700 Subject: [PATCH 13/13] `dotnet format` --- .../Pages/Views/Expander/ExpanderPageCS.cs | 4 ++-- .../Pages/Views/MediaElement/MediaElementPage.xaml.cs | 6 +++--- .../ViewModels/Views/MediaElementCarouselViewViewModel.cs | 2 +- .../ViewModels/Views/MediaElementCollectionViewViewModel.cs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs index aaec91a379..71ee424832 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs @@ -11,9 +11,9 @@ public ExpanderPageCS() { const string dotnetBotUrl = "https://avatars.githubusercontent.com/u/9011267?v=4"; const string dotnetMauiUrl = "https://dot.net/maui"; - + Title = "Expander Page, C# UI"; - + Content = new VerticalStackLayout() { Spacing = 12, diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs index 960a5fded9..819e1c9441 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs @@ -219,13 +219,13 @@ async void ChangeSourceClicked(Object sender, EventArgs e) async void ChangeAspectClicked(object? sender, EventArgs e) { const string cancel = "Cancel"; - + var resultAspect = await DisplayActionSheet( "Choose aspect ratio", - cancel, + cancel, null, Aspect.AspectFit.ToString(), - Aspect.AspectFill.ToString(), + Aspect.AspectFill.ToString(), Aspect.Fill.ToString()); if (resultAspect is null or cancel) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs index 7c09970452..a9715ebffd 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCarouselViewViewModel.cs @@ -6,7 +6,7 @@ public partial class MediaElementCarouselViewViewModel : BaseViewModel const string buckBunnyMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; const string elephantsDreamMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"; const string sintelMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"; - + public ObservableCollection ItemSource { get; } = [ new(new Uri(buckBunnyMp4Url), "Buck Bunny", 720, 1280), diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs index 8cc9ffae1a..8df3f64fb4 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElementCollectionViewViewModel.cs @@ -6,7 +6,7 @@ public partial class MediaElementCollectionViewViewModel : BaseViewModel const string buckBunnyMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; const string elephantsDreamMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"; const string sintelMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"; - + public ObservableCollection ItemSource { get; } = [ new(new Uri(buckBunnyMp4Url), "Buck Bunny", 720, 1280),