From aa15871666b85177b99042e6398eb9489aeec3cd Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 21 Aug 2024 23:35:56 -0700 Subject: [PATCH] Remove analytics service from WinUI sample app --- .../Constants/Error.cs | 10 ---- .../Constants/Event.cs | 16 ------ .../Services/DebugAnalyticsService.cs | 49 ------------------- .../Services/IAnalyticsService.cs | 23 --------- .../ViewModels/MainViewModel.cs | 49 +------------------ .../Views/MainWindow.xaml | 7 ++- .../Views/MainWindow.xaml.cs | 8 --- 7 files changed, 6 insertions(+), 156 deletions(-) delete mode 100644 samples/ComputeSharp.SwapChain.WinUI/Constants/Error.cs delete mode 100644 samples/ComputeSharp.SwapChain.WinUI/Constants/Event.cs delete mode 100644 samples/ComputeSharp.SwapChain.WinUI/Services/DebugAnalyticsService.cs delete mode 100644 samples/ComputeSharp.SwapChain.WinUI/Services/IAnalyticsService.cs diff --git a/samples/ComputeSharp.SwapChain.WinUI/Constants/Error.cs b/samples/ComputeSharp.SwapChain.WinUI/Constants/Error.cs deleted file mode 100644 index 3665d3dd..00000000 --- a/samples/ComputeSharp.SwapChain.WinUI/Constants/Error.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ComputeSharp.SwapChain.Core.Constants; - -/// -/// A with the collection of tracked errors for analytics. -/// -public static class Error -{ - public const string RenderingFailedOnMainPanel = "[SHELL] RenderingFailed (main panel)"; - public const string RenderingFailedOnSelectionPanel = "[SHELL] RenderingFailed (selection panel)"; -} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.WinUI/Constants/Event.cs b/samples/ComputeSharp.SwapChain.WinUI/Constants/Event.cs deleted file mode 100644 index 6e4b8268..00000000 --- a/samples/ComputeSharp.SwapChain.WinUI/Constants/Event.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace ComputeSharp.SwapChain.Core.Constants; - -/// -/// A with the collection of tracked events for analytics. -/// -public static class Event -{ - public const string SelectedRenderingModeChanged = "[SETTINGS] SelectedRenderingMode"; - public const string IsVerticalSyncEnabledChanged = "[SETTINGS] IsVerticalSyncEnabled"; - public const string IsDynamicResolutionEnabledChanged = "[SETTINGS] IsDynamicResolutionEnabled"; - public const string SelectedResolutionScaleChanged = "[SETTINGS] SelectedResolutionScale"; - public const string SelectedComputeShaderChanged = "[SETTINGS] SelectedComputeShader"; - public const string IsRenderingPausedChanged = "[SETTINGS] IsRenderingPaused"; - public const string OpenShaderSelectionPanel = "[SHELL] Open ShaderSelectionPanel"; - public const string CloseShaderSelectionPanel = "[SHELL] Close ShaderSelectionPanel"; -} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.WinUI/Services/DebugAnalyticsService.cs b/samples/ComputeSharp.SwapChain.WinUI/Services/DebugAnalyticsService.cs deleted file mode 100644 index 4cfa34c3..00000000 --- a/samples/ComputeSharp.SwapChain.WinUI/Services/DebugAnalyticsService.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Diagnostics; -using System.Text; - -namespace ComputeSharp.SwapChain.Core.Services; - -/// -/// A that manages the analytics service in a test environment. -/// -public sealed class DebugAnalyticsService : IAnalyticsService -{ - /// - public void Log(string title, params (string Property, object? Value)[]? data) - { - StringBuilder builder = new(); - - _ = builder.AppendLine($"[EVENT]: \"{title}\""); - - if (data is not null) - { - foreach ((string Property, object? Value) info in data) - { - _ = builder.AppendLine($">> {info.Property}: \"{info.Value ?? ""}\""); - } - } - - Trace.Write(builder); - } - - /// - public void Log(Exception exception, params (string Property, object? Value)[]? data) - { - StringBuilder builder = new(); - - _ = builder.AppendLine($"[EXCEPTION]: \"{exception.GetType()}\""); - _ = builder.AppendLine(">> Stack trace"); - _ = builder.AppendLine(exception.StackTrace); - - if (data is not null) - { - foreach ((string Property, object? Value) info in data) - { - _ = builder.AppendLine($">> {info.Property}: \"{info.Value ?? ""}\""); - } - } - - Trace.Write(builder); - } -} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.WinUI/Services/IAnalyticsService.cs b/samples/ComputeSharp.SwapChain.WinUI/Services/IAnalyticsService.cs deleted file mode 100644 index b1b63ee9..00000000 --- a/samples/ComputeSharp.SwapChain.WinUI/Services/IAnalyticsService.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace ComputeSharp.SwapChain.Core.Services; - -/// -/// The default for an analytics service. -/// -public interface IAnalyticsService -{ - /// - /// Logs an event with a specified title and optional properties. - /// - /// The title of the event to track. - /// The optional event properties. - void Log(string title, params (string Property, object? Value)[]? data); - - /// - /// Logs an exception with optional properties. - /// - /// The exception that has been thrown. - /// The optional event properties. - void Log(Exception exception, params (string Property, object? Value)[]? data); -} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs b/samples/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs index f978d35c..7abe34bf 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs @@ -1,10 +1,7 @@ using System.Collections.Generic; -using CommunityToolkit.Diagnostics; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using ComputeSharp.SwapChain.Core.Constants; using ComputeSharp.SwapChain.Core.Enums; -using ComputeSharp.SwapChain.Core.Services; using ComputeSharp.SwapChain.Core.Shaders; using ComputeSharp.SwapChain.Core.Shaders.Runners; using ComputeSharp.SwapChain.Shaders; @@ -17,19 +14,11 @@ namespace ComputeSharp.SwapChain.Core.ViewModels; /// public sealed partial class MainViewModel : ObservableObject { - /// - /// The instance currently in use. - /// - private readonly IAnalyticsService analyticsService; - /// /// Creates a new instance. /// - public MainViewModel(IAnalyticsService analyticsService) + public MainViewModel() { - Guard.IsNotNull(analyticsService); - - this.analyticsService = analyticsService; this.selectedRenderingMode = RenderingMode.DirectX12; this.isVerticalSyncEnabled = true; this.isDynamicResolutionEnabled = true; @@ -157,46 +146,10 @@ public sealed partial class MainViewModel : ObservableObject IsRenderingPaused = !IsRenderingPaused; } - /// - partial void OnSelectedRenderingModeChanged(RenderingMode value) - { - this.analyticsService.Log(Event.SelectedRenderingModeChanged, (nameof(value), value)); - } - - /// - partial void OnIsVerticalSyncEnabledChanged(bool value) - { - this.analyticsService.Log(Event.IsVerticalSyncEnabledChanged, (nameof(value), value)); - } - - /// - partial void OnIsDynamicResolutionEnabledChanged(bool value) - { - this.analyticsService.Log(Event.IsDynamicResolutionEnabledChanged, (nameof(value), value)); - } - - /// - partial void OnSelectedResolutionScaleChanged(int value) - { - this.analyticsService.Log(Event.SelectedResolutionScaleChanged, (nameof(value), value)); - } - /// partial void OnSelectedComputeShaderChanging(ShaderRunnerViewModel? oldValue, ShaderRunnerViewModel newValue) { oldValue!.IsSelected = false; newValue.IsSelected = true; } - - /// - partial void OnSelectedComputeShaderChanged(ShaderRunnerViewModel value) - { - this.analyticsService.Log(Event.SelectedComputeShaderChanged, (nameof(value.ShaderType), value.ShaderType)); - } - - /// - partial void OnIsRenderingPausedChanged(bool value) - { - this.analyticsService.Log(Event.IsRenderingPausedChanged, (nameof(value), value)); - } } \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml index 410e1310..7ae8318a 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml +++ b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml @@ -9,11 +9,14 @@ xmlns:enums="using:ComputeSharp.SwapChain.Core.Enums" xmlns:media="using:CommunityToolkit.WinUI.UI.Media" xmlns:ui="using:CommunityToolkit.WinUI.UI" - xmlns:viewmodels="using:ComputeSharp.SwapChain.Core.ViewModels" + xmlns:viewModels="using:ComputeSharp.SwapChain.Core.ViewModels" xmlns:views="using:ComputeSharp.SwapChain.WinUI.Views" SizeChanged="Window_SizeChanged"> + + + - + - /// Gets the instance for the current view. - /// - public MainViewModel ViewModel => (MainViewModel)this.Root.DataContext; - /// /// Stops all rendering when the application is closing. ///