Merged in backwards-compatibility (pull request #234)

Backwards compatibility

Approved-by: Jake Norbut <jake.norbut@bluetradesys.com>
This commit is contained in:
John Colvin authored and Pedro Pinto committed 2019-05-22 14:57:09 +00:00
commit 4ed4e2e5e4
4 files changed
+69 -5

No files matched your search

@@ -20,6 +20,27 @@ namespace bts.shell {
readonly IBus _bus;
readonly OrdersModel _orders_model;
readonly UserSettingsHub _settings_hub;
/// Fills 'sorting-criterion' settings were compromised a while back (mid-late 2018).
/// The issue was that, when a column was sorted, its 'sort member path' was assigned to the SortingCriteria.col_name,
/// rather than the <see cref="Columns"/> enum/id string.
/// This dictionary serves as a reverse-lookup so the sort member path can be converted to the enum/id string.
static readonly IReadOnlyDictionary<string, Columns> _sort_member_to_id =
new Dictionary<string, Columns> {
{ nameof(FillsVM.Row.account), Columns.Account },
{ nameof(FillsVM.Row.exchange), Columns.Exchange },
{ nameof(FillsVM.Row.fill_key), Columns.FillKey },
{ nameof(FillsVM.Row.fill_kind), Columns.FillKind },
{ nameof(FillsVM.Row.fill_time), Columns.FillTime },
{ nameof(FillsVM.Row.order_key), Columns.OrderKey },
{ nameof(FillsVM.Row.order_type), Columns.OrderType },
{ nameof(FillsVM.Row.price), Columns.Price },
{ nameof(FillsVM.Row.security), Columns.Security },
{ nameof(FillsVM.Row.security_key), Columns.SecurityKey },
{ nameof(FillsVM.Row.side), Columns.Side },
{ nameof(FillsVM.Row.size), Columns.Size },
{ nameof(FillsVM.Row.time_in_force), Columns.TimeInForce },
{ nameof(FillsVM.Row.user), Columns.User }
};
public FillsWindowFactory(TradingShellModule module, IBus bus, UserSettingsHub settings_hub, OrdersModel orders_model)
: base(module, "Fills") {
@@ -38,6 +59,7 @@ namespace bts.shell {
_bus.post(SparkTags.ShowWindow, await load(state));
IShellWindow _create(StartupData state) {
GridSettingsHelper.normalize_sorting_criterion(state.sorting_criterion, _sort_member_to_id);
var settings_manager = new WindowSettingsManager<GridSettings>(_settings_hub,
state.grid,
get: us => us.fills_grid,
@@ -99,8 +99,11 @@ namespace bts.shell.orderbook {
public OrderBookGridSettings grid_settings_wrapper() {
if (use_defaults)
return null;
if (orderbook_grid == null)
orderbook_grid = new OrderBookGridSettings(grid.clone(), _predicate_animations);
if (orderbook_grid == null) {
if (grid == null)
grid = _default_general_grid;
orderbook_grid = new OrderBookGridSettings(grid.clone(), _predicate_animations);
}
return orderbook_grid;
}
#pragma warning restore CS0612 // Type or member is obsolete
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace mbts.ui.settings {
static class GridSettingsHelper {
public static TColKey? parse_col_id<TColKey>(string id) where TColKey : struct =>
Enum.TryParse(id, true, out TColKey key) ? key : (TColKey?)null;
public static string fmt_col_id<TColKey>(TColKey key) where TColKey : struct =>
key.ToString();
public static void normalize_sorting_criterion<TColKey>(IEnumerable<SortingCriteria> sorting_criterion, IReadOnlyDictionary<string, TColKey> sort_member_to_id) where TColKey : struct =>
normalize_sorting_criterion(sorting_criterion, new Func<string, TColKey?>[] {
parse_col_id<TColKey>,
col_name => sort_member_to_id.TryGetValue(col_name, out var k) ? k : (TColKey?)null
});
public static void normalize_sorting_criterion<TColKey>(IEnumerable<SortingCriteria> sorting_criterion, IEnumerable<Func<string, TColKey?>> conversion_dels) where TColKey : struct {
foreach (var sc in sorting_criterion) {
sc.col_name = conversion_dels
.Select(del => del(sc.col_name))
.FirstOrDefault(k => k.HasValue)?.ToString() ?? sc.col_name;
}
}
}
}
@@ -1,5 +1,8 @@
using bts.utils;
using bts;
using bts.collections;
using bts.utils;
using mbts.collections;
using mbts.ui.settings;
using mbts.ui.utility;
using mbts.utils;
using System;
@@ -51,8 +54,17 @@ namespace mbts.ui.controls {
).to_comparer();
}
public void load_from(IEnumerable<SortingCriteria> sorting_criterion) =>
_on_settings(sorting_criterion.Select(sc => (EnumHelper.parse<TColKey>(sc.col_name), sc.is_ascending ? ListSortDirection.Ascending : ListSortDirection.Descending)));
public void load_from(IEnumerable<SortingCriteria> sorting_criterion) {
var sort_member_to_id = _map
.Where(kv => !string.IsNullOrEmpty(kv.Value.col.sort_member_path))
.Distinct()
.ToDictionary(kv => kv.Value.col.sort_member_path, kv => kv.Key);
GridSettingsHelper.normalize_sorting_criterion(sorting_criterion, sort_member_to_id);
_on_settings(sorting_criterion
.Select(sc => (GridSettingsHelper.parse_col_id<TColKey>(sc.col_name), sc.is_ascending ? ListSortDirection.Ascending : ListSortDirection.Descending))
.Where(t => t.Item1.HasValue)
.Select(t => (t.Item1.Value, t.Item2)));
}
public IEnumerable<SortingCriteria> create() =>
_active_cols.AsCollection().Select(t => new SortingCriteria(t.col.id, t.direction == ListSortDirection.Ascending));