Skip to content

Commit

Permalink
Moving telemetry to core
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaulino committed Jul 29, 2021
1 parent abd3bd8 commit 988bb76
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@
<Compile Include="Converters\ThemeConverter.cs" />
<Compile Include="Converters\VisibilityConverter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\AppCentreTelemetry.cs" />
<Compile Include="Services\AppServiceController.cs" />
<Compile Include="Services\AppSettings.cs" />
<Compile Include="Services\BackgroundDownloadService.cs" />
Expand Down Expand Up @@ -488,10 +487,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AppCenter.Analytics">
<Version>4.2.0</Version>
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AppCenter.Crashes">
<Version>4.2.0</Version>
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>5.0.1</Version>
Expand Down
8 changes: 7 additions & 1 deletion src/AmbientSounds.Uwp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using AmbientSounds.Services;
using AmbientSounds.Services.Uwp;
using AmbientSounds.ViewModels;
using Microsoft.AppCenter;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Identity.Client.Extensibility;
using Microsoft.Toolkit.Diagnostics;
Expand All @@ -15,6 +16,7 @@
using Windows.ApplicationModel.Background;
using Windows.ApplicationModel.Core;
using Windows.Foundation.Collections;
using Windows.Globalization;
using Windows.Storage;
using Windows.System.Profile;
using Windows.UI;
Expand Down Expand Up @@ -332,14 +334,18 @@ private static IServiceProvider ConfigureServices(IAppSettings? appsettings = nu
.AddSingleton<IIapService, StoreService>()
.AddSingleton<IDownloadManager, WindowsDownloadManager>()
.AddSingleton<IScreensaverService, ScreensaverService>()
.AddSingleton<ITelemetry, AppCentreTelemetry>()
.AddSingleton<ITelemetry, AppCenterTelemetry>()
.AddSingleton<IOnlineSoundDataProvider, OnlineSoundDataProvider>()
.AddSingleton<ISystemInfoProvider, SystemInfoProvider>()
.AddSingleton<IMixMediaPlayerService, MixMediaPlayerService>()
.AddSingleton<ISoundDataProvider, SoundDataProvider>()
.AddSingleton(appsettings ?? new AppSettings())
.BuildServiceProvider(true);

// preload telemetry to ensure country code is set.
provider.GetService<ITelemetry>();
AppCenter.SetCountryCode(new GeographicRegion().CodeTwoLetter);

// preload appservice controller to ensure its
// dispatcher queue loads properly on the ui thread.
provider.GetService<AppServiceController>();
Expand Down
2 changes: 2 additions & 0 deletions src/AmbientSounds/AmbientSounds.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<ItemGroup>
<PackageReference Include="ByteSize" Version="2.0.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.3.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.3.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.Toolkit" Version="7.0.1" />
<PackageReference Include="Microsoft.Toolkit.Diagnostics" Version="7.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@
using Microsoft.Toolkit.Diagnostics;
using System;
using System.Collections.Generic;
using Windows.Globalization;

#nullable enable

namespace AmbientSounds.Services.Uwp
namespace AmbientSounds.Services
{
/// <summary>
/// Telemetry service for app centre.
/// </summary>
public class AppCentreTelemetry : ITelemetry
public class AppCenterTelemetry : ITelemetry
{
private readonly IUserSettings _userSettings;

public AppCentreTelemetry(
public AppCenterTelemetry(
IUserSettings userSettings,
IAppSettings appSettings)
IAppSettings appSettings,
ISystemInfoProvider systemInfoProvider)
{
Guard.IsNotNull(userSettings, nameof(userSettings));
_userSettings = userSettings;
AppCenter.SetCountryCode(new GeographicRegion().CodeTwoLetter);

AppCenter.Start(appSettings.TelemetryApiKey, typeof(Analytics), typeof(Crashes));
}

Expand Down

0 comments on commit 988bb76

Please sign in to comment.