Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added experimentation system #446

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AmbientSounds.Tasks/AmbientSounds.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="JeniusApps.Common.Uwp">
<Version>0.0.38-preview</Version>
<Version>0.0.40-preview</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.14</Version>
Expand Down
3 changes: 1 addition & 2 deletions src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@
<Compile Include="Services\StoreService.cs" />
<Compile Include="Services\DialogService.cs" />
<Compile Include="Services\FileWriter.cs" />
<Compile Include="Services\LocalSettings.cs" />
<Compile Include="Services\Navigator.cs" />
<Compile Include="Services\PartnerCentreNotificationRegistrar.cs" />
<Compile Include="Services\ScreensaverService.cs" />
Expand Down Expand Up @@ -773,7 +772,7 @@
<Version>0.0.1</Version>
</PackageReference>
<PackageReference Include="JeniusApps.Common.Uwp">
<Version>0.0.38-preview</Version>
<Version>0.0.40-preview</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>7.0.0</Version>
Expand Down
12 changes: 10 additions & 2 deletions src/AmbientSounds.Uwp/App.Configuration.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
using Microsoft.Toolkit.Uwp.Helpers;
using Windows.Storage;
using Windows.System.Profile;
using JeniusApps.Common.Settings;
using JeniusApps.Common.Settings.Uwp;

#nullable enable

Expand Down Expand Up @@ -56,11 +58,18 @@ private static IServiceProvider ConfigureServices(IAppSettings? appsettings = nu

// Manually register additional services requiring more customization
collection.AddSingleton(appsettings ?? new AppSettings());
collection.AddSingleton<IUserSettings, LocalSettings>(s => new LocalSettings(UserSettingsConstants.Defaults));
collection.AddSingleton<IExperimentationService, LocalExperimentationService>(s => new LocalExperimentationService(ExperimentConstants.AllKeys, s.GetRequiredService<IUserSettings>()));
collection.AddSingleton<ITelemetry, AppInsightsTelemetry>(s =>
{
var apiKey = s.GetRequiredService<IAppSettings>().TelemetryApiKey;
var isEnabled = s.GetRequiredService<IUserSettings>().Get<bool>(UserSettingsConstants.TelemetryOn);
return new AppInsightsTelemetry(apiKey, isEnabled: isEnabled, context: GetContext());
var context = GetContext();
foreach (var experiment in s.GetRequiredService<IExperimentationService>().GetAllExperiments())
{
context?.GlobalProperties.Add(experiment.Key, experiment.Value.ToString());
}
return new AppInsightsTelemetry(apiKey, isEnabled: isEnabled, context: context);
});

IServiceProvider provider = collection.BuildServiceProvider();
Expand Down Expand Up @@ -177,7 +186,6 @@ private static IServiceProvider ConfigureServices(IAppSettings? appsettings = nu
[Singleton(typeof(SoundService), typeof(ISoundService))]
[Singleton(typeof(GuideService), typeof(IGuideService))]
[Singleton(typeof(FocusHistoryRepository), typeof(IFocusHistoryRepository))]
[Singleton(typeof(LocalSettings), typeof(IUserSettings))]
[Singleton(typeof(SoundMixService), typeof(ISoundMixService))]
[Singleton(typeof(Renamer), typeof(IRenamer))]
[Singleton(typeof(UpdateService), typeof(IUpdateService))]
Expand Down
1 change: 1 addition & 0 deletions src/AmbientSounds.Uwp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using AmbientSounds.Services;
using AmbientSounds.Services.Uwp;
using AmbientSounds.ViewModels;
using JeniusApps.Common.Settings;
using JeniusApps.Common.Telemetry;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Toolkit.Uwp.Connectivity;
Expand Down
4 changes: 2 additions & 2 deletions src/AmbientSounds.Uwp/Controls/ActiveTrackItem.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using AmbientSounds.Constants;
using AmbientSounds.Services;
using JeniusApps.Common.Settings;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Toolkit.Uwp.UI.Helpers;
using System;
Expand Down Expand Up @@ -88,7 +88,7 @@ private string GetCurrentTheme()
}
else
{
return userThemeSetting;
return userThemeSetting ?? string.Empty;
}
}

