From 3de65fb027bc8368d4988b97d2a9cc56c56b07fe Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 22 Jan 2019 12:37:53 -0600 Subject: [PATCH] Create a new OrderbookVM each time; fixes crash when launching mini-ob from same badge multiple times --- .../spark/view/Spark/Ladder/LadderOrderVM.cs | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/client/spark/view/Spark/Ladder/LadderOrderVM.cs b/src/client/spark/view/Spark/Ladder/LadderOrderVM.cs index 47c78289d..748611472 100644 --- a/src/client/spark/view/Spark/Ladder/LadderOrderVM.cs +++ b/src/client/spark/view/Spark/Ladder/LadderOrderVM.cs @@ -38,7 +38,6 @@ namespace mbts.spark { readonly Property _is_exchange_order, _has_multiple_orders_at_same_level, _is_hedge_order; readonly Property _parent_algo_type; readonly Property _summary, _description; - readonly Property _orderbook_vm; IObservable _bs; LadderSettings.BadgeStyle _current_badge_style; int _n_active_price_change_ops = 0; @@ -77,23 +76,6 @@ namespace mbts.spark { // add_order(o); - var price_filter = new filters.DoubleMinMaxState(); - price_filter.minimum.value = real_price; - price_filter.maximum.value = real_price; - - var obvm = new OrderBookVM(null, parent.bus, null, parent.model.order_gateway, null); - var state = new bts.shell.OrderBookWindowFactory.OrderBookStartupData( - new bts.shell.OrderBookWindowFactory.FilterStates { - security_criteria = new SecurityCriteria(_parent.security), - price = price_filter, - statuses = new[] { OrderStatus.Working } - }, - bts.shell.OrderBookWindowFactory.OrderBookStartupData.default_mini_grid, - use_defaults: false - ); - obvm.load_from(state); - _orderbook_vm = backing(nameof(orderbook_vm), obvm); - _dispose = Disposable.Create( _bs.Subscribe(badge => { _current_badge_style = badge; @@ -209,7 +191,32 @@ namespace mbts.spark { public bool has_multiple_orders_at_same_level { get => _has_multiple_orders_at_same_level.Value; private set => _has_multiple_orders_at_same_level.Value = value; } public bool is_hedge_order { get => _is_hedge_order.Value; private set => _is_hedge_order.Value = value; } public Brush parent_algo_type_brush { get => _parent_algo_type_brush.Value; private set => _parent_algo_type_brush.Value = value; } - public OrderBookVM orderbook_vm { get => _orderbook_vm.Value; private set => _orderbook_vm.Value = value; } + public OrderBookVM orderbook_vm { + // We are returning a new OrderBookVM each time b/c after + // successive launches of the mini-ob from the same badge, we get an exception + // System.InvalidOperationException: Sharing GridViewColumn among multiple GridViewColumnCollections or adding the same GridViewColumn into one GridViewColumnCollection more than once is not allowed. + // I checked with Eric and he guesses that what is happening is that the Popup is throwing away the grid, but the binding doesn't remove the columns from that grid + // + // I think returning a new OrderbookVM is okay at the moment since this Popup window will not be saving any state at this time + get { + var price_filter = new filters.DoubleMinMaxState(); + price_filter.minimum.value = real_price; + price_filter.maximum.value = real_price; + + var obvm = new OrderBookVM(null, _parent.bus, null, _parent.model.order_gateway, null); + var state = new bts.shell.OrderBookWindowFactory.OrderBookStartupData( + new bts.shell.OrderBookWindowFactory.FilterStates { + security_criteria = new SecurityCriteria(_parent.security), + price = price_filter, + statuses = new[] { OrderStatus.Working } + }, + bts.shell.OrderBookWindowFactory.OrderBookStartupData.default_mini_grid, + use_defaults: false + ); + obvm.load_from(state); + return obvm; + } + } // the setter is public so that the LadderVM can set this field public CustomOrderDefinition.CustomOneofCase parent_algo_type { get => _parent_algo_type.Value; set => _parent_algo_type.Value = value; }