Skip to content

Commit

Permalink
➕ TracepointHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Nov 22, 2024
1 parent e505e91 commit ebbb2d9
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ref/DirectoryPackages
2 changes: 2 additions & 0 deletions src/BD.WTTS.Client/BD.WTTS.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
<PackageReference Include="SkiaSharp.HarfBuzz" />
<PackageReference Include="HarfBuzzSharp" />
<PackageReference Include="Utf8StringInterpolation" />
<PackageReference Include="BD.Any.AppCenter" />
<PackageReference Include="BD.Any.AppCenter.Analytics" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'windows'">
Expand Down
30 changes: 30 additions & 0 deletions src/BD.WTTS.Client/Helpers/TracepointHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if USE_MS_APPCENTER_ANALYTICS
using Microsoft.AppCenter.Analytics;
#else
using BD.AppCenter.Analytics;
#endif

namespace BD.WTTS.Helpers;

/// <summary>
/// 描点助手类
/// </summary>
static partial class TracepointHelper
{
/// <summary>
/// 跟踪带有名称和可选属性的自定义事件
/// 名称参数不能为空或空值。最大允许长度 = 256
/// 属性参数最大项数 = 20
/// 属性键/名称不能为空,最大允许键长度 = 125
/// 属性值不能为空,允许的最大值长度 = 125
/// https://learn.microsoft.com/zh-cn/appcenter/sdk/analytics/windows#custom-events
/// 可以使用 最多 20 个属性 跟踪自己的自定义事件,以了解用户与应用之间的交互
/// 启动 SDK 后,使用 TrackEvent() 方法通过属性跟踪事件。 最多可以发送 200 个不同的事件名称。 此外,每个事件名称的最大限制为 256 个字符,每个事件属性名称和事件属性值的最大限制为 125 个字符。
/// </summary>
/// <param name="name">事件名称(可定义枚举值,最多不超过 200 个名称)</param>
/// <param name="properties">可选属性</param>
public static void TrackEvent(string name, IDictionary<string, string>? properties = null)
{
Analytics.TrackEvent(name, properties!);
}
}
31 changes: 30 additions & 1 deletion src/VisualStudioAppCenterSDK.cs
Original file line number Diff line number Diff line change
@@ -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

/// <summary>
/// Visual Studio App Center
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

0 comments on commit ebbb2d9

Please sign in to comment.