Expand Down
76 changes: 37 additions & 39 deletions src/AmbientSounds.Uwp/Controls/InterruptionDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
using System;
using AmbientSounds.Constants;
using JeniusApps.Common.Settings;
using Microsoft.Extensions.DependencyInjection;
using Windows.UI.Xaml.Controls;
using WinUI = Microsoft.UI.Xaml.Controls;
using Microsoft.Extensions.DependencyInjection;
using AmbientSounds.Constants;
using AmbientSounds.Services;

namespace AmbientSounds.Controls
namespace AmbientSounds.Controls;

public sealed partial class InterruptionDialog : ContentDialog
{
public sealed partial class InterruptionDialog : ContentDialog
public InterruptionDialog()
{
this.InitializeComponent();
this.Opened += OnDialogOpened;
}

public double MinutesLogged { get; private set; }

public string InterruptionNotes { get; private set; }

private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
MinutesLogged = MinutesBox.Value;
InterruptionNotes = NotesBox.Text;
}

private void NumberBox_ValueChanged(WinUI.NumberBox sender, WinUI.NumberBoxValueChangedEventArgs args)
{
IsPrimaryButtonEnabled = args.NewValue > 0d;
}

private void OnDialogOpened(ContentDialog sender, ContentDialogOpenedEventArgs args)
{
var settings = App.Services.GetRequiredService<IUserSettings>();
HelpMessageBar.IsOpen = !settings.Get<bool>(UserSettingsConstants.HasClosedInterruptionMessageKey);
}

private void HelpMessageBar_CloseButtonClick(WinUI.InfoBar sender, object args)
{
public InterruptionDialog()
{
this.InitializeComponent();
this.Opened += OnDialogOpened;
}

public double MinutesLogged { get; private set; }

public string InterruptionNotes { get; private set; }

private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
MinutesLogged = MinutesBox.Value;
InterruptionNotes = NotesBox.Text;
}

private void NumberBox_ValueChanged(WinUI.NumberBox sender, WinUI.NumberBoxValueChangedEventArgs args)
{
IsPrimaryButtonEnabled = args.NewValue > 0d;
}

private void OnDialogOpened(ContentDialog sender, ContentDialogOpenedEventArgs args)
{
var settings = App.Services.GetRequiredService<IUserSettings>();
HelpMessageBar.IsOpen = !settings.Get<bool>(UserSettingsConstants.HasClosedInterruptionMessageKey);
}

private void HelpMessageBar_CloseButtonClick(WinUI.InfoBar sender, object args)
{
var settings = App.Services.GetRequiredService<IUserSettings>();
settings.Set(UserSettingsConstants.HasClosedInterruptionMessageKey, true);
HelpMessageBar.IsOpen = false;
}
var settings = App.Services.GetRequiredService<IUserSettings>();
settings.Set(UserSettingsConstants.HasClosedInterruptionMessageKey, true);
HelpMessageBar.IsOpen = false;
}
}
1 change: 1 addition & 0 deletions src/AmbientSounds.Uwp/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using AmbientSounds.Converters;
using AmbientSounds.ViewModels;
using CommunityToolkit.Diagnostics;
using JeniusApps.Common.Settings;
using JeniusApps.Common.Tools;
using System;
using System.Collections.Generic;
Expand Down
62 changes: 0 additions & 62 deletions src/AmbientSounds.Uwp/Services/LocalSettings.cs

This file was deleted.

5 changes: 2 additions & 3 deletions src/AmbientSounds.Uwp/Views/CataloguePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using AmbientSounds.Constants;
using AmbientSounds.Services;
using AmbientSounds.ViewModels;
using JeniusApps.Common.Settings;
using JeniusApps.Common.Telemetry;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Threading;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using JeniusApps.Common.Telemetry;

#nullable enable

Expand Down
6 changes: 3 additions & 3 deletions src/AmbientSounds.Uwp/Views/CompactPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using AmbientSounds.Constants;
using AmbientSounds.Controls;
using AmbientSounds.Services;
using AmbientSounds.ViewModels;
using JeniusApps.Common.Settings;
using JeniusApps.Common.Telemetry;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using Windows.ApplicationModel.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using JeniusApps.Common.Telemetry;

