Merge pull request #188 from Sergio0694/feature/sample-app-analytics
Add AppCenter analytics to UWP sample app
このコミットが含まれているのは:
17ファイル変更
+372
-26
検索条件に一致するファイルはありません
@@ -3,6 +3,9 @@
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# App tokens
|
||||
**/ServiceTokens/
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
# Create the tokens folder
|
||||
$TOKENS_FOLDER_RELATIVE_PATH = Join-Path -Path $PSScriptRoot -ChildPath "..\samples\ComputeSharp.SwapChain.Uwp\Assets\ServiceTokens"
|
||||
if(!(Test-Path -Path $TOKENS_FOLDER_RELATIVE_PATH)) {
|
||||
New-Item -ItemType directory -Path $TOKENS_FOLDER_RELATIVE_PATH
|
||||
}
|
||||
$TOKENS_FOLDER_PATH = Resolve-Path -Path $TOKENS_FOLDER_RELATIVE_PATH
|
||||
|
||||
# AppCenter tokens
|
||||
$APPCENTER_TOKENS_NAME = "AppCenter.txt"
|
||||
$APPCENTER_TOKENS_PATH = Join-Path -Path $TOKENS_FOLDER_PATH -ChildPath $APPCENTER_TOKENS_NAME
|
||||
if (!(Test-Path -Path $APPCENTER_TOKENS_PATH))
|
||||
{
|
||||
echo "<APP_CENTER_SECRET>" > $APPCENTER_TOKENS_PATH
|
||||
}
|
||||
@@ -9,9 +9,12 @@
|
||||
<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" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Services\DebugAnalyticsService.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Services\IAnalyticsService.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\Runners\ContouredLayersRunner.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\MainViewModel.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -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)";
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that manages the analytics service in a test environment.
|
||||
/// </summary>
|
||||
public sealed class DebugAnalyticsService : IAnalyticsService
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Log(string title, params (string Property, object? Value)[]? data)
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
|
||||
builder.AppendLine($"[EVENT]: \"{title}\"");
|
||||
|
||||
if (data is not null)
|
||||
{
|
||||
foreach (var info in data)
|
||||
{
|
||||
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>"}\"");
|
||||
}
|
||||
}
|
||||
|
||||
Trace.Write(builder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// The default <see langword="interface"/> for an analytics service.
|
||||
/// </summary>
|
||||
public interface IAnalyticsService
|
||||
{
|
||||
/// <summary>
|
||||
/// Logs an event with a specified title and optional properties.
|
||||
/// </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, 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);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
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;
|
||||
using ComputeSharp.SwapChain.Shaders;
|
||||
#if WINDOWS_UWP
|
||||
@@ -9,6 +11,7 @@ using ComputeSharp.Uwp;
|
||||
#else
|
||||
using ComputeSharp.WinUI;
|
||||
#endif
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
#nullable enable
|
||||
|
||||
@@ -19,11 +22,19 @@ namespace ComputeSharp.SwapChain.Core.ViewModels;
|
||||
/// </summary>
|
||||
public sealed class MainViewModel : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="IAnalyticsService"/> instance currently in use.
|
||||
/// </summary>
|
||||
private readonly IAnalyticsService analyticsService;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MainViewModel"/> instance.
|
||||
/// </summary>
|
||||
public MainViewModel()
|
||||
public MainViewModel(IAnalyticsService analyticsService)
|
||||
{
|
||||
Guard.IsNotNull(analyticsService, nameof(analyticsService));
|
||||
|
||||
this.analyticsService = analyticsService;
|
||||
this.isDynamicResolutionEnabled = true;
|
||||
this.selectedResolutionScale = 100;
|
||||
this.selectedComputeShader = ComputeShaderOptions[0];
|
||||
@@ -46,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;
|
||||
@@ -57,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>
|
||||
@@ -78,16 +101,16 @@ public sealed class MainViewModel : ObservableObject
|
||||
/// </summary>
|
||||
public IReadOnlyList<ComputeShader> ComputeShaderOptions { get; } = new ComputeShader[]
|
||||
{
|
||||
new("Colorful infinity", new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds))),
|
||||
new("Extruded truchet", new ShaderRunner<ExtrudedTruchetPattern>(static time => new((float)time.TotalSeconds))),
|
||||
new("Fractal tiling", new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds))),
|
||||
new("Menger Journey", new ShaderRunner<MengerJourney>(static time => new((float)time.TotalSeconds))),
|
||||
new("Octagrams", new ShaderRunner<Octagrams>(static time => new((float)time.TotalSeconds))),
|
||||
new("Protean clouds", new ShaderRunner<ProteanClouds>(static time => new((float)time.TotalSeconds))),
|
||||
new("Two tiled truchet", new ShaderRunner<TwoTiledTruchet>(static time => new((float)time.TotalSeconds))),
|
||||
new("Pyramid pattern", new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds))),
|
||||
new("Triangle grid contouring", new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds))),
|
||||
new("Contoured layers", new ContouredLayersRunner())
|
||||
new("Colorful infinity", new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds))),
|
||||
new("Extruded truchet", new ShaderRunner<ExtrudedTruchetPattern>(static time => new((float)time.TotalSeconds))),
|
||||
new("Fractal tiling", new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds))),
|
||||
new("Menger Journey", new ShaderRunner<MengerJourney>(static time => new((float)time.TotalSeconds))),
|
||||
new("Octagrams", new ShaderRunner<Octagrams>(static time => new((float)time.TotalSeconds))),
|
||||
new("Protean clouds", new ShaderRunner<ProteanClouds>(static time => new((float)time.TotalSeconds))),
|
||||
new("Two tiled truchet", new ShaderRunner<TwoTiledTruchet>(static time => new((float)time.TotalSeconds))),
|
||||
new("Pyramid pattern", new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds))),
|
||||
new("Triangle grid contouring", new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds))),
|
||||
new("Contoured layers", new ContouredLayersRunner())
|
||||
};
|
||||
|
||||
private ComputeShader selectedComputeShader;
|
||||
@@ -105,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;
|
||||
}
|
||||
}
|
||||
@@ -118,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>
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
using ComputeSharp.SwapChain.Uwp.Views;
|
||||
#if !DEBUG
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
#endif
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using ComputeSharp.SwapChain.Core.Services;
|
||||
using ComputeSharp.SwapChain.Core.ViewModels;
|
||||
#if !DEBUG
|
||||
using ComputeSharp.SwapChain.Uwp.Extensions;
|
||||
using ComputeSharp.SwapChain.Uwp.Services;
|
||||
#endif
|
||||
using ComputeSharp.SwapChain.Uwp.Views;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.ApplicationModel.Core;
|
||||
using Windows.UI;
|
||||
using Windows.UI.ViewManagement;
|
||||
using Windows.UI.Xaml;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Uwp;
|
||||
|
||||
/// <summary>
|
||||
@@ -13,7 +28,7 @@ namespace ComputeSharp.SwapChain.Uwp;
|
||||
sealed partial class App : Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||
/// </summary>
|
||||
public App()
|
||||
@@ -26,6 +41,7 @@ sealed partial class App : Application
|
||||
{
|
||||
if (Window.Current.Content is not MainView)
|
||||
{
|
||||
ConfigureServices();
|
||||
StyleTitleBar();
|
||||
ExpandViewIntoTitleBar();
|
||||
|
||||
@@ -38,6 +54,33 @@ sealed partial class App : Application
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the services for the application.
|
||||
/// </summary>
|
||||
private static void ConfigureServices()
|
||||
{
|
||||
ServiceCollection services = new();
|
||||
|
||||
#if !DEBUG
|
||||
if (!Debugger.IsAttached &&
|
||||
Assembly.GetExecutingAssembly().TryReadAllTextFromManifestFile("Assets/ServiceTokens/AppCenter.txt", out string? secret) &&
|
||||
Guid.TryParse(secret, out _))
|
||||
{
|
||||
services.AddSingleton<IAnalyticsService>(new AppCenterService(secret!));
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddSingleton<IAnalyticsService, DebugAnalyticsService>();
|
||||
}
|
||||
#else
|
||||
services.AddSingleton<IAnalyticsService, DebugAnalyticsService>();
|
||||
#endif
|
||||
|
||||
services.AddTransient<MainViewModel>();
|
||||
|
||||
Ioc.Default.ConfigureServices(services.BuildServiceProvider());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Styles the title bar buttons according to the theme in use
|
||||
/// </summary>
|
||||
|
||||
@@ -122,8 +122,10 @@
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Extensions\AssemblyExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\SkipLocalsInitAttribute.cs" />
|
||||
<Compile Include="Services\AppCenterService.cs" />
|
||||
<Compile Include="Views\MainView.xaml.cs">
|
||||
<DependentUpon>MainView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -146,6 +148,7 @@
|
||||
<Link>Assets\Textures\RustyMetal.png</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<EmbeddedResource Include="Assets\ServiceTokens\AppCenter.txt" />
|
||||
<Content Include="Assets\SmallTile.scale-100.png" />
|
||||
<Content Include="Assets\SmallTile.scale-125.png" />
|
||||
<Content Include="Assets\SmallTile.scale-150.png" />
|
||||
@@ -204,6 +207,15 @@
|
||||
<PackageReference Include="CommunityToolkit.Mvvm">
|
||||
<Version>7.1.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AppCenter.Analytics">
|
||||
<Version>4.4.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AppCenter.Crashes">
|
||||
<Version>4.4.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
|
||||
<Version>6.0.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||
<Version>6.2.13</Version>
|
||||
</PackageReference>
|
||||
@@ -232,6 +244,9 @@
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)\build\CreateBlankAppCenterToken.ps1</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Uwp.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Helpers for the <see cref="Assembly"/> type.
|
||||
/// </summary>
|
||||
public static class AssemblyExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to read a <see cref="string"/> from a specified file in the target <see cref="Assembly"/>.
|
||||
/// </summary>
|
||||
/// <param name="assembly">The target <see cref="Assembly"/> to read data from.</param>
|
||||
/// <param name="filename">The target filename to read from.</param>
|
||||
/// <param name="text">The resulting text, if the read was successful.</param>
|
||||
/// <returns>The contents of the specified file.</returns>
|
||||
public static bool TryReadAllTextFromManifestFile(this Assembly assembly, string filename, out string? text)
|
||||
{
|
||||
Guard.IsNotNull(assembly, nameof(assembly));
|
||||
Guard.IsNotNull(filename, nameof(filename));
|
||||
|
||||
try
|
||||
{
|
||||
string manifestFilename = $"{assembly.GetName().Name}.{filename.Replace('/', '.').Replace('\\', '.')}";
|
||||
|
||||
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestFilename);
|
||||
using StreamReader reader = new(stream);
|
||||
|
||||
text = reader.ReadToEnd().Trim();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
text = null;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
<Identity
|
||||
Name="26577SergioPedri.ComputeSharpSampleApp"
|
||||
Publisher="CN=46C587B2-48EE-4200-9544-40C64534E565"
|
||||
Version="1.0.0.0" />
|
||||
Version="0.0.5.0" />
|
||||
|
||||
<mp:PhoneIdentity PhoneProductId="85b5430e-b15d-4364-a837-e4c49f3f3f77" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
|
||||
@@ -48,4 +48,8 @@
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
||||
<Capabilities>
|
||||
<Capability Name="internetClient"/>
|
||||
</Capabilities>
|
||||
</Package>
|
||||
@@ -17,5 +17,10 @@
|
||||
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Application>
|
||||
|
||||
<!-- Shader types need their info preserved for logging -->
|
||||
<Type Name="ComputeSharp.Uwp.ShaderRunner`1" Activate="Required Public" />
|
||||
<Namespace Name="ComputeSharp.SwapChain.Core.Shaders.Runners" Activate="Required Public" />
|
||||
<Namespace Name="ComputeSharp.SwapChain.Shaders" Activate="Required Public" />
|
||||
</Application>
|
||||
</Directives>
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ComputeSharp.SwapChain.Core.Services;
|
||||
using Microsoft.AppCenter;
|
||||
using Microsoft.AppCenter.Analytics;
|
||||
using Microsoft.AppCenter.Crashes;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Uwp.Services;
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IAnalyticsService"/> implementation using AppCenter.
|
||||
/// </summary>
|
||||
public sealed class AppCenterService : IAnalyticsService
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum length for any property name and value
|
||||
/// </summary>
|
||||
/// <remarks>It's 125, but one character is reserved for the leading '|' to indicate trimming.</remarks>
|
||||
private const int PropertyStringMaxLength = 124;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public AppCenterService(string secret)
|
||||
{
|
||||
AppCenter.Start(secret, typeof(Crashes), typeof(Analytics));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Log(string title, params (string Property, object? Value)[]? data)
|
||||
{
|
||||
Analytics.TrackEvent(title, GetProperties(data));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Log(string title, Exception exception, params (string Property, object? Value)[]? data)
|
||||
{
|
||||
Crashes.TrackError(exception, GetProperties(data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the additional logging properties from the input data.
|
||||
/// </summary>
|
||||
/// <param name="data">The optional event properties.</param>
|
||||
/// <returns>The additional logging properties to track.</returns>
|
||||
private static IDictionary<string, string>? GetProperties((string Property, object? Value)[]? data)
|
||||
{
|
||||
return
|
||||
data?.ToDictionary(
|
||||
pair => pair.Property,
|
||||
pair =>
|
||||
{
|
||||
string text = (pair.Value ?? "<NULL>").ToString();
|
||||
|
||||
return text.Length <= PropertyStringMaxLength
|
||||
? text
|
||||
: $"|{text.Substring(text.Length - PropertyStringMaxLength)}";
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,12 @@
|
||||
xmlns:media="using:Microsoft.Toolkit.Uwp.UI.Media"
|
||||
xmlns:models="using:ComputeSharp.SwapChain.Core.Models"
|
||||
xmlns:ui="using:Microsoft.Toolkit.Uwp.UI"
|
||||
xmlns:viewmodels="using:ComputeSharp.SwapChain.Core.ViewModels"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="400"
|
||||
SizeChanged="UserControl_SizeChanged"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid x:Name="Root">
|
||||
<Grid.DataContext>
|
||||
<viewmodels:MainViewModel x:Name="ViewModel" />
|
||||
</Grid.DataContext>
|
||||
<Grid.Resources>
|
||||
|
||||
<!--
|
||||
@@ -125,7 +121,7 @@
|
||||
<Grid>
|
||||
|
||||
<!-- Shader preview -->
|
||||
<computesharp:AnimatedComputeShaderPanel ShaderRunner="{x:Bind ShaderRunner}" />
|
||||
<computesharp:AnimatedComputeShaderPanel RenderingFailed="SelectionShaderPanel_RenderingFailed" ShaderRunner="{x:Bind ShaderRunner}" />
|
||||
|
||||
<!--
|
||||
Note: here we have a selection property to work around {x:Bind} not working correctly outside of the
|
||||
@@ -158,6 +154,7 @@
|
||||
Grid.Row="1"
|
||||
IsDynamicResolutionEnabled="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=OneWay}"
|
||||
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"
|
||||
RenderingFailed="MainShaderPanel_RenderingFailed"
|
||||
ResolutionScale="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToScale(ViewModel.SelectedResolutionScale), Mode=OneWay}"
|
||||
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}" />
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using ComputeSharp.SwapChain.Core.Constants;
|
||||
using ComputeSharp.SwapChain.Core.Services;
|
||||
using ComputeSharp.SwapChain.Core.ViewModels;
|
||||
using ComputeSharp.Uwp;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Input;
|
||||
@@ -13,11 +18,19 @@ public sealed partial class MainView : UserControl
|
||||
public MainView()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.DataContext = Ioc.Default.GetRequiredService<MainViewModel>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="MainViewModel"/> instance for the current view.
|
||||
/// </summary>
|
||||
public MainViewModel ViewModel => (MainViewModel)DataContext;
|
||||
|
||||
// Opens the shader selection panel
|
||||
private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.OpenShaderSelectionPanel);
|
||||
|
||||
Root.Resources.Remove("ShaderSelectionPanel");
|
||||
Root.Children.Add(ShaderSelectionPanel);
|
||||
}
|
||||
@@ -25,6 +38,8 @@ public sealed partial class MainView : UserControl
|
||||
// Hides the shader selection panel
|
||||
private void ShaderSelectionPanel_Tapped(object sender, TappedRoutedEventArgs e)
|
||||
{
|
||||
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.CloseShaderSelectionPanel);
|
||||
|
||||
Root.Children.Remove(ShaderSelectionPanel);
|
||||
}
|
||||
|
||||
@@ -33,4 +48,16 @@ public sealed partial class MainView : UserControl
|
||||
{
|
||||
ShadersListContainerPanel.Height = Math.Round(e.NewSize.Height * 0.35);
|
||||
}
|
||||
|
||||
// Logs rendering failed in the main panel
|
||||
private void MainShaderPanel_RenderingFailed(AnimatedComputeShaderPanel sender, Exception args)
|
||||
{
|
||||
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.RenderingFailedOnMainPanel, args);
|
||||
}
|
||||
|
||||
// Logs rendering failed in a secondary panel
|
||||
private void SelectionShaderPanel_RenderingFailed(AnimatedComputeShaderPanel sender, Exception args)
|
||||
{
|
||||
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.RenderingFailedOnSelectionPanel, args);
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,10 @@
|
||||
xmlns:media="using:CommunityToolkit.WinUI.UI.Media"
|
||||
xmlns:models="using:ComputeSharp.SwapChain.Core.Models"
|
||||
xmlns:ui="using:CommunityToolkit.WinUI.UI"
|
||||
xmlns:viewmodels="using:ComputeSharp.SwapChain.Core.ViewModels"
|
||||
SizeChanged="UserControl_SizeChanged"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid x:Name="Root">
|
||||
<Grid.DataContext>
|
||||
<viewmodels:MainViewModel x:Name="ViewModel" />
|
||||
</Grid.DataContext>
|
||||
<Grid.Resources>
|
||||
|
||||
<!--
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ComputeSharp.SwapChain.Core.Services;
|
||||
using ComputeSharp.SwapChain.Core.ViewModels;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
|
||||
@@ -15,8 +17,15 @@ public sealed partial class MainWindow : Window
|
||||
this.ExtendsContentIntoTitleBar = true;
|
||||
|
||||
SetTitleBar(TitleBarRectangle);
|
||||
|
||||
Root.DataContext = new MainViewModel(new DebugAnalyticsService());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="MainViewModel"/> instance for the current view.
|
||||
/// </summary>
|
||||
public MainViewModel ViewModel => (MainViewModel)Root.DataContext;
|
||||
|
||||
// Opens the shader selection panel
|
||||
private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする