public OptimizatorContent() { InitializeComponent(); ParametersGrid.ItemsSource = _parameters; var isInitialization = false; var cmdSvc = ConfigManager.GetService <IStudioCommandService>(); cmdSvc.Register <StartStrategyCommand>(this, true, cmd => { var error = Strategy.CheckCanStart(false); if (error != null) { new MessageBoxBuilder() .Owner(this) .Caption(LocalizedStrings.Str3577) .Text(error) .Warning() .Show(); return; } try { _parameters.ForEach(p => p.Check()); } catch (Exception excp) { new MessageBoxBuilder() .Owner(this) .Caption(LocalizedStrings.Str3577) .Text(excp.Message) .Warning() .Show(); return; } isInitialization = true; _strategies.Clear(); ResultsPanel.Clear(); Task.Factory.StartNew(() => { EmulationService.Strategies = CreateStrategies().ToEx(GetIterationCount()); EmulationService.StartEmulation(); isInitialization = false; }); }, cmd => EmulationService != null && EmulationService.CanStart && !isInitialization); cmdSvc.Register <StopStrategyCommand>(this, true, cmd => EmulationService.StopEmulation(), cmd => EmulationService != null && EmulationService.CanStop); ResultsPanel.AddContextMenuItem(new Separator()); ResultsPanel.AddContextMenuItem(new MenuItem { Header = LocalizedStrings.Str3578, Command = OpenStrategyCommand, CommandTarget = this }); ResultsPanel.AddContextMenuItem(new MenuItem { Header = LocalizedStrings.Str3579, Command = SetParametersCommand, CommandTarget = this }); }
public StrategyContent() { InitializeComponent(); _controls = new ControlList(); _controls.Loaded += () => { //чтобы команда привязки стратегии отработала корректно, //ее необходимо вызвать когда проинициализированы все Scope //для контролов, что будет только после их загрузки. if (Strategy != null) { RaiseBindStrategy(); //RaiseSelectStrategy(); } ChildsLoaded.SafeInvoke(); if (!_needRaiseChangedOnLoaded) { return; } //первая загрузка шаблона происходит до открытия вкладки //поэтому после того как она будет открыта необходимо сохранить настройки _needRaiseChangedOnLoaded = false; RaiseChangedCommand(); }; _controls.SizeChanged += RaiseChangedCommand; DockSite.WindowClosing += (sender, args) => { //окна могут открываться и закрываться в момент загрузки разметки if (!_suspendChangedEvent) { ((IStudioControl)args.Window.Content).Dispose(); } var contentWindow = args.Window as IContentWindow; if (contentWindow != null) { _controls.Remove(contentWindow); } RaiseChangedCommand(); }; DockSite.WindowOpened += (sender, args) => { var contentWindow = args.Window as IContentWindow; if (contentWindow != null) { _controls.Add(contentWindow); } RaiseChangedCommand(); }; DockSite.WindowStateChanged += (sender, args) => RaiseChangedCommand(); DockSite.WindowDragged += (sender, args) => RaiseChangedCommand(); var cmdSvc = ConfigManager.GetService <IStudioCommandService>(); cmdSvc.Register <ControlChangedCommand>(this, false, cmd => RaiseChangedCommand()); cmdSvc.Register <OpenWindowCommand>(this, true, cmd => OpenControl(cmd.Id, cmd.CtrlType, null, ctrl => { })); cmdSvc.Register <OpenMarketDepthCommand>(this, true, cmd => OpenControl(cmd.Security.Id, typeof(ScalpingMarketDepthControl), cmd.Security, ctrl => { ((ScalpingMarketDepthControl)ctrl).Settings.Security = cmd.Security; })); cmdSvc.Register <AddLogListenerCommand>(this, false, cmd => _logManager.Listeners.Add(cmd.Listener)); cmdSvc.Register <RemoveLogListenerCommand>(this, false, cmd => _logManager.Listeners.Remove(cmd.Listener)); cmdSvc.Register <RequestBindSource>(this, true, cmd => RaiseBindStrategy(cmd.Control)); cmdSvc.Register <LoadLayoutCommand>(this, true, cmd => LoadTemplate(cmd.Layout, true)); cmdSvc.Register <SaveLayoutCommand>(this, true, cmd => cmd.Layout = this.Save().SaveSettingsStorage()); cmdSvc.Register <StartStrategyCommand>(this, true, cmd => { if (EmulationService != null) { var error = Strategy.CheckCanStart(false); if (error != null) { new MessageBoxBuilder() .Owner(this) .Caption(LocalizedStrings.Str3598) .Text(error) .Warning() .Show(); return; } EmulationService.StartEmulation(); } else { new StartStrategyCommand(cmd.Strategy).Process(this); } }); cmdSvc.Register <StopStrategyCommand>(this, true, cmd => { if (EmulationService != null) { EmulationService.StopEmulation(); } else { new StopStrategyCommand(cmd.Strategy).Process(this); } }); }