#nullable enable

Expand Down Expand Up @@ -36,7 +36,7 @@ public CompactPage()

public CompactPageViewModel ViewModel => (CompactPageViewModel)this.DataContext;

private string BackgroundImagePath => _userSettings.Get<string>(UserSettingsConstants.BackgroundImage);
private string BackgroundImagePath => _userSettings.Get<string>(UserSettingsConstants.BackgroundImage) ?? "http://localhost";

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
Expand Down
1 change: 1 addition & 0 deletions src/AmbientSounds.Uwp/Views/HomePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AmbientSounds.Constants;
using AmbientSounds.Services;
using JeniusApps.Common.Settings;
using JeniusApps.Common.Telemetry;
using Microsoft.Extensions.DependencyInjection;
using Windows.UI.Xaml;
Expand Down
3 changes: 2 additions & 1 deletion src/AmbientSounds.Uwp/Views/ScreensaverPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AmbientSounds.Constants;
using AmbientSounds.Services;
using AmbientSounds.ViewModels;
using JeniusApps.Common.Settings;
using JeniusApps.Common.Telemetry;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
Expand All @@ -14,7 +16,6 @@
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using JeniusApps.Common.Telemetry;

#nullable enable

Expand Down
2 changes: 1 addition & 1 deletion src/AmbientSounds.Uwp/Views/ShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using AmbientSounds.Models;
using AmbientSounds.Services;
using AmbientSounds.ViewModels;
using JeniusApps.Common.Settings;
using JeniusApps.Common.Telemetry;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.Services.Store;
using Windows.UI.ViewManagement;
Expand Down
2 changes: 1 addition & 1 deletion src/AmbientSounds/AmbientSounds.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<PackageReference Include="Humanizer.Core.uk" Version="2.14.1" />
<PackageReference Include="Humanizer.Core.zh-cn" Version="2.14.1" />
<PackageReference Include="Humanizer.Core.zh-hant" Version="2.14.1" />
<PackageReference Include="JeniusApps.Common" Version="0.0.38-preview" />
<PackageReference Include="JeniusApps.Common" Version="0.0.40-preview" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.17" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="MimeTypeMapOfficial" Version="1.0.17" />
Expand Down
24 changes: 24 additions & 0 deletions src/AmbientSounds/Constants/ExperimentConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;

#nullable enable

namespace AmbientSounds.Constants;

/// <summary>
/// Class dedicated to holding constants related to experimentation.
/// </summary>
public class ExperimentConstants
{
/// <summary>
/// Convenient list of all experimentation key strings.
/// </summary>
public static readonly IReadOnlyList<string> AllKeys =
[
CataloguePreviews
];

/// <summary>
/// Key name to track the catalogue previews feature.
/// </summary>
public const string CataloguePreviews = "cataloguePreviews";
}
13 changes: 7 additions & 6 deletions src/AmbientSounds/Factories/SoundVmFactory.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using AmbientSounds.Models;
using AmbientSounds.Repositories;
using AmbientSounds.Services;
using AmbientSounds.Tools;
using AmbientSounds.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using CommunityToolkit.Diagnostics;
using CommunityToolkit.Mvvm.Input;
using System;
using JeniusApps.Common.Settings;
using JeniusApps.Common.Telemetry;
using JeniusApps.Common.Tools;
using AmbientSounds.Repositories;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Concurrent;
using JeniusApps.Common.Telemetry;

namespace AmbientSounds.Factories;

Expand Down Expand Up @@ -48,7 +48,8 @@ public OnlineSoundViewModel GetOnlineSoundVm(Sound s)
_serviceProvider.GetRequiredService<IAssetLocalizer>(),
_serviceProvider.GetRequiredService<IMixMediaPlayerService>(),
_serviceProvider.GetRequiredService<IUpdateService>(),
_serviceProvider.GetRequiredService<ILocalizer>());
_serviceProvider.GetRequiredService<ILocalizer>(),
_serviceProvider.GetRequiredService<IExperimentationService>());

_onlineSoundVmCache.TryAdd(s.Id, newVm);
return newVm;
Expand Down
Loading