From adcb5502b05eca0f5f8b43cbcbc6f68d4976bb56 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 11 Sep 2019 13:04:52 -0500 Subject: [PATCH] UserSettingsHub fills migration rules impl --- .../UserSettings/ISettingsMigrationRule.cs | 3 ++- .../ShellInterface/UserSettings/UserSettingsHub.cs | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/client/spark/core/ShellInterface/UserSettings/ISettingsMigrationRule.cs b/src/client/spark/core/ShellInterface/UserSettings/ISettingsMigrationRule.cs index c64f8fde3..5429752d0 100644 --- a/src/client/spark/core/ShellInterface/UserSettings/ISettingsMigrationRule.cs +++ b/src/client/spark/core/ShellInterface/UserSettings/ISettingsMigrationRule.cs @@ -12,8 +12,9 @@ namespace bts.settings { // should be exposed through explicitly named interfaces that inherit ISettingsMigrationRule. // This avoids magic const names in the MEF import/export contracts, which would otherwise be needed to // determine the various windows to which such rules apply. - interface IPAndLGridSettingsMigrationRule : ISettingsMigrationRule { } + interface IFillsGridSettingsMigrationRule : ISettingsMigrationRule { } interface IMarketViewGridSettingsMigrationRule : ISettingsMigrationRule { } + interface IPAndLGridSettingsMigrationRule : ISettingsMigrationRule { } static class SettingsMigrationHelper { public static bool apply(T settings, IEnumerable> migration_rules, out T new_settings) { diff --git a/src/client/spark/core/ShellInterface/UserSettings/UserSettingsHub.cs b/src/client/spark/core/ShellInterface/UserSettings/UserSettingsHub.cs index ce9eadf6e..e374ff0ed 100644 --- a/src/client/spark/core/ShellInterface/UserSettings/UserSettingsHub.cs +++ b/src/client/spark/core/ShellInterface/UserSettings/UserSettingsHub.cs @@ -22,11 +22,13 @@ namespace mbts.persist { const string NAME_SPACE = "settings", DEFAULT_KEY = "default"; static readonly IImmutableProperty + _fills_propi = ImmutableProperty.create(us => us.fills_grid, (us, gs) => us.with(provided_fills_gridsettings: gs)), _mview_propi = ImmutableProperty.create(us => us.market_view_grid, (us, gs) => us.with(provided_market_view_gridsettings: gs)), _pandl_propi = ImmutableProperty.create(us => us.pnl_grid, (us, gs) => us.with(provided_pnl_gridsettings: gs)); readonly object _default_settings_lock = new object(); readonly BehaviorSubject _default_settings_subject = new BehaviorSubject(UserSettings.factory_defaults); + readonly IEnumerable _fills_migration_rules; readonly IEnumerable _mview_migration_rules; readonly IEnumerable _pandl_migration_rules; readonly IUserPersist _persist; @@ -36,10 +38,12 @@ namespace mbts.persist { [ImportingConstructor] public UserSettingsHub( IUserPersist persist, + [ImportMany]IEnumerable fills_migration_rules, [ImportMany]IEnumerable mview_migration_rules, [ImportMany]IEnumerable pandl_migration_rules) { // _persist = persist; + _fills_migration_rules = fills_migration_rules ?? Enumerable.Empty(); _mview_migration_rules = mview_migration_rules ?? Enumerable.Empty(); _pandl_migration_rules = pandl_migration_rules ?? Enumerable.Empty(); init(); @@ -49,6 +53,7 @@ namespace mbts.persist { s = await _persist.get(NAME_SPACE, DEFAULT_KEY); if (s != null) { var wrapped_rules = new[] { + _fills_migration_rules.merge().wrap(_fills_propi), _mview_migration_rules.merge().wrap(_mview_propi), _pandl_migration_rules.merge().wrap(_pandl_propi) }; @@ -100,6 +105,12 @@ namespace mbts.persist { /// Assuming there aren't any rogue agents saving UserSettings by themselves, there should never be any discrepancies. public IObservable subscribe_default_settings() => _default_settings_subject.AsObservable(); + public IWindowSettingsManager create_fills_settings_manager(GridSettings instance_settings) => + _create_settings_manager( + instance_settings, + _fills_migration_rules, + _fills_propi); + public IWindowSettingsManager create_mview_settings_manager(GridSettings instance_settings) => _create_settings_manager( instance_settings,