Enable analytics in UWP sample app

このコミットが含まれているのは:
Sergio Pedri committed 2022-01-06 00:41:31 +01:00
1 親 c06594c0d0
コミット 66994c6333
11ファイル変更
+139 -20

検索条件に一致するファイルはありません

@@ -9,6 +9,7 @@
<Import_RootNamespace>ComputeSharp.SwapChain.Core.Shared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Constants\Event.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\RenderingPauseConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\ResolutionScaleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\ComputeShader.cs" />
+16
ファイルの表示
@@ -0,0 +1,16 @@
namespace ComputeSharp.SwapChain.Core.Constants;
/// <summary>
/// A <see langword="class"/> with the collection of tracked events for analytics.
/// </summary>
public static class Event
{
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";
public const string RenderingFailedOnMainPanel = "[SHELL] RenderingFailed (main panel)";
public const string RenderingFailedOnSelectionPanel = "[SHELL] RenderingFailed (selection panel)";
}
+25 -3
ファイルの表示
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Text;
#nullable enable
@@ -11,7 +12,7 @@ namespace ComputeSharp.SwapChain.Core.Services;
public sealed class DebugAnalyticsService : IAnalyticsService
{
/// <inheritdoc/>
public void Log(string title, params (string Property, string Value)[]? data)
public void Log(string title, params (string Property, object? Value)[]? data)
{
StringBuilder builder = new();
@@ -21,7 +22,28 @@ public sealed class DebugAnalyticsService : IAnalyticsService
{
foreach (var info in data)
{
builder.AppendLine($">> {info.Property}: \"{info.Value}\"");
builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
}
}
Trace.Write(builder);
}
/// <inheritdoc/>
public void Log(string title, Exception exception, params (string Property, object? Value)[]? data)
{
StringBuilder builder = new();
builder.AppendLine($"[EXCEPTION]: \"{title}\"");
builder.AppendLine($">> Type: \"{exception.GetType()}\"");
builder.AppendLine(">> Stack trace");
builder.AppendLine(exception.StackTrace);
if (data is not null)
{
foreach (var info in data)
{
builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
}
}
+12 -2
ファイルの表示
@@ -1,4 +1,6 @@
#nullable enable
using System;
#nullable enable
namespace ComputeSharp.SwapChain.Core.Services;
@@ -12,5 +14,13 @@ public interface IAnalyticsService
/// </summary>
/// <param name="title">The title of the event to track.</param>
/// <param name="data">The optional event properties.</param>
void Log(string title, params (string Property, string Value)[]? data);
void Log(string title, params (string Property, object? Value)[]? data);
/// <summary>
/// Logs an exception with a specified title and optional properties.
/// </summary>
/// <param name="title">The title of the event to track.</param>
/// <param name="exception">The exception that has been thrown.</param>
/// <param name="data">The optional event properties.</param>
void Log(string title, Exception exception, params (string Property, object? Value)[]? data);
}
+24 -3
ファイルの表示
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ComputeSharp.SwapChain.Core.Constants;
using ComputeSharp.SwapChain.Core.Models;
using ComputeSharp.SwapChain.Core.Services;
using ComputeSharp.SwapChain.Core.Shaders.Runners;
@@ -56,7 +57,13 @@ public sealed class MainViewModel : ObservableObject
public bool IsDynamicResolutionEnabled
{
get => this.isDynamicResolutionEnabled;
set => SetProperty(ref this.isDynamicResolutionEnabled, value);
set
{
if (SetProperty(ref this.isDynamicResolutionEnabled, value))
{
this.analyticsService.Log(Event.IsDynamicResolutionEnabledChanged, (nameof(value), value));
}
}
}
private int selectedResolutionScale;
@@ -67,7 +74,13 @@ public sealed class MainViewModel : ObservableObject
public int SelectedResolutionScale
{
get => this.selectedResolutionScale;
private set => SetProperty(ref this.selectedResolutionScale, value);
private set
{
if (SetProperty(ref this.selectedResolutionScale, value))
{
this.analyticsService.Log(Event.SelectedResolutionScaleChanged, (nameof(value), value));
}
}
}
/// <summary>
@@ -115,6 +128,8 @@ public sealed class MainViewModel : ObservableObject
if (SetProperty(ref this.selectedComputeShader, value) &&
value is not null)
{
this.analyticsService.Log(Event.SelectedComputeShaderChanged, (nameof(value.ShaderRunner), value.ShaderRunner));
value.IsSelected = true;
}
}
@@ -128,7 +143,13 @@ public sealed class MainViewModel : ObservableObject
public bool IsRenderingPaused
{
get => this.isRenderingPaused;
set => SetProperty(ref this.isRenderingPaused, value);
set
{
if (SetProperty(ref this.isRenderingPaused, value))
{
this.analyticsService.Log(Event.IsRenderingPausedChanged, (nameof(value), value));
}
}
}
/// <summary>