using System.Collections.Generic; using System.Linq; using System.Threading; using ComputeSharp.SwapChain.Core.Services; using Microsoft.AppCenter; using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; #nullable enable namespace ComputeSharp.SwapChain.Uwp.Services; /// /// An implementation using AppCenter. /// public sealed class AppCenterService : IAnalyticsService { /// /// The maximum length for any property name and value /// /// It's 125, but one character is reserved for the leading '|' to indicate trimming. private const int PropertyStringMaxLength = 124; /// public AppCenterService(string secret) { AppCenter.Start(secret, typeof(Crashes), typeof(Analytics)); } /// public void Log(string title, params (string Property, string Value)[]? data) { IDictionary? properties = data?.ToDictionary( pair => pair.Property, pair => pair.Value.Length <= PropertyStringMaxLength ? pair.Value : $"|{pair.Value.Substring(pair.Value.Length - PropertyStringMaxLength)}"); Analytics.TrackEvent(title, properties); } }