From 01acbe08f5c5e529b92d022d2a573cef9cd2f343 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 14 Oct 2019 15:20:47 -0500 Subject: [PATCH] remove dead code --- .../Trading/AlgoStudio/VM/AlgoVMWrapper.cs | 214 ------------------ .../AlgoEditorGridView/AlgoParamRowsHelper.cs | 27 +-- .../AlgoStudio/View/AlgoEditorView.xaml | 2 +- .../Order/AlgoContentTemplateSelector.xaml.cs | 3 +- 4 files changed, 3 insertions(+), 243 deletions(-) delete mode 100644 src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoVMWrapper.cs diff --git a/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoVMWrapper.cs b/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoVMWrapper.cs deleted file mode 100644 index f82bbdd02..000000000 --- a/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoVMWrapper.cs +++ /dev/null @@ -1,214 +0,0 @@ -using bts.api; -using bts.api.orderman; -using bts.collections; -using bts.spark; -using mbts.spark.utilities; -using mbts.ui; -using mbts.ui.controls; -using mbts.ui.shell; -using mbts.utils; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using System.ComponentModel; -using System.Reactive.Disposables; -using System.Reactive.Linq; -using System.Threading.Tasks; -using System.Windows.Input; - -namespace mbts.spark { - class AlgoVMWrapper : DisposableViewModelBase, IAlgoVM, - IObserver, - IObserver, - IObserver, - IObserver { - static readonly HashSet - _algo_root_echo_props = new HashSet { - nameof(is_expanded), - nameof(editing_permissions), - nameof(definition), - nameof(display_name) - }; - static readonly IReadOnlyDictionary - _value_echo_props = new Dictionary { - { nameof(AlgoDefinitionVM.name), nameof(display_name) }, - { nameof(AlgoDefinitionVM.abbreviation), nameof(abbreviation) }, - { nameof(AlgoDefinitionVM.badge_fill), nameof(meta) } - }; - readonly ObservableAggregateCollection _child_algo_selectors = new ObservableAggregateCollection(); - readonly ObservableAggregateCollection _algo_params = new ObservableAggregateCollection(); - readonly DisposableContainer _value_hooks = new DisposableContainer(); - Action _definition_changed = () => { }; - _ObservedData? _data_cache; - AlgoDefinitionVM _value; - - public AlgoVMWrapper(AlgoDefinitionVM algo_definition_vm) { - value = algo_definition_vm; - _dispose = new CompositeDisposable(_value_hooks) { - _child_algo_selectors.clear_collections, - _algo_params.clear_collections, - () => _value?.Dispose() - }; - } - - public event Action definition_changed { add => _definition_changed += value; remove => _definition_changed -= value; } - - public AlgoDefinitionVM value { - get => _value; - set { - if (_value != value) { - _value?.Dispose(); - _value = value; - _value_hooks.replace(_set_hooks(value)); - RaisePropertyChanged(nameof(value)); - } - } - } - public AlgoKey id => _value.key; - public CustomOrderDefinition.CustomOneofCase order_type => _algo_root?.order_type ?? CustomOrderDefinition.CustomOneofCase.None; - public OrderMetadata meta { - get { - if (_value != null) { - if (_value.custom_badge_color.enabled) - return new OrderMetadata { Color = value.custom_badge_color.value.rgb_color(), KeyBinding = value.abbreviation.if_null_or_empty(value.name) }; - else if (_value.algo_root != null) - return _value.algo_root.meta; - } - return OrderDataHelper.get_metadata(order_type); - } - } - public AlgoEditingPermissions editing_permissions => _value?.editing_permissions ?? AlgoEditingPermissions.None; - public bool can_expand => _algo_root?.can_expand ?? false; - public bool is_expanded { - get => _value.algo_root?.is_expanded ?? false; - set { - if (_value != null) - _value.is_expanded = value; - } - } - public string display_name => _value?.name ?? string.Empty; - public string abbreviation => _value?.abbreviation; - public AlgoDisplayGroup group => _value?.group ?? AlgoDisplayGroup.BTS; - public CustomOrderDefinitionImmutable definition => _algo_root?.definition ?? new CustomOrderDefinitionImmutable(new CustomOrderDefinition()); - public ObservableCollection child_algo_selectors => _child_algo_selectors; - [EditorBrowsable(EditorBrowsableState.Never)] - public ObservableCollection child_algo_selectors_view { - get { - _value?.algo_root?.ensure_init(); - return _child_algo_selectors; - } - } - public IReadOnlyObservableCollection algo_params => _algo_params; - [EditorBrowsable(EditorBrowsableState.Never)] - public dynamic children_vm => _algo_root?.children_vm; - - IAlgoVM _algo_root => _value?.algo_root; - - public void assign_to(CustomOrderDefinition value) => _algo_root?.assign_to(value); - public bool key_match(KeyEventArgs e) => _algo_root?.key_match(e) ?? false; - public void load_from(CustomOrderDefinitionImmutable value) => _algo_root?.load_from(value); - public void load_many(IEnumerable values) => _algo_root?.load_many(values); - void IAlgoVM.ensure_init() => _value?.algo_root?.ensure_init(); - - IDisposable _set_hooks(AlgoDefinitionVM vm) { - var algo_root_subs = new DisposableContainer(); - vm.PropertyChanged += on_value_prop_changed; - return new CompositeDisposable( - vm.observe_algo_root().Subscribe(r => { - algo_root_subs.replace(null); - _child_algo_selectors.clear_collections(); - _algo_params.clear_collections(); - if (r != null) { - if (_data_cache.HasValue) { - _data_cache.Value.forward_to(r); - } - _child_algo_selectors.add_collection(r.child_algo_selectors); - _algo_params.add_collection(r.algo_params); - ((INotifyPropertyChanged)r).PropertyChanged += on_algo_root_prop_changed; - algo_root_subs.replace(new CompositeDisposable( - r.subscribe_definition().Subscribe(_ => _definition_changed?.Invoke())) { - () => ((INotifyPropertyChanged)r).PropertyChanged -= on_algo_root_prop_changed - }); - } - RaisePropertyChanged(nameof(group)); - }), - algo_root_subs) { - () => vm.PropertyChanged -= on_value_prop_changed - }; - void on_algo_root_prop_changed(object sender, PropertyChangedEventArgs e) { - if (_algo_root_echo_props.Contains(e.PropertyName)) - RaisePropertyChanged(e.PropertyName); - } - void on_value_prop_changed(object sender, PropertyChangedEventArgs e) { - if (_value_echo_props.TryGetValue(e.PropertyName, out string wrapper_prop)) - RaisePropertyChanged(wrapper_prop); - } - } - - // permissions - void IObserver.OnNext(AlgoEditingPermissions value) { - _data_cache = _data_cache?.with(value) ?? new _ObservedData(value, default, default, default); - (_algo_root as IObserver)?.OnNext(value); - } - void IObserver.OnError(Exception error) { } - void IObserver.OnCompleted() { } - // model - void IObserver.OnNext(OrdersModel value) { - _data_cache = _data_cache?.with(value) ?? new _ObservedData(default, value, default, default); - (_algo_root as IObserver)?.OnNext(value); - } - void IObserver.OnError(Exception error) { } - void IObserver.OnCompleted() { } - // security - void IObserver.OnNext(SecurityImmutable? value) { - _data_cache = _data_cache?.with(value) ?? new _ObservedData(default, default, value, default); - (_algo_root as IObserver)?.OnNext(value); - } - void IObserver.OnError(Exception error) { } - void IObserver.OnCompleted() { } - // security md - void IObserver.OnNext(SecurityMD? value) { - _data_cache = _data_cache?.with(value) ?? new _ObservedData(default, default, default, value); - (_algo_root as IObserver)?.OnNext(value); - } - void IObserver.OnError(Exception error) { } - void IObserver.OnCompleted() { } - - struct _ObservedData { - public readonly AlgoEditingPermissions permissions; - public readonly OrdersModel model; - public readonly SecurityImmutable? security; - public readonly SecurityMD? security_md; - - public _ObservedData(AlgoEditingPermissions permissions, OrdersModel model, SecurityImmutable? security, SecurityMD? security_md) { - this.permissions = permissions; - this.model = model; - this.security = security; - this.security_md = security_md; - } - - public void forward_to(IAlgoVM recipient) { - (recipient as IObserver)?.OnNext(permissions); - if (model != null) - (recipient as IObserver)?.OnNext(model); - if (security_md.HasValue) - (recipient as IObserver)?.OnNext(security_md); - if (security.HasValue) - (recipient as IObserver)?.OnNext(security); - } - - public _ObservedData with(AlgoEditingPermissions? permissions) => - new _ObservedData(permissions ?? this.permissions, model, security, security_md); - - public _ObservedData with(OrdersModel model) => - new _ObservedData(permissions, model, security, security_md); - - public _ObservedData with(SecurityImmutable? security) => - new _ObservedData(permissions, model, security, security_md); - - public _ObservedData with(SecurityMD? security_md) => - new _ObservedData(permissions, model, security, security_md); - } - } -} diff --git a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs index c49712bae..fd9f18e82 100644 --- a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs +++ b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs @@ -39,31 +39,6 @@ namespace mbts.spark { } } - static IDisposable _wrap_rows(AlgoDefinitionVM algo_def, ObservableAggregateCollection rows, bool include_algo_type_rows) { - AlgoParamRowVM root = null; - ObservableAggregateCollection algo_params; - if (include_algo_type_rows) { - // while normal params live and die with the selected algo-type (when the algo-type changes, they are removed, and replaced with params for the new algo type), - // the algo-type row is constant (it is the row with the algo-type dropdown, which the user may use to select different algos). - algo_params = new ObservableAggregateCollection(); - rows.add_collection(new ObservableAppendCollection(algo_params, root = new AlgoSelectorParamRowVM(new AlgoVMWrapper(algo_def), algo_def, null)).AsReadOnly()); - } else { - algo_params = rows; - } - return algo_def.observe_algo_root().SubscribeEach(a => { - algo_params.clear_collections(); - if (a == null) - return Disposable.empty; - var child_rows = new ObservableAggregateCollection(); - /// Note: the order of operations here matters - /// has the potential to trigger a lot of CollectionChanged events (depending on how deep the algo-tree is). - /// There is no need to burden the aggregate 'rows' with echoing all of these events, if the child-row collection is finished changing when it is added to the aggregate. - var hook = _wrap_rows(a, root, child_rows, include_algo_type_rows); - algo_params.add_collection(child_rows.AsReadOnly()); - return hook; - }); - } - static IDisposable _wrap_rows(IAlgoVM algo_root, AlgoParamRowVM parent, ObservableAggregateCollection all_rows, bool include_algo_type_rows) { var wrapped_params = new ObservableAutoWrapper(algo_root.algo_params, pvm => new AlgoParamRowVM(algo_root, pvm, parent)); var selector_params = new ObservableCollection(); @@ -85,4 +60,4 @@ namespace mbts.spark { } } } -} +} \ No newline at end of file diff --git a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorView.xaml b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorView.xaml index 179c48a45..847228a60 100644 --- a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorView.xaml +++ b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorView.xaml @@ -106,7 +106,7 @@ { if (obj is AlgoDefinitionVM) return DefinitionDropDownStyleKey; return null; - }), - DataContextConverter = ValueConverter.create(obj => obj is AlgoVMWrapper w ? w.value.algo_root : obj); + }); public static IMultiValueConverter TriggerTimeoutStateConverter = ValueConverter.create((is_timeout_enabled, editing_permissions) =>