From ebbb2d90ba6c55e351596364db23e2a42e13bd04 Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Fri, 22 Nov 2024 15:21:47 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20TracepointHelper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ref/DirectoryPackages | 2 +- src/BD.WTTS.Client/BD.WTTS.Client.csproj | 2 ++ .../Helpers/TracepointHelper.cs | 30 ++++++++++++++++++ src/VisualStudioAppCenterSDK.cs | 31 ++++++++++++++++++- 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/BD.WTTS.Client/Helpers/TracepointHelper.cs diff --git a/ref/DirectoryPackages b/ref/DirectoryPackages index 7a43b4afd3f..6781ffdb223 160000 --- a/ref/DirectoryPackages +++ b/ref/DirectoryPackages @@ -1 +1 @@ -Subproject commit 7a43b4afd3f0cf642c5fc58c8e5a5e445e73c2ce +Subproject commit 6781ffdb2236125aa66bfd45701620e2e53b5fba diff --git a/src/BD.WTTS.Client/BD.WTTS.Client.csproj b/src/BD.WTTS.Client/BD.WTTS.Client.csproj index aafb0a9ac8f..69e3f1ff6fe 100644 --- a/src/BD.WTTS.Client/BD.WTTS.Client.csproj +++ b/src/BD.WTTS.Client/BD.WTTS.Client.csproj @@ -123,6 +123,8 @@ + + diff --git a/src/BD.WTTS.Client/Helpers/TracepointHelper.cs b/src/BD.WTTS.Client/Helpers/TracepointHelper.cs new file mode 100644 index 00000000000..365c5edd4f3 --- /dev/null +++ b/src/BD.WTTS.Client/Helpers/TracepointHelper.cs @@ -0,0 +1,30 @@ +#if USE_MS_APPCENTER_ANALYTICS +using Microsoft.AppCenter.Analytics; +#else +using BD.AppCenter.Analytics; +#endif + +namespace BD.WTTS.Helpers; + +/// +/// 描点助手类 +/// +static partial class TracepointHelper +{ + /// + /// 跟踪带有名称和可选属性的自定义事件 + /// 名称参数不能为空或空值。最大允许长度 = 256 + /// 属性参数最大项数 = 20 + /// 属性键/名称不能为空,最大允许键长度 = 125 + /// 属性值不能为空,允许的最大值长度 = 125 + /// https://learn.microsoft.com/zh-cn/appcenter/sdk/analytics/windows#custom-events + /// 可以使用 最多 20 个属性 跟踪自己的自定义事件,以了解用户与应用之间的交互 + /// 启动 SDK 后,使用 TrackEvent() 方法通过属性跟踪事件。 最多可以发送 200 个不同的事件名称。 此外,每个事件名称的最大限制为 256 个字符,每个事件属性名称和事件属性值的最大限制为 125 个字符。 + /// + /// 事件名称(可定义枚举值,最多不超过 200 个名称) + /// 可选属性 + public static void TrackEvent(string name, IDictionary? properties = null) + { + Analytics.TrackEvent(name, properties!); + } +} diff --git a/src/VisualStudioAppCenterSDK.cs b/src/VisualStudioAppCenterSDK.cs index fa626a45c76..9eb107aefee 100644 --- a/src/VisualStudioAppCenterSDK.cs +++ b/src/VisualStudioAppCenterSDK.cs @@ -1,6 +1,9 @@ using Microsoft.AppCenter; using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; +#if !APP_REVERSE_PROXY && (WINDOWS || LINUX || MACCATALYST || MACOS) +using BD_AppCenter = BD.AppCenter.AppCenter; +#endif /// /// Visual Studio App Center @@ -34,10 +37,20 @@ internal static void Init() #pragma warning restore CS0612 // 类型或成员已过时 #endif AppCenter.Start(appSecret, typeof(Analytics), typeof(Crashes)); + +#if !USE_MS_APPCENTER_ANALYTICS && !APP_REVERSE_PROXY && (WINDOWS || LINUX || MACCATALYST || MACOS) + BD_AppCenter.SetDeviceInformationHelper(utils); + BD_AppCenter.SetPlatformHelper(utils); +#pragma warning disable CS0612 // 类型或成员已过时 + BD_AppCenter.SetApplicationSettingsFactory(utils); +#pragma warning restore CS0612 // 类型或成员已过时 + + BD_AppCenter.Start(appSecret, typeof(Analytics)); +#endif } #if WINDOWS || LINUX || MACCATALYST || MACOS || APP_REVERSE_PROXY - internal sealed class UtilsImpl : + internal sealed partial class UtilsImpl : Microsoft.AppCenter.Utils.IAbstractDeviceInformationHelper, Microsoft.AppCenter.Utils.IPlatformHelper, Microsoft.AppCenter.Utils.IApplicationSettingsFactory, @@ -217,5 +230,21 @@ public void SetValue(string key, object value) #endregion } + +#if !APP_REVERSE_PROXY + partial class UtilsImpl : + BD.AppCenter.Utils.IAbstractDeviceInformationHelper, + BD.AppCenter.Utils.IPlatformHelper, + BD.AppCenter.Utils.IApplicationSettingsFactory, + BD.AppCenter.Utils.IApplicationSettings + { + + #region IApplicationSettingsFactory + + BD.AppCenter.Utils.IApplicationSettings BD.AppCenter.Utils.IApplicationSettingsFactory.CreateApplicationSettings() => this; + + #endregion + } +#endif #endif } \ No newline at end of file