Add the idea of a PartialCommand to SparkCommands. This is a SparkCommand without a payload. It cannot be posted to the bus until a payload is provided by calling .complete() on it
This commit is contained in:
1 parent
4e86357645
commit
50bd7aff0e
13 files changed
+107
-95
No files matched your search
@@ -10,6 +10,7 @@ using System.ComponentModel.Composition;
|
||||
using mbts;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using bts.spark;
|
||||
|
||||
namespace bts {
|
||||
[Export, Export(typeof(IShellDaemon))]
|
||||
@@ -26,13 +27,13 @@ namespace bts {
|
||||
);
|
||||
}
|
||||
|
||||
void show_pick_one(SparkBusData.ContractPickerOneMessage message) {
|
||||
void show_pick_one(PartialCommand<SecurityMD> message) {
|
||||
var vm = new ContractPickerModel(_bus, false, null);
|
||||
var view = new ContractPickerView(vm);
|
||||
|
||||
Window picker = new Window {
|
||||
Content = view,
|
||||
Title = $" {message.window_title} security selection",
|
||||
Title = $" {message.title} security selection",
|
||||
Icon = message.icon,
|
||||
Height = view.Height,
|
||||
Width = view.Width
|
||||
@@ -43,20 +44,20 @@ namespace bts {
|
||||
|
||||
vm.close_action = () => {
|
||||
picker.Close();
|
||||
_bus.post(message.next, vm.result);
|
||||
message.complete(vm.result).execute(_bus);
|
||||
};
|
||||
picker.move_to_mouse();
|
||||
picker.Show();
|
||||
}
|
||||
|
||||
void show_pick_multiple(SparkBusData.ContractPickerNMessage message) {
|
||||
void show_pick_multiple(PartialCommand<SecurityCriteria> message) {
|
||||
var vm = new ContractPickerModel(_bus, true, null);
|
||||
var view = new ContractPickerView(vm);
|
||||
|
||||
Window picker = new Window
|
||||
{
|
||||
Content = view,
|
||||
Title = $" {message.window_title} security selection",
|
||||
Title = $" {message.title} security selection",
|
||||
Icon = message.icon,
|
||||
Height = view.Height,
|
||||
Width = view.Width,
|
||||
@@ -67,7 +68,7 @@ namespace bts {
|
||||
|
||||
vm.close_action = () => {
|
||||
picker.Close();
|
||||
_bus.post(message.next, vm.result_criteria);
|
||||
message.complete(vm.result_criteria).execute(_bus);
|
||||
};
|
||||
picker.move_to_mouse();
|
||||
picker.Show();
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace bts.shell
|
||||
public int priority => 10;
|
||||
|
||||
public IEnumerable<SparkCommand> actions => new [] {
|
||||
SparkCommands.ShowMarketView,
|
||||
SparkCommands.ShowTimeAndSales
|
||||
SparkCommands.PickMarketView,
|
||||
SparkCommands.PickTimeAndSales
|
||||
};
|
||||
|
||||
public Task<IShellWindow> create(Stream load_stream) {
|
||||
|
||||
@@ -47,7 +47,8 @@ namespace mbts.spark {
|
||||
public override UIElement Content => _view;
|
||||
|
||||
public override IEnumerable<SparkCommand> Commands => new[] {
|
||||
SparkCommands.ShowLadder
|
||||
SparkCommands.PickLadder
|
||||
//SparkCommands.ShowLadderDirect.parameterize(selected_security ;
|
||||
// linked ladder
|
||||
// OrderTicket
|
||||
// LinkedOrderTicket
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace bts.shell {
|
||||
);
|
||||
}
|
||||
public override async Task<IShellWindow> load(TimeAndSalesStartupData state) {
|
||||
return await TimeAndSalesWindow.create(this, _bus, state, SparkCommands.ShowTimeAndSales.icon);
|
||||
return await TimeAndSalesWindow.create(this, _bus, state, SparkCommands.PickTimeAndSales.icon);
|
||||
}
|
||||
|
||||
public async void show(SecurityCriteria criteria) {
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace bts.Modules.Support {
|
||||
SparkCommands.ShowManual,
|
||||
SparkCommands.ShowAuditLogs,
|
||||
SparkCommands.ShowDiagnostics,
|
||||
SparkCommands.ShowReportIssue,
|
||||
SparkCommands.ShowReportIssue.complete("Create Support Ticket"),
|
||||
SparkCommands.ShowAboutSpark
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace bts.shell {
|
||||
}
|
||||
|
||||
|
||||
void show_fills_window(IEnumerable<SecurityImmutable> secs) {
|
||||
void show_fills_window(SecurityCriteria secs) {
|
||||
}
|
||||
IShellWindow create_fills_window(IEnumerable<SecurityImmutable> secs, IEnumerable<SortingCriteria> sort) {
|
||||
var vm = new FillsVM(this, _bus, new DemoOrdersModel(_bus), _ssrc, secs, sort);
|
||||
|
||||
@@ -21,11 +21,13 @@ namespace bts.shell {
|
||||
Disposable.dispose(ref _dispose);
|
||||
}
|
||||
|
||||
private void show_order_ticket(OneOf<SecurityMD, Order> t) {
|
||||
var vm =
|
||||
t.Match(
|
||||
md => null,
|
||||
order => new OrderTicketVM(new DemoOrdersModel(_bus), order, null, _bus));
|
||||
private void show_order_ticket(SecurityMD md) {
|
||||
// This is temporary until the new-new Order type comes in
|
||||
var vm =
|
||||
new OrderTicketVM(
|
||||
new DemoOrdersModel(_bus),
|
||||
new Order() { Security = md.security.CloneToMutable() },
|
||||
null, _bus);
|
||||
|
||||
var ui = new OrderTicket() { DataContext = vm };
|
||||
ui.Show(-200, -160, true);
|
||||
|
||||
@@ -38,12 +38,12 @@ namespace bts.shell {
|
||||
|
||||
public int priority => 20;
|
||||
|
||||
public IEnumerable<SparkCommand> actions => new[] {
|
||||
public IEnumerable<SparkCommand> actions => new [] {
|
||||
SparkCommands.ShowOrders,
|
||||
SparkCommands.ShowFills,
|
||||
SparkCommands.PickFills,
|
||||
SparkCommands.ShowPAndL,
|
||||
SparkCommands.ShowLadder,
|
||||
SparkCommands.ShowOrderTicket
|
||||
SparkCommands.PickLadder,
|
||||
SparkCommands.PickOrderTicket
|
||||
};
|
||||
|
||||
IEnumerable<IShellWindowFactory> window_factories() {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using bts.api;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,6 +9,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using static mbts.spark.SparkTags;
|
||||
|
||||
namespace bts.spark {
|
||||
|
||||
@@ -21,46 +24,65 @@ namespace bts.spark {
|
||||
public abstract void execute(IBus bus);
|
||||
public virtual bool canExecute() { return true; }
|
||||
|
||||
public static SparkCommand<T> create<T>(
|
||||
string title, ImageSource icon, ITag<T> tag) {
|
||||
return new SparkCommand<T>(title, icon, tag, null, null);
|
||||
public static PartialCommand<T> create<T>(string title, ImageSource icon, ITag<T> tag) {
|
||||
return new PartialCommand<T>(title, icon, tag);
|
||||
}
|
||||
internal static SparkCommand<Nothing> create(string title, ImageSource icon, ITag<Nothing> tag) {
|
||||
return new SparkCommand<Nothing>(title, icon, tag, () => null, null);
|
||||
}
|
||||
|
||||
public static SparkCommand<T> create<T>(
|
||||
string title, ImageSource icon, ITag<T> tag, T parameter) {
|
||||
public static SparkCommand<T> create<T>(string title, ImageSource icon, ITag<T> tag, T parameter) {
|
||||
return new SparkCommand<T>(title, icon, tag, () => parameter, null);
|
||||
}
|
||||
|
||||
public static SparkCommand<T> create<T>(
|
||||
string title, ImageSource icon, ITag<T> tag, Func<T> parameter, Func<bool> can_execute) {
|
||||
return new SparkCommand<T>(title, icon, tag, parameter, can_execute);
|
||||
public static SparkCommand<T> create<T>(string title, ImageSource icon, ITag<T> tag, Func<T> parameter) {
|
||||
return new SparkCommand<T>(title, icon, tag, parameter, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class PartialCommand<T> {
|
||||
public PartialCommand(string title, ImageSource icon, ITag<T> tag) {
|
||||
this.title = title;
|
||||
this.icon = icon;
|
||||
this.tag = tag;
|
||||
}
|
||||
public string title { get; }
|
||||
public ImageSource icon { get; }
|
||||
public ITag<T> tag { get; }
|
||||
|
||||
public SparkCommand<T> complete(T value) {
|
||||
return SparkCommand.create(title, icon, tag, () => value);
|
||||
}
|
||||
public SparkCommand<T> complete(Func<T> value) {
|
||||
return SparkCommand.create(title, icon, tag, value);
|
||||
}
|
||||
public SparkCommand<T> complete() {
|
||||
return SparkCommand.create(title, icon, tag, ()=>default);
|
||||
}
|
||||
}
|
||||
|
||||
public class SparkCommand<T> : SparkCommand {
|
||||
public SparkCommand(
|
||||
string title, ImageSource icon,
|
||||
ITag<T> tag, Func<T> param, Func<bool> can_execute) : base(title, icon) {
|
||||
string title, ImageSource icon,
|
||||
ITag<T> tag, Func<T> param, Func<T, bool> can_execute) : base(title, icon) {
|
||||
this.tag = tag;
|
||||
_get_parameter = param ?? (()=>default);
|
||||
_get_parameter = param ?? (() => default);
|
||||
_can_execute = can_execute;
|
||||
}
|
||||
|
||||
Func<T> _get_parameter;
|
||||
Func<bool> _can_execute;
|
||||
Func<T, bool> _can_execute;
|
||||
public ITag<T> tag { get; }
|
||||
|
||||
public override void execute(IBus bus) {
|
||||
bus.post(tag, _get_parameter());
|
||||
}
|
||||
public override bool canExecute() {
|
||||
return _can_execute?.Invoke() ?? base.canExecute();
|
||||
return _can_execute?.Invoke(_get_parameter()) ?? base.canExecute();
|
||||
}
|
||||
public SparkCommand<T> with_parameter(T parameter, Func<bool> can_execute=null) {
|
||||
return create(title, icon, tag, () => parameter, can_execute);
|
||||
}
|
||||
public SparkCommand<T> with_parameter(Func<T> parameter, Func<bool> can_execute=null) {
|
||||
return create(title, icon, tag, parameter, can_execute);
|
||||
|
||||
public SparkCommand<T> conditional(Func<T, bool> can_execute) {
|
||||
return new SparkCommand<T>(title, icon, tag, _get_parameter, can_execute);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +100,7 @@ namespace bts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class SparkCommandVM : mbts.ui.shell.ViewModelBase, ICommand {
|
||||
readonly SparkCommand _cmd;
|
||||
readonly IBus _bus;
|
||||
|
||||
@@ -13,50 +13,65 @@ namespace bts.spark
|
||||
{
|
||||
|
||||
// Market
|
||||
public static SparkCommand ShowMarketView { get; } =
|
||||
SparkCommand.create("Market View", Icons.Sheets, SparkTags.ShowPickMultiple, new ContractPickerNMessage(SparkTags.ShowMarketViewTag, "Market View", Icons.Sheets));
|
||||
public static SparkCommand ShowTimeAndSales { get; } =
|
||||
SparkCommand.create("Time and Sales", Icons.Clock, SparkTags.ShowPickMultiple, new ContractPickerNMessage(SparkTags.ShowTimeAndSalesTag, "Time and Sales", Icons.Clock));
|
||||
public static PartialCommand<SecurityCriteria> ShowMarketView =>
|
||||
SparkCommand.create("Market View", Icons.Sheets, SparkTags.ShowMarketViewTag);
|
||||
public static SparkCommand PickMarketView =>
|
||||
SparkCommand.create("Market View", Icons.Sheets, SparkTags.ShowPickMultiple, ShowMarketView);
|
||||
|
||||
public static PartialCommand<SecurityCriteria> ShowTimeAndSales =>
|
||||
SparkCommand.create("Time and Sales", Icons.Clock, SparkTags.ShowTimeAndSalesTag);
|
||||
public static SparkCommand PickTimeAndSales =>
|
||||
SparkCommand.create("Time and Sales", Icons.Clock, SparkTags.ShowPickMultiple, ShowTimeAndSales);
|
||||
|
||||
// Trading
|
||||
public static SparkCommand ShowOrders { get; } =
|
||||
public static SparkCommand ShowOrders =>
|
||||
SparkCommand.create("Order Book", Icons.Book, SparkTags.ShowOrderBookTag);
|
||||
public static SparkCommand ShowFills { get; } =
|
||||
|
||||
public static PartialCommand<SecurityCriteria> ShowFills =>
|
||||
SparkCommand.create("Fills", Icons.Payment, SparkTags.ShowFillsTag);
|
||||
public static SparkCommand ShowPAndL { get; } =
|
||||
public static SparkCommand PickFills =>
|
||||
SparkCommand.create("Fills", Icons.Payment, SparkTags.ShowPickMultiple, ShowFills);
|
||||
|
||||
public static SparkCommand ShowPAndL =>
|
||||
SparkCommand.create("Position/P&L", Icons.Accounting, SparkTags.ShowPositionsTag);
|
||||
public static SparkCommand ShowLadder { get; }
|
||||
= SparkCommand.create("Ladder", Icons.Depth, SparkTags.ShowPickOne, new ContractPickerOneMessage(SparkTags.ShowLadderTag, "Ladder", Icons.Depth));
|
||||
public static SparkCommand ShowOrderTicket { get; } =
|
||||
|
||||
public static SparkCommand PickLadder =>
|
||||
SparkCommand.create("Ladder", Icons.Depth, SparkTags.ShowPickOne, ShowLadder);
|
||||
public static PartialCommand<SecurityMD> ShowLadder =>
|
||||
SparkCommand.create("Ladder", Icons.Depth, SparkTags.ShowLadderTag);
|
||||
|
||||
public static PartialCommand<SecurityMD> ShowOrderTicket =>
|
||||
SparkCommand.create("Order Ticket", Icons.Ticket, SparkTags.ShowOrderTicketTag);
|
||||
public static SparkCommand PickOrderTicket =>
|
||||
SparkCommand.create("Order Ticket", Icons.Ticket, SparkTags.ShowPickOne, ShowOrderTicket);
|
||||
|
||||
// Spreader
|
||||
public static SparkCommand ShowSyntheticSpreads { get; }
|
||||
= SparkCommand.create("Synthetic Spreads", Icons.Spreads, SparkTags.NotImplemented);
|
||||
public static SparkCommand ShowSyntheticSpreads =>
|
||||
SparkCommand.create("Synthetic Spreads", Icons.Spreads, SparkTags.NotImplemented);
|
||||
|
||||
public static SparkCommand ShowLatencyReport { get; } =
|
||||
public static SparkCommand ShowLatencyReport =>
|
||||
SparkCommand.create("Latency Report", Icons.Analytics, SparkTags.NotImplemented);
|
||||
|
||||
// Settings
|
||||
public static SparkCommand ShowWorkspaces { get; } =
|
||||
public static SparkCommand ShowWorkspaces =>
|
||||
SparkCommand.create("Workspaces", Icons.FavoriteWindow, SparkTags.ShowWorkspaces);
|
||||
public static SparkCommand ShowSettings { get; } =
|
||||
public static SparkCommand ShowSettings =>
|
||||
SparkCommand.create("Settings", Icons.Admin, SparkTags.ShowSettings);
|
||||
|
||||
// Support
|
||||
public static SparkCommand ShowManual { get; } =
|
||||
public static SparkCommand ShowManual =>
|
||||
SparkCommand.create("Manual", Icons.Book, SparkTags.ShowUri, new Uri("bts://m/"));
|
||||
|
||||
public static SparkCommand ShowAuditLogs { get; } =
|
||||
public static SparkCommand ShowAuditLogs =>
|
||||
SparkCommand.create("Audit Logs", Icons.Book, SparkTags.NotImplemented);
|
||||
|
||||
public static SparkCommand ShowDiagnostics { get; } =
|
||||
public static SparkCommand ShowDiagnostics =>
|
||||
SparkCommand.create("Diagnostics", Icons.Target, SparkTags.NotImplemented);
|
||||
|
||||
public static SparkCommand ShowAboutSpark { get; } =
|
||||
public static SparkCommand ShowAboutSpark =>
|
||||
SparkCommand.create("About Spark", Icons.Support, SparkTags.About);
|
||||
|
||||
public static SparkCommand ShowReportIssue { get; } =
|
||||
public static PartialCommand<string> ShowReportIssue =>
|
||||
SparkCommand.create("Contact Support", Icons.Support, SparkTags.Support);
|
||||
|
||||
}
|
||||
|
||||
@@ -24,14 +24,14 @@ namespace mbts.spark {
|
||||
|
||||
#region Show Window
|
||||
public static ITag<ShowAuditLogsMessage> ShowAuditLogsTag { get; } = new SparkTag<ShowAuditLogsMessage>(nameof(ShowAuditLogsTag));
|
||||
public static ITag<SecurityList> ShowFillsTag { get; } = new SparkTag<SecurityList>(nameof(ShowFillsTag));
|
||||
public static ITag<SecurityCriteria> ShowFillsTag { get; } = new SparkTag<SecurityCriteria>(nameof(ShowFillsTag));
|
||||
public static ITag<SecurityMD> ShowLadderTag { get; } = new SparkTag<SecurityMD>("Show Ladder");
|
||||
public static ITag<IObservable<uint>> ShowLinkedLadder { get; } = new SparkTag<IObservable<uint>>("Linked Ladder");
|
||||
public static ITag<SecurityCriteria> ShowMarketViewTag { get; } = new SparkTag<SecurityCriteria>("Show MarketView");
|
||||
public static ITag<Nothing> ShowOrderBookTag { get; } = new SparkTag<Nothing>(nameof(ShowOrderBookTag));
|
||||
public static ITag<OrderID> ShowOrderDetailsTag { get; } = new SparkTag<OrderID>(nameof(ShowOrderDetailsTag));
|
||||
public static ITag<ShowOrderModifyMessage> ShowOrderModifyTag { get; } = new SparkTag<ShowOrderModifyMessage>(nameof(ShowOrderModifyTag));
|
||||
public static ITag<OneOf<SecurityMD, Order>> ShowOrderTicketTag = new SparkTag<OneOf<SecurityMD,Order>>(nameof(ShowOrderTicketTag));
|
||||
public static ITag<SecurityMD> ShowOrderTicketTag = new SparkTag<SecurityMD>(nameof(ShowOrderTicketTag));
|
||||
public static ITag<ShowLinkedOrderTicketMessage> ShowLinkedOrderTicketTag = new SparkTag<ShowLinkedOrderTicketMessage>(nameof(ShowLinkedOrderTicketTag));
|
||||
public static ITag<Nothing> ShowPositionsTag { get; } = new SparkTag<Nothing>(nameof(ShowPositionsTag));
|
||||
public static ITag<ShowSpreadMatrixMessage> ShowSpreadMatrixTag { get; } = new SparkTag<ShowSpreadMatrixMessage>(nameof(ShowSpreadMatrixTag));
|
||||
@@ -49,8 +49,8 @@ namespace mbts.spark {
|
||||
|
||||
public static ITag<IShellWindow> ShowWindow { get; } = new SparkTag<IShellWindow>("Show Window");
|
||||
|
||||
public static ITag<ContractPickerNMessage> ShowPickMultiple { get; } = new SparkTag<ContractPickerNMessage>("PickN");
|
||||
public static ITag<ContractPickerOneMessage> ShowPickOne { get; } = new SparkTag<ContractPickerOneMessage>("Pick1");
|
||||
public static ITag<PartialCommand<SecurityCriteria>> ShowPickMultiple { get; } = new SparkTag<PartialCommand<SecurityCriteria>>("PickN");
|
||||
public static ITag<PartialCommand<SecurityMD>> ShowPickOne { get; } = new SparkTag<PartialCommand<SecurityMD>>("Pick1");
|
||||
|
||||
public static ITag<string> Support { get; } = new SparkTag<string>(nameof(Support));
|
||||
public static ITag<Nothing> About { get; } = new SparkTag<Nothing>("About");
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace mbts.spark
|
||||
|
||||
public IEnumerable<SparkCommand> actions => new[] {
|
||||
new SparkCommandCommand("Go!", Icons.Tetris, new DelegateCommand(start)),
|
||||
SparkCommands.ShowLadder
|
||||
SparkCommands.PickLadder
|
||||
};
|
||||
|
||||
public Task<IShellWindow> create(Stream load_stream) {
|
||||
|
||||
@@ -45,32 +45,6 @@ namespace mbts.spark
|
||||
public OrderBookMessage(OrderBook order_book) { this.order_book = order_book; }
|
||||
}
|
||||
|
||||
public class ContractPickerOneMessage
|
||||
{
|
||||
public readonly ITag<SecurityMD> next;
|
||||
public readonly string window_title;
|
||||
public readonly System.Windows.Media.ImageSource icon;
|
||||
|
||||
public ContractPickerOneMessage(ITag<SecurityMD> next, string window_title, System.Windows.Media.ImageSource icon) {
|
||||
this.next = next;
|
||||
this.window_title = window_title;
|
||||
this.icon = icon;
|
||||
}
|
||||
}
|
||||
|
||||
public class ContractPickerNMessage
|
||||
{
|
||||
public readonly ITag<SecurityCriteria> next;
|
||||
public readonly string window_title;
|
||||
public readonly System.Windows.Media.ImageSource icon;
|
||||
|
||||
public ContractPickerNMessage(ITag<SecurityCriteria> next, string window_title, System.Windows.Media.ImageSource icon) {
|
||||
this.next = next;
|
||||
this.window_title = window_title;
|
||||
this.icon = icon;
|
||||
}
|
||||
}
|
||||
|
||||
public class SyntheticSecuritiesMessage : BusMessageWrapper<IDictionary<uint, SyntheticExecutionStrategy>> {
|
||||
public SyntheticSecuritiesMessage(IDictionary<uint, SyntheticExecutionStrategy> m) : base(m) { }
|
||||
}
|
||||
@@ -84,10 +58,6 @@ namespace mbts.spark
|
||||
public ShowOrderModifyMessage(Order order) : base(new[] { order }) { }
|
||||
public ShowOrderModifyMessage(IReadOnlyCollection<Order> orders) : base(orders) { }
|
||||
}
|
||||
public class ShowOrderTicketMessage : BusMessageWrapper<IReadOnlyCollection<Order>> {
|
||||
public ShowOrderTicketMessage(Order order) : base(new[] { order }) { }
|
||||
public ShowOrderTicketMessage(IReadOnlyCollection<Order> orders) : base(orders) { }
|
||||
}
|
||||
public class ShowLinkedOrderTicketMessage : BusMessageWrapper<IObservable<Order>> {
|
||||
public ShowLinkedOrderTicketMessage(IObservable<Order> order) : base(order) { }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user