public MainWindowViewModel(ISessionService resultService, IMessenger messenger) { _resultService = resultService; _messenger = messenger; if (IsInDesignMode) { SessionName = "localhost:1000"; } ExitCommand = new RelayCommand(() => Application.Current.Shutdown()); CloseCommand = new RelayCommand(() => _resultService.CloseSession()); OpenSessionCommand = new RelayCommand(() => _messenger.Send(new ShowNewSessionWindowMessage())); _messenger.Register <SessionOpenedMessage>(this, message => SessionName = message.Name); _messenger.Register <SessionClosedMessage>(this, message => { SessionName = string.Empty; Charts.Clear(); }); _messenger.Register <SessionUpdateMessage>(this, message => { try { lock (_charts) { ParseResult(message.Result); } } catch (Exception e) { Console.WriteLine(e); } }); _messenger.Register <GridRequestMessage>(this, message => { var chartTableViewModel = new GridPanelViewModel { Key = message.Key, }; // Calcualte the index for this tab var index = Charts.IndexOf(Charts.First(c => c.Key == message.Key)); Charts.Insert(index, chartTableViewModel); chartTableViewModel.IsSelected = true; // Get the latest data for this tab and inject it var chart = _resultService.LastResult.Charts[message.Key]; chartTableViewModel.ParseChart(chart); }); }
public MainWindowViewModel(ISessionService resultService, IMessenger messenger, ILayoutManager layoutManager, StatusViewModel statusViewModel) { StatusViewModel = statusViewModel; _sessionService = resultService; _layoutManager = layoutManager; _messenger = messenger; // TODO: These viewmodels should be injected LogPane = ViewModelLocator.LogPanel; StatisticsPane = ViewModelLocator.StatisticsPanel; RuntimeStatisticsPane = ViewModelLocator.RuntimeStatisticsPanel; ProfitLossPane = ViewModelLocator.ProfitLossPanel; TradesPane = ViewModelLocator.TradesPanel; ExitCommand = new RelayCommand(() => Application.Current.Shutdown()); CloseCommand = new RelayCommand(() => _sessionService.ShutdownSession(), () => IsSessionActive); OpenSessionCommand = new RelayCommand(() => _messenger.Send(new ShowNewSessionWindowMessage())); ExportCommand = new RelayCommand(Export, () => IsSessionActive); ConnectCommand = new RelayCommand(() => _sessionService.IsSessionSubscribed = true, () => _sessionState != SessionState.Subscribed && _sessionService.CanSubscribe); DisconnectCommand = new RelayCommand(() => _sessionService.IsSessionSubscribed = false, () => _sessionState != SessionState.Unsubscribed); SaveLayoutCommand = new RelayCommand <DockingManager>(manager => _layoutManager.SaveLayout(manager)); RestoreLayoutCommand = new RelayCommand <DockingManager>(manager => _layoutManager.LoadLayout(manager)); ResetLayoutCommand = new RelayCommand <DockingManager>(manager => _layoutManager.ResetLayout(manager)); _messenger.Register <SessionOpenedMessage>(this, message => InvalidateCommands()); _messenger.Register <SessionClosedMessage>(this, message => { SessionState = SessionState.Unsubscribed; Documents.Clear(); InvalidateCommands(); }); _messenger.Register <SessionStateChangedMessage>(this, message => { SessionState = message.State; InvalidateCommands(); }); _messenger.Register <SessionUpdateMessage>(this, message => { try { lock (_documents) { ParseResult(message.ResultContext.Result); } } catch (Exception e) { Console.WriteLine(e); } }); _messenger.Register <GridRequestMessage>(this, message => { var chartTableViewModel = new GridPanelViewModel { Key = message.Key }; // Calcualte the index for this tab var index = Documents.IndexOf(Documents.First(c => c.Key == message.Key)); Documents.Insert(index, chartTableViewModel); chartTableViewModel.IsSelected = true; // Get the latest data for this tab and inject it var chart = _sessionService.LastResult.Charts[message.Key]; chartTableViewModel.ParseChart(chart); }); }