diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs index 1c652e381..deeeba2ab 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs @@ -1,7 +1,6 @@ using bts.api; using bts.shell; using bts.spark; -using mbts.config; using mbts.ui; using mbts.ui.spark; using mbts.utils; @@ -14,6 +13,7 @@ using System.Windows.Media; namespace mbts.spark { class MarketViewWindow : SparkWindow { + const string _window_type = "MarketView"; readonly MarketViewWindowFactory _factory; readonly OrdersModel _orders_model; @@ -61,6 +61,7 @@ namespace mbts.spark { public void update_criteria(SecurityCriteria c) => _initialize(new MarketViewWindowFactory.StartupData(c, _vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states())); + public override string window_type => _window_type; public override UIElement Content => _view; public override IEnumerable Commands { get; } public override MarketViewWindowFactory.StartupData SaveState => _state = new MarketViewWindowFactory.StartupData(_state.security_criteria, _vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states()); diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs index df0ee6e7e..ea4758743 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs @@ -15,6 +15,7 @@ using static bts.shell.TimeAndSalesWindowFactory; namespace mbts.spark { class TimeAndSalesWindow : SparkWindow, ISlowWindow { + const string _window_type = "TimeAndSales"; readonly MDConsumer _consumer; readonly TimeAndSalesWindowFactory _factory; SingleValuePump _vm; @@ -31,6 +32,7 @@ namespace mbts.spark { _state = state; } + public override string window_type => _window_type; public override IEnumerable Commands => _commands; public override UIElement Content => _view; public override double MinWidth => 444 + SPARK_MENU_COLLAPSED_WIDTH + LAUNCHER_BUTTON_BORDER_WIDTH; diff --git a/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs b/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs index bac5fb36d..b997562f4 100644 --- a/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs +++ b/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs @@ -13,6 +13,7 @@ using static bts.shell.SyntheticManagementWindowFactory; namespace mbts.spark { class SyntheticManagementWindow : SparkWindow { + const string _window_type = "SyntheticManagement"; SingleValuePump _vm = new SingleValuePump(); StartupData _state; OrdersModel _orders_model; @@ -60,6 +61,7 @@ namespace mbts.spark { else _view.DataContext = _vm.value; } + public override string window_type => _window_type; public override UIElement Content => _view; public override IEnumerable Commands { get; } public override StartupData SaveState => _state = new StartupData(_vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states()); diff --git a/src/client/spark/Modules/Support/ActivityLog/ActivityLogWindow.cs b/src/client/spark/Modules/Support/ActivityLog/ActivityLogWindow.cs index fce30735f..3f53d964a 100644 --- a/src/client/spark/Modules/Support/ActivityLog/ActivityLogWindow.cs +++ b/src/client/spark/Modules/Support/ActivityLog/ActivityLogWindow.cs @@ -15,6 +15,7 @@ using System.Windows.Media; namespace bts.shell { class ActivityLogWindow : SparkWindow, ISharedWindow { + const string _window_type = "ActivityLog"; readonly IObservable _message_src; readonly LogViewerMessageCollection _messages = new LogViewerMessageCollection(); IDisposable _dispose; @@ -25,6 +26,7 @@ namespace bts.shell _message_src = messages; } + public override string window_type => _window_type; public override ActivityWindowState SaveState => new ActivityWindowState(); public override UIElement Content => _content; diff --git a/src/client/spark/Modules/Trading/Fills/FillsWindow.cs b/src/client/spark/Modules/Trading/Fills/FillsWindow.cs index 2e368f60f..36a111a4a 100644 --- a/src/client/spark/Modules/Trading/Fills/FillsWindow.cs +++ b/src/client/spark/Modules/Trading/Fills/FillsWindow.cs @@ -6,9 +6,9 @@ using mbts.ui.spark; using mbts.utils; using System.Windows; -namespace mbts.spark -{ +namespace mbts.spark { class FillsWindow : SparkWindow { + const string _window_type = "Fills"; readonly OrdersModel _orders_model; SingleValuePump _vm = new SingleValuePump(); FillsWindowFactory.StartupData _state; @@ -31,6 +31,7 @@ namespace mbts.spark else _view.DataContext = _vm.value; } + public override string window_type => _window_type; public override UIElement Content => _view; public override FillsWindowFactory.StartupData SaveState => _state = new FillsWindowFactory.StartupData(_state.orders, _vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filters()); public override double MinWidth => 1050 + SPARK_MENU_COLLAPSED_WIDTH + LAUNCHER_BUTTON_BORDER_WIDTH; diff --git a/src/client/spark/Modules/Trading/LadderWindowFactory.cs b/src/client/spark/Modules/Trading/LadderWindowFactory.cs index 6db1b16c1..18db8ee71 100644 --- a/src/client/spark/Modules/Trading/LadderWindowFactory.cs +++ b/src/client/spark/Modules/Trading/LadderWindowFactory.cs @@ -14,6 +14,7 @@ using System.Windows; namespace bts.shell { class LadderWindowFactory : ShellWindowFactory { + const string _window_type = "Ladder"; readonly IBus _bus; readonly IWindowManager _wm; readonly OrdersModel _orders_model; @@ -26,8 +27,7 @@ namespace bts.shell { _wm = wm; _orders_model = orders_model; var window_props = Configuration.get(); - _max_ladders_open = window_props != null && window_props.ladder != null ? - (int)window_props.ladder.max_total_open : 50; + _max_ladders_open = (int)(window_props?.ladder?.max_total_open ?? 50); _dispose = Disposable.Create( bus.subscribe(SparkTags.SecuritiesTag).Subscribe(s => _securities = s), bus.subscribe(SparkTags.ShowLadderTag).ObserveOnDispatcher().Subscribe(s => show_windows(new[] { s })), @@ -46,7 +46,6 @@ namespace bts.shell { static LadderSaveState _get_state(LadderVM vm) => new LadderSaveState { security_key = vm.security.Id, settings = vm.current_settings }; - const string _thread_prefix = "Ladder"; int _ladder_count = 0; IShellWindow create_ladder_window(SecurityMD md, IObservable settings) { var id = Interlocked.Increment(ref _ladder_count) % Environment.ProcessorCount; @@ -55,18 +54,16 @@ namespace bts.shell { var vm = new LadderVM(_bus, model, settings); return new LadderView(vm); }); - string thread = Configuration.get().enabled ? $"{_thread_prefix}{id:00}" : ""; + string thread = Configuration.get().enabled ? $"Ladder{id:00}" : ""; return ShellWindow.create( - module, md.security.ToString(), view, + module, md.security.ToString(), _window_type, view, (v,s) => save(_get_state(((LadderView)v).vm), s), icon: Icons.Ladder, thread_id: thread); } void show_windows(IReadOnlyCollection securities) { - // This is not the most elegant way to count ladders, but I expect the window limits responsibility will eventually be moved to the IWindowManager. - // In the meantime, this will do the job (I considered making an actual LadderWindow Class, so OfType().Count() would work, but this is pretty much the same thing). - int n_allowed = _max_ladders_open - _wm.Windows.OfType().Where(w => w.thread_id.StartsWith(_thread_prefix)).Count(); + int n_allowed = _max_ladders_open - _wm.Windows.Where(w => w.window_type == _window_type).Count(); int n_opened = 0; foreach (var s in securities) { if (++n_opened > n_allowed) { diff --git a/src/client/spark/Tests/ViewTests/TestShellWindow.cs b/src/client/spark/Tests/ViewTests/TestShellWindow.cs index b654900b3..06e6eb1f8 100644 --- a/src/client/spark/Tests/ViewTests/TestShellWindow.cs +++ b/src/client/spark/Tests/ViewTests/TestShellWindow.cs @@ -14,6 +14,7 @@ namespace mbts.ui.tests public event Action TitleChanged = () => { }; public System.Windows.Media.ImageSource Icon { get { return null; } } public event Action IconChanged = () => { }; + public string window_type { get; } public IShellModule Owner { get; set; } public void GetState(System.IO.Stream save_here) { } #endregion diff --git a/src/client/spark/core/ShellInterface/IShellWindow.cs b/src/client/spark/core/ShellInterface/IShellWindow.cs index 05ea173fe..a6b3e299e 100644 --- a/src/client/spark/core/ShellInterface/IShellWindow.cs +++ b/src/client/spark/core/ShellInterface/IShellWindow.cs @@ -1,20 +1,18 @@ -using System; +using mbts.ui.shell; +using System; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; -using System.Threading.Tasks; using System.Windows; using System.Windows.Media; using System.Windows.Threading; -using mbts.ui.shell; -using mbts; -namespace mbts.ui -{ - public interface IShellWindow : IDisposable - { +namespace mbts.ui { + public interface IShellWindow : IDisposable { // Window title string Title { get; set; } + // Window type (e.g Ladder, MarketView, etc) + string window_type { get; } // Call this callback if you set the title property so the shell knows to update the display. event Action TitleChanged; @@ -99,4 +97,4 @@ namespace mbts.ui } } } -} +} \ No newline at end of file diff --git a/src/client/spark/view/Controls/Browser/BrowserWindow.cs b/src/client/spark/view/Controls/Browser/BrowserWindow.cs index 6e559f1c0..3090bcd12 100644 --- a/src/client/spark/view/Controls/Browser/BrowserWindow.cs +++ b/src/client/spark/view/Controls/Browser/BrowserWindow.cs @@ -1,19 +1,16 @@ -using System; +using bts.api; +using mbts.config; +using mbts.spark; +using ProtoBuf; +using System; using System.Collections.Generic; using System.ComponentModel.Composition; -using System.Linq; -using System.Text; using System.Threading.Tasks; using System.Windows.Controls; -using ProtoBuf; -using mbts.config; -using bts.api; -using mbts.spark; -namespace mbts.ui.controls -{ - public class BrowserWindow : IShellWindow - { +namespace mbts.ui.controls { + public class BrowserWindow : IShellWindow { + const string _window_type = "Browser"; private WebBrowser _browser; public BrowserWindow(Uri uri, IShellModule owner) { @@ -71,6 +68,8 @@ namespace mbts.ui.controls public System.Windows.Media.ImageSource Icon { get { return Icons.FavoriteWindow; } } public event Action IconChanged = () => { }; + public string window_type => _window_type; + public IShellModule Owner {get; set; } public ShellWindowUI GetContent() { return new ShellWindowUI(_browser); } diff --git a/src/client/spark/view/Controls/HierarchicalLaunchMenu.xaml.cs b/src/client/spark/view/Controls/HierarchicalLaunchMenu.xaml.cs index 36bc9bfa0..7766023b6 100644 --- a/src/client/spark/view/Controls/HierarchicalLaunchMenu.xaml.cs +++ b/src/client/spark/view/Controls/HierarchicalLaunchMenu.xaml.cs @@ -28,6 +28,7 @@ namespace mbts.ui.controls public event Action TitleChanged = () => { }; public ImageSource Icon { get; set; } public event Action IconChanged = () => { }; + public string window_type { get; set; } public IShellModule Owner { get; set; } public void Dispose() { } public void GetState(System.IO.Stream save_here) { } diff --git a/src/client/spark/view/Controls/MenuLaunchMenu.xaml.cs b/src/client/spark/view/Controls/MenuLaunchMenu.xaml.cs index 7ee8d0cf8..947ca39ae 100644 --- a/src/client/spark/view/Controls/MenuLaunchMenu.xaml.cs +++ b/src/client/spark/view/Controls/MenuLaunchMenu.xaml.cs @@ -31,6 +31,7 @@ namespace mbts.ui.controls public event Action TitleChanged = () => { }; public ImageSource Icon { get; set; } public event Action IconChanged = () => { }; + public string window_type { get; set; } public IShellModule Owner { get; set; } public void Dispose() { } public void GetState(System.IO.Stream save_here) { } diff --git a/src/client/spark/view/Extensions/ShellWindow.cs b/src/client/spark/view/Extensions/ShellWindow.cs index 73592d5cc..2a86f0cc5 100644 --- a/src/client/spark/view/Extensions/ShellWindow.cs +++ b/src/client/spark/view/Extensions/ShellWindow.cs @@ -1,16 +1,9 @@ -using mbts; -using System; -using System.Collections; -using System.Collections.Generic; +using System; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Media; -namespace mbts.ui -{ +namespace mbts.ui { public static class ShellWindow { private class AnonShellWindow : IShellWindow { private ImageSource _icon; @@ -24,6 +17,7 @@ namespace mbts.ui get { return _title; } set { _title = value; TitleChanged?.Invoke(); } } + public string window_type { get; set; } public event Action IconChanged; public event Action TitleChanged; @@ -51,19 +45,20 @@ namespace mbts.ui public void thread_init() { } } - public static IShellWindow create(IShellModule owner, string title, Lazy content, Action get_state = null, ImageSource icon = null, string thread_id=null) { + public static IShellWindow create(IShellModule owner, string title, string window_type, Lazy content, Action get_state = null, ImageSource icon = null, string thread_id=null) { if (string.IsNullOrEmpty(thread_id)) { - return create(owner, title, content, get_state, icon); + return create(owner, title, window_type, content, get_state, icon); } else { - var res = create(owner, title, content, get_state, icon); + var res = create(owner, title, window_type, content, get_state, icon); res.thread_id = thread_id; return res; } } - static T create(IShellModule owner, string title, Lazy content, Action get_state=null, ImageSource icon=null) where T : AnonShellWindow, new() { + static T create(IShellModule owner, string title, string window_type, Lazy content, Action get_state=null, ImageSource icon=null) where T : AnonShellWindow, new() { var result = new T() { Title = title, + window_type = window_type, Icon = icon ?? (owner != null ? owner.icon : Icons.Window), Owner = owner, get_state = get_state, diff --git a/src/client/spark/view/Shell/Error/ErrorShellWindow.cs b/src/client/spark/view/Shell/Error/ErrorShellWindow.cs index cf61be2e4..25567c479 100644 --- a/src/client/spark/view/Shell/Error/ErrorShellWindow.cs +++ b/src/client/spark/view/Shell/Error/ErrorShellWindow.cs @@ -1,12 +1,9 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -namespace mbts.ui.shell -{ - public class ErrorShellWindow : IShellWindow - { +namespace mbts.ui.shell { + public class ErrorShellWindow : IShellWindow { + const string _window_type = "Error"; + public string Title { get; set; } public event Action TitleChanged = () => { }; @@ -15,6 +12,8 @@ namespace mbts.ui.shell public event Action IconChanged = () => { }; + public string window_type => _window_type; + public IShellModule Owner { get { return null; } set { } @@ -34,4 +33,4 @@ namespace mbts.ui.shell } } -} +} \ No newline at end of file diff --git a/src/client/spark/view/Shell/ShellLaunchMenu.xaml.cs b/src/client/spark/view/Shell/ShellLaunchMenu.xaml.cs index ed3743f4a..7de815888 100644 --- a/src/client/spark/view/Shell/ShellLaunchMenu.xaml.cs +++ b/src/client/spark/view/Shell/ShellLaunchMenu.xaml.cs @@ -1,19 +1,9 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -namespace mbts.ui.shell -{ +namespace mbts.ui.shell { public class ShellLaunchMenuItem { public string name { get; set; } @@ -53,6 +43,8 @@ namespace mbts.ui.shell public event Action IconChanged = () => { }; + public string window_type { get; set; } + public mbts.ui.IShellModule Owner { get { return null; } diff --git a/src/client/spark/view/Spark/PAndL/PAndLWindow.cs b/src/client/spark/view/Spark/PAndL/PAndLWindow.cs index d59033b0f..a3bb149f1 100644 --- a/src/client/spark/view/Spark/PAndL/PAndLWindow.cs +++ b/src/client/spark/view/Spark/PAndL/PAndLWindow.cs @@ -13,7 +13,7 @@ using System.Windows.Media; namespace mbts.spark { internal class PAndLWindow : SparkWindow, ISharedWindow { - const string PNL_THREAD_ID = "PnL"; + const string _window_type = "PAndL", PNL_THREAD_ID = "PnL"; PAndLWindowFactory.PAndLStartupData _state; PAndLModel _model; PAndLView _view; @@ -25,6 +25,7 @@ namespace mbts.spark { _state = state; } + public override string window_type => _window_type; public override PAndLWindowFactory.PAndLStartupData SaveState => _state = new PAndLWindowFactory.PAndLStartupData(); public override UIElement Content => _view; diff --git a/src/client/spark/view/Spark/Shell/OrderBook/OrderBookWindow.cs b/src/client/spark/view/Spark/Shell/OrderBook/OrderBookWindow.cs index d41863305..c8230979c 100644 --- a/src/client/spark/view/Spark/Shell/OrderBook/OrderBookWindow.cs +++ b/src/client/spark/view/Spark/Shell/OrderBook/OrderBookWindow.cs @@ -12,7 +12,7 @@ using System.Windows.Media; namespace mbts.spark { internal class OrderBookWindow : SparkWindow, ISharedWindow { - const string ORDERBOOK_THREAD_ID = "OrderBook"; + const string _window_type = "OrderBook", ORDERBOOK_THREAD_ID = "OrderBook"; OrderBookWindowFactory.OrderBookStartupData _state; OrdersModel _model; OrderBookVM _vm; @@ -41,6 +41,7 @@ namespace mbts.spark { _vm.get_filter_states() ); + public override string window_type => _window_type; public override UIElement Content => _view; public override IEnumerable Commands => _commands; public override double MinWidth => 1577; diff --git a/src/client/spark/view/Spark/SparkWindow.cs b/src/client/spark/view/Spark/SparkWindow.cs index faf3f1764..1432a42c8 100644 --- a/src/client/spark/view/Spark/SparkWindow.cs +++ b/src/client/spark/view/Spark/SparkWindow.cs @@ -54,6 +54,7 @@ namespace bts.spark { } } public IShellModule Owner => _save.module; + public abstract string window_type { get; } public abstract T SaveState { get; } public abstract UIElement Content { get; } public virtual IEnumerable Commands => Enumerable.Empty();