From c7c94ebe69a1183bb67cc98d66dfa3a7774b6fee Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Fri, 1 Apr 2022 16:22:17 -0400 Subject: [PATCH 1/4] Fixes #2158 add check box disable run --- src/PKSim.Assets/PKSimConstants.cs | 5 +- src/PKSim.CLI.Core/Services/SnapshotRunner.cs | 2 +- .../Snapshots/Services/SnapshotTask.cs | 6 +- .../DTO/Snapshots/LoadFromSnapshotDTO.cs | 11 ++- .../Snapshots/LoadFromSnapshotPresenter.cs | 17 ++-- .../LoadProjectFromSnapshotPresenter.cs | 21 +++-- .../LoadSimulationFromSnapshotPresenter.cs | 13 +-- src/PKSim.Presentation/StartOptions.cs | 2 +- .../Views/Snapshots/ILoadFromSnapshotView.cs | 1 + .../LoadFromSnapshotView.Designer.cs | 85 +++++++++++++------ .../Views/Snapshots/LoadFromSnapshotView.cs | 13 ++- tests/PKSim.Tests/CLI/SnapshotRunnerSpecs.cs | 4 +- .../LoadProjectFromSnapshotPresenterSpecs.cs | 18 +++- 13 files changed, 140 insertions(+), 58 deletions(-) diff --git a/src/PKSim.Assets/PKSimConstants.cs b/src/PKSim.Assets/PKSimConstants.cs index 02057f8e7..44d9c2064 100644 --- a/src/PKSim.Assets/PKSimConstants.cs +++ b/src/PKSim.Assets/PKSimConstants.cs @@ -2588,8 +2588,9 @@ public static string DragFieldMessage(string fieldType) public static string LoadObjectFromSnapshot(string objectType) => $"Load {objectType.ToLowerInvariant()} from snapshot"; - public static string LoadFromSnapshot => "Load Snapshot"; - public static string SelectExpressionProfile => "Select an expression profile"; + public static string LoadFromSnapshot = "Load Snapshot"; + public static string SelectExpressionProfile = "Select an expression profile"; + public static string RunSimulations = "Run Simulations"; public static string NumberOfTemplatesSelectedIs(int number, string templateType) => $"{number} {templateType.PluralizeIf(number).ToLowerInvariant()} selected"; diff --git a/src/PKSim.CLI.Core/Services/SnapshotRunner.cs b/src/PKSim.CLI.Core/Services/SnapshotRunner.cs index 877cb3032..e3004ce6b 100644 --- a/src/PKSim.CLI.Core/Services/SnapshotRunner.cs +++ b/src/PKSim.CLI.Core/Services/SnapshotRunner.cs @@ -102,7 +102,7 @@ private async Task startSnapshotRun(IReadOnlyList fileMaps, Func> LoadModelsFromSnapshotFileAsync(string fileName) where T : class; - Task LoadProjectFromSnapshotFileAsync(string fileName); + Task LoadProjectFromSnapshotFileAsync(string fileName, bool runSimulations = true); Task LoadProjectFromSnapshotAsync(Project snapshot, bool runSimulations); @@ -175,10 +175,10 @@ private async Task loadModelFromSnapshot(object snapshot) return models.FirstOrDefault(); } - public async Task LoadProjectFromSnapshotFileAsync(string fileName) + public async Task LoadProjectFromSnapshotFileAsync(string fileName, bool runSimulations = true) { var projectSnapshot = await LoadSnapshotFromFileAsync(fileName); - var project = await LoadProjectFromSnapshotAsync(projectSnapshot, runSimulations: true); + var project = await LoadProjectFromSnapshotAsync(projectSnapshot, runSimulations); return projectWithUpdatedProperties(project, FileHelper.FileNameFromFileFullPath(fileName)); } diff --git a/src/PKSim.Presentation/DTO/Snapshots/LoadFromSnapshotDTO.cs b/src/PKSim.Presentation/DTO/Snapshots/LoadFromSnapshotDTO.cs index 10cecf6d3..1a5302d3f 100644 --- a/src/PKSim.Presentation/DTO/Snapshots/LoadFromSnapshotDTO.cs +++ b/src/PKSim.Presentation/DTO/Snapshots/LoadFromSnapshotDTO.cs @@ -1,4 +1,5 @@ -using OSPSuite.Core.Domain; +using NPOI.HSSF.Util; +using OSPSuite.Core.Domain; using OSPSuite.Presentation.DTO; using OSPSuite.Utility.Validation; @@ -7,6 +8,8 @@ namespace PKSim.Presentation.DTO.Snapshots public class LoadFromSnapshotDTO : ValidatableDTO { private string _snapshotFile; + //By default, always run simulations + private bool _runSimulations = true; public virtual string SnapshotFile { @@ -14,6 +17,12 @@ public virtual string SnapshotFile set => SetProperty(ref _snapshotFile, value); } + public virtual bool RunSimulations + { + get => _runSimulations; + set => SetProperty(ref _runSimulations, value); + } + public LoadFromSnapshotDTO() { Rules.Add(AllRules.FileExists); diff --git a/src/PKSim.Presentation/Presenters/Snapshots/LoadFromSnapshotPresenter.cs b/src/PKSim.Presentation/Presenters/Snapshots/LoadFromSnapshotPresenter.cs index aa625c21c..c0a08654b 100644 --- a/src/PKSim.Presentation/Presenters/Snapshots/LoadFromSnapshotPresenter.cs +++ b/src/PKSim.Presentation/Presenters/Snapshots/LoadFromSnapshotPresenter.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using OSPSuite.Assets; +using OSPSuite.Core; using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Services; using OSPSuite.Core.Services; @@ -47,6 +48,7 @@ public class LoadFromSnapshotPresenter : AbstractDisposablePresenter _model; public LoadFromSnapshotPresenter( @@ -56,7 +58,8 @@ public LoadFromSnapshotPresenter( IDialogCreator dialogCreator, IObjectTypeResolver objectTypeResolver, IOSPSuiteLogger logger, - IEventPublisher eventPublisher) : base(view) + IEventPublisher eventPublisher, + IStartOptions startOptions) : base(view) { _snapshotTask = snapshotTask; _dialogCreator = dialogCreator; @@ -64,10 +67,12 @@ public LoadFromSnapshotPresenter( _logger = logger; _logPresenter = logPresenter; _eventPublisher = eventPublisher; + _startOptions = startOptions; AddSubPresenters(_logPresenter); _view.Caption = PKSimConstants.UI.LoadObjectFromSnapshot(typeToLoad); _view.AddLogView(_logPresenter.BaseView); _view.BindTo(_loadFromSnapshotDTO); + _view.RunSimulationsSwitchVisible = _startOptions.IsDeveloperMode; } public override bool ShouldClose @@ -119,7 +124,7 @@ public async Task StartAsync() _logPresenter.ClearLog(); _view.EnableButtons(false); _logger.AddInfo(PKSimConstants.Information.LoadingSnapshot(_loadFromSnapshotDTO.SnapshotFile, typeToLoad)); - await Task.Run(() => PerformLoadAsync(_loadFromSnapshotDTO.SnapshotFile)); + await Task.Run(performLoadAsync); _logger.AddInfo(PKSimConstants.Information.SnapshotLoaded(typeToLoad)); } catch (Exception e) @@ -137,10 +142,10 @@ public async Task StartAsync() public string SnapshotFile => _loadFromSnapshotDTO.SnapshotFile; - protected async Task PerformLoadAsync(string snapshotFile) + private async Task performLoadAsync() { ClearModel(); - _model = await LoadModelAsync(snapshotFile); + _model = await LoadModelAsync(_loadFromSnapshotDTO); } protected virtual void ClearModel() @@ -154,9 +159,9 @@ protected virtual void ClearModel(IEnumerable model) /*override if something needs to be done for specific loading case*/ } - protected virtual Task> LoadModelAsync(string snapshotFile) + protected virtual Task> LoadModelAsync(LoadFromSnapshotDTO loadFromSnapshotDTO) { - return _snapshotTask.LoadModelsFromSnapshotFileAsync(snapshotFile); + return _snapshotTask.LoadModelsFromSnapshotFileAsync(loadFromSnapshotDTO.SnapshotFile); } protected override void Cleanup() diff --git a/src/PKSim.Presentation/Presenters/Snapshots/LoadProjectFromSnapshotPresenter.cs b/src/PKSim.Presentation/Presenters/Snapshots/LoadProjectFromSnapshotPresenter.cs index 53a9f96b4..bd1af717c 100644 --- a/src/PKSim.Presentation/Presenters/Snapshots/LoadProjectFromSnapshotPresenter.cs +++ b/src/PKSim.Presentation/Presenters/Snapshots/LoadProjectFromSnapshotPresenter.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using OSPSuite.Core; using OSPSuite.Core.Domain.Services; using OSPSuite.Core.Services; using OSPSuite.Presentation.Presenters; @@ -8,6 +9,7 @@ using PKSim.Core.Model; using PKSim.Core.Services; using PKSim.Core.Snapshots.Services; +using PKSim.Presentation.DTO.Snapshots; using PKSim.Presentation.Views.Snapshots; namespace PKSim.Presentation.Presenters.Snapshots @@ -26,15 +28,16 @@ public class LoadProjectFromSnapshotPresenter : LoadFromSnapshotPresenter> LoadModelAsync(string snapshotFile) + protected override async Task> LoadModelAsync(LoadFromSnapshotDTO loadFromSnapshotDTO) { - var project = await _snapshotTask.LoadProjectFromSnapshotFileAsync(snapshotFile); + var project = await _snapshotTask.LoadProjectFromSnapshotFileAsync(loadFromSnapshotDTO.SnapshotFile, loadFromSnapshotDTO.RunSimulations); _registrationTask.RegisterProject(project); await runQualificationPlans(project); return new[] { project }; diff --git a/src/PKSim.Presentation/Presenters/Snapshots/LoadSimulationFromSnapshotPresenter.cs b/src/PKSim.Presentation/Presenters/Snapshots/LoadSimulationFromSnapshotPresenter.cs index 8c513fec2..52b2b6c10 100644 --- a/src/PKSim.Presentation/Presenters/Snapshots/LoadSimulationFromSnapshotPresenter.cs +++ b/src/PKSim.Presentation/Presenters/Snapshots/LoadSimulationFromSnapshotPresenter.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using OSPSuite.Core; using OSPSuite.Core.Domain.Services; using OSPSuite.Core.Services; using OSPSuite.Presentation.Presenters; @@ -9,6 +10,7 @@ using PKSim.Core.Services; using PKSim.Core.Snapshots.Mappers; using PKSim.Core.Snapshots.Services; +using PKSim.Presentation.DTO.Snapshots; using PKSim.Presentation.Views.Snapshots; namespace PKSim.Presentation.Presenters.Snapshots @@ -36,8 +38,9 @@ public LoadSimulationFromSnapshotPresenter( IOSPSuiteLogger logger, IEventPublisher eventPublisher, SimulationMapper simulationMapper, - IPKSimProjectRetriever projectRetriever - ) : base(view, logPresenter, snapshotTask, dialogCreator, objectTypeResolver, logger, eventPublisher) + IPKSimProjectRetriever projectRetriever, + IStartOptions startOptions + ) : base(view, logPresenter, snapshotTask, dialogCreator, objectTypeResolver, logger, eventPublisher, startOptions) { _simulationMapper = simulationMapper; _projectRetriever = projectRetriever; @@ -49,10 +52,10 @@ public Simulation LoadSimulation() return models?.FirstOrDefault(); } - protected override async Task> LoadModelAsync(string snapshotFile) + protected override async Task> LoadModelAsync(LoadFromSnapshotDTO loadFromSnapshotDTO) { - var snapshots = await _snapshotTask.LoadSnapshotsAsync(snapshotFile); - var simulationContext = new SimulationContext(_projectRetriever.Current, run: true); + var snapshots = await _snapshotTask.LoadSnapshotsAsync(loadFromSnapshotDTO.SnapshotFile); + var simulationContext = new SimulationContext(_projectRetriever.Current, run: loadFromSnapshotDTO.RunSimulations); var tasks = snapshots.Select(x => _simulationMapper.MapToModel(x, simulationContext)); return await Task.WhenAll(tasks); } diff --git a/src/PKSim.Presentation/StartOptions.cs b/src/PKSim.Presentation/StartOptions.cs index da2414858..69d85781d 100644 --- a/src/PKSim.Presentation/StartOptions.cs +++ b/src/PKSim.Presentation/StartOptions.cs @@ -31,7 +31,7 @@ public class StartOptions : IStartOptions /// /// Specifies if the app should be started in developer mode. Default is false /// - public bool IsDeveloperMode { get; private set; } = false; + public bool IsDeveloperMode { get; private set; } /// /// Loading a project or a simulation file diff --git a/src/PKSim.Presentation/Views/Snapshots/ILoadFromSnapshotView.cs b/src/PKSim.Presentation/Views/Snapshots/ILoadFromSnapshotView.cs index b1237b1d7..6210487c8 100644 --- a/src/PKSim.Presentation/Views/Snapshots/ILoadFromSnapshotView.cs +++ b/src/PKSim.Presentation/Views/Snapshots/ILoadFromSnapshotView.cs @@ -9,5 +9,6 @@ public interface ILoadFromSnapshotView : IModalView void AddLogView(IView view); void BindTo(LoadFromSnapshotDTO loadFromSnapshotDTO); void EnableButtons(bool cancelEnabled, bool okEnabled = false, bool startEnabled=false); + bool RunSimulationsSwitchVisible { set; } } } \ No newline at end of file diff --git a/src/PKSim.UI/Views/Snapshots/LoadFromSnapshotView.Designer.cs b/src/PKSim.UI/Views/Snapshots/LoadFromSnapshotView.Designer.cs index 1ff8c9612..ea25cde88 100644 --- a/src/PKSim.UI/Views/Snapshots/LoadFromSnapshotView.Designer.cs +++ b/src/PKSim.UI/Views/Snapshots/LoadFromSnapshotView.Designer.cs @@ -30,14 +30,17 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.layoutControl = new OSPSuite.UI.Controls.UxLayoutControl(); + this.buttonStart = new DevExpress.XtraEditors.SimpleButton(); this.logPanel = new DevExpress.XtraEditors.PanelControl(); this.buttonEditSelectSnapshot = new DevExpress.XtraEditors.ButtonEdit(); this.layoutControlGroup = new DevExpress.XtraLayout.LayoutControlGroup(); this.layoutItemButtonSelectSnapshot = new DevExpress.XtraLayout.LayoutControlItem(); this.layoutItemLogPanel = new DevExpress.XtraLayout.LayoutControlItem(); - this.buttonStart = new DevExpress.XtraEditors.SimpleButton(); this.layoutItemStartButton = new DevExpress.XtraLayout.LayoutControlItem(); this.emptySpaceItem1 = new DevExpress.XtraLayout.EmptySpaceItem(); + this.chkRunSimulations = new DevExpress.XtraEditors.CheckEdit(); + this.layoutItemRunSimulations = new DevExpress.XtraLayout.LayoutControlItem(); + ((System.ComponentModel.ISupportInitialize)(this.tablePanel)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this._errorProvider)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutControl)).BeginInit(); this.layoutControl.SuspendLayout(); @@ -48,11 +51,19 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.layoutItemLogPanel)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutItemStartButton)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chkRunSimulations.Properties)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.layoutItemRunSimulations)).BeginInit(); this.SuspendLayout(); - + // + // tablePanel + // + this.tablePanel.Location = new System.Drawing.Point(0, 581); + this.tablePanel.Size = new System.Drawing.Size(769, 43); // // layoutControl // + this.layoutControl.AllowCustomization = false; + this.layoutControl.Controls.Add(this.chkRunSimulations); this.layoutControl.Controls.Add(this.buttonStart); this.layoutControl.Controls.Add(this.logPanel); this.layoutControl.Controls.Add(this.buttonEditSelectSnapshot); @@ -60,24 +71,33 @@ private void InitializeComponent() this.layoutControl.Location = new System.Drawing.Point(0, 0); this.layoutControl.Name = "layoutControl"; this.layoutControl.Root = this.layoutControlGroup; - this.layoutControl.Size = new System.Drawing.Size(769, 578); + this.layoutControl.Size = new System.Drawing.Size(769, 581); this.layoutControl.TabIndex = 38; this.layoutControl.Text = "layoutControl1"; // + // buttonStart + // + this.buttonStart.Location = new System.Drawing.Point(386, 547); + this.buttonStart.Name = "buttonStart"; + this.buttonStart.Size = new System.Drawing.Size(371, 22); + this.buttonStart.StyleController = this.layoutControl; + this.buttonStart.TabIndex = 6; + this.buttonStart.Text = "buttonStart"; + // // logPanel // - this.logPanel.Location = new System.Drawing.Point(12, 36); + this.logPanel.Location = new System.Drawing.Point(12, 60); this.logPanel.Name = "logPanel"; - this.logPanel.Size = new System.Drawing.Size(745, 504); + this.logPanel.Size = new System.Drawing.Size(745, 483); this.logPanel.TabIndex = 5; // // buttonEditSelectSnapshot // - this.buttonEditSelectSnapshot.Location = new System.Drawing.Point(173, 12); + this.buttonEditSelectSnapshot.Location = new System.Drawing.Point(182, 12); this.buttonEditSelectSnapshot.Name = "buttonEditSelectSnapshot"; this.buttonEditSelectSnapshot.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton()}); - this.buttonEditSelectSnapshot.Size = new System.Drawing.Size(584, 20); + this.buttonEditSelectSnapshot.Size = new System.Drawing.Size(575, 20); this.buttonEditSelectSnapshot.StyleController = this.layoutControl; this.buttonEditSelectSnapshot.TabIndex = 4; // @@ -89,10 +109,10 @@ private void InitializeComponent() this.layoutItemButtonSelectSnapshot, this.layoutItemLogPanel, this.layoutItemStartButton, - this.emptySpaceItem1}); - this.layoutControlGroup.Location = new System.Drawing.Point(0, 0); + this.emptySpaceItem1, + this.layoutItemRunSimulations}); this.layoutControlGroup.Name = "layoutControlGroup"; - this.layoutControlGroup.Size = new System.Drawing.Size(769, 578); + this.layoutControlGroup.Size = new System.Drawing.Size(769, 581); this.layoutControlGroup.TextVisible = false; // // layoutItemButtonSelectSnapshot @@ -103,28 +123,19 @@ private void InitializeComponent() this.layoutItemButtonSelectSnapshot.Size = new System.Drawing.Size(749, 24); this.layoutItemButtonSelectSnapshot.TextSize = new System.Drawing.Size(158, 13); // - // layoutControlItem1 + // layoutItemLogPanel // this.layoutItemLogPanel.Control = this.logPanel; - this.layoutItemLogPanel.Location = new System.Drawing.Point(0, 24); + this.layoutItemLogPanel.Location = new System.Drawing.Point(0, 48); this.layoutItemLogPanel.Name = "layoutItemLogPanel"; - this.layoutItemLogPanel.Size = new System.Drawing.Size(749, 508); + this.layoutItemLogPanel.Size = new System.Drawing.Size(749, 487); this.layoutItemLogPanel.TextSize = new System.Drawing.Size(0, 0); this.layoutItemLogPanel.TextVisible = false; // - // buttonStart - // - this.buttonStart.Location = new System.Drawing.Point(386, 544); - this.buttonStart.Name = "buttonStart"; - this.buttonStart.Size = new System.Drawing.Size(371, 22); - this.buttonStart.StyleController = this.layoutControl; - this.buttonStart.TabIndex = 6; - this.buttonStart.Text = "buttonStart"; - // - // layoutControlItem2 + // layoutItemStartButton // this.layoutItemStartButton.Control = this.buttonStart; - this.layoutItemStartButton.Location = new System.Drawing.Point(374, 532); + this.layoutItemStartButton.Location = new System.Drawing.Point(374, 535); this.layoutItemStartButton.Name = "layoutItemStartButton"; this.layoutItemStartButton.Size = new System.Drawing.Size(375, 26); this.layoutItemStartButton.TextSize = new System.Drawing.Size(0, 0); @@ -133,11 +144,29 @@ private void InitializeComponent() // emptySpaceItem1 // this.emptySpaceItem1.AllowHotTrack = false; - this.emptySpaceItem1.Location = new System.Drawing.Point(0, 532); + this.emptySpaceItem1.Location = new System.Drawing.Point(0, 535); this.emptySpaceItem1.Name = "emptySpaceItem1"; this.emptySpaceItem1.Size = new System.Drawing.Size(374, 26); this.emptySpaceItem1.TextSize = new System.Drawing.Size(0, 0); // + // chkRunSimulations + // + this.chkRunSimulations.Location = new System.Drawing.Point(12, 36); + this.chkRunSimulations.Name = "chkRunSimulations"; + this.chkRunSimulations.Properties.Caption = "chkRunSimulations"; + this.chkRunSimulations.Size = new System.Drawing.Size(745, 20); + this.chkRunSimulations.StyleController = this.layoutControl; + this.chkRunSimulations.TabIndex = 0; + // + // layoutControlItem1 + // + this.layoutItemRunSimulations.Control = this.chkRunSimulations; + this.layoutItemRunSimulations.Location = new System.Drawing.Point(0, 24); + this.layoutItemRunSimulations.Name = "layoutItemRunSimulations"; + this.layoutItemRunSimulations.Size = new System.Drawing.Size(749, 24); + this.layoutItemRunSimulations.TextSize = new System.Drawing.Size(0, 0); + this.layoutItemRunSimulations.TextVisible = false; + // // LoadFromSnapshotView // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -147,7 +176,9 @@ private void InitializeComponent() this.Controls.Add(this.layoutControl); this.Name = "LoadFromSnapshotView"; this.Text = "LoadFromSnapshotView"; + this.Controls.SetChildIndex(this.tablePanel, 0); this.Controls.SetChildIndex(this.layoutControl, 0); + ((System.ComponentModel.ISupportInitialize)(this.tablePanel)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this._errorProvider)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutControl)).EndInit(); this.layoutControl.ResumeLayout(false); @@ -158,6 +189,8 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.layoutItemLogPanel)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutItemStartButton)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chkRunSimulations.Properties)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.layoutItemRunSimulations)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -174,5 +207,7 @@ private void InitializeComponent() private DevExpress.XtraEditors.SimpleButton buttonStart; private DevExpress.XtraLayout.LayoutControlItem layoutItemStartButton; private DevExpress.XtraLayout.EmptySpaceItem emptySpaceItem1; + private DevExpress.XtraEditors.CheckEdit chkRunSimulations; + private DevExpress.XtraLayout.LayoutControlItem layoutItemRunSimulations; } } \ No newline at end of file diff --git a/src/PKSim.UI/Views/Snapshots/LoadFromSnapshotView.cs b/src/PKSim.UI/Views/Snapshots/LoadFromSnapshotView.cs index a2b3bd118..e09527a84 100644 --- a/src/PKSim.UI/Views/Snapshots/LoadFromSnapshotView.cs +++ b/src/PKSim.UI/Views/Snapshots/LoadFromSnapshotView.cs @@ -1,4 +1,5 @@ using System.Windows.Forms; +using DevExpress.XtraLayout.Utils; using OSPSuite.Assets; using OSPSuite.DataBinding; using OSPSuite.DataBinding.DevExpress; @@ -31,9 +32,14 @@ public LoadFromSnapshotView(IShell shell) : base(shell) public override void InitializeBinding() { base.InitializeBinding(); + _screenBinder.Bind(x => x.SnapshotFile) .To(buttonEditSelectSnapshot); + _screenBinder.Bind(x => x.RunSimulations) + .To(chkRunSimulations) + .WithCaption(PKSimConstants.UI.RunSimulations); + buttonEditSelectSnapshot.ButtonClick += (o, e) => OnEvent(() => _presenter.SelectFile()); buttonStart.Click += (o, e) => OnEvent(() => _presenter.StartAsync()); @@ -62,6 +68,11 @@ public void EnableButtons(bool cancelEnabled, bool okEnabled = false, bool start buttonStart.Enabled = startEnabled; } + public bool RunSimulationsSwitchVisible + { + set => layoutItemRunSimulations.Visibility = LayoutVisibilityConvertor.FromBoolean(value); + } + protected override void SetOkButtonEnable() { base.SetOkButtonEnable(); @@ -73,7 +84,7 @@ protected override void SetOkButtonEnable() public override void InitializeResources() { base.InitializeResources(); - layoutItemStartButton.AdjustLongButtonSize(); + layoutItemStartButton.AdjustLargeButtonSize(); buttonStart.InitWithImage(ApplicationIcons.Run, PKSimConstants.UI.StartImport); layoutItemButtonSelectSnapshot.Text = PKSimConstants.UI.SnapshotFile.FormatForLabel(); ApplicationIcon = ApplicationIcons.Snapshot; diff --git a/tests/PKSim.Tests/CLI/SnapshotRunnerSpecs.cs b/tests/PKSim.Tests/CLI/SnapshotRunnerSpecs.cs index e3446b0d9..46f6e5cea 100644 --- a/tests/PKSim.Tests/CLI/SnapshotRunnerSpecs.cs +++ b/tests/PKSim.Tests/CLI/SnapshotRunnerSpecs.cs @@ -80,7 +80,7 @@ protected override Task Because() [Observation] public void should_load_the_snapshot_from_file() { - A.CallTo(() => _snapshotTask.LoadProjectFromSnapshotFileAsync(_snapshotFile)).MustHaveHappened(); + A.CallTo(() => _snapshotTask.LoadProjectFromSnapshotFileAsync(_snapshotFile, true)).MustHaveHappened(); } [Observation] @@ -162,7 +162,7 @@ protected override Task Because() [Observation] public void should_load_the_snapshot_from_file() { - A.CallTo(() => _snapshotTask.LoadProjectFromSnapshotFileAsync(_snapshotFile)).MustHaveHappened(); + A.CallTo(() => _snapshotTask.LoadProjectFromSnapshotFileAsync(_snapshotFile, true)).MustHaveHappened(); } [Observation] diff --git a/tests/PKSim.Tests/Presentation/LoadProjectFromSnapshotPresenterSpecs.cs b/tests/PKSim.Tests/Presentation/LoadProjectFromSnapshotPresenterSpecs.cs index 4ceb2a69e..c723cc91d 100644 --- a/tests/PKSim.Tests/Presentation/LoadProjectFromSnapshotPresenterSpecs.cs +++ b/tests/PKSim.Tests/Presentation/LoadProjectFromSnapshotPresenterSpecs.cs @@ -1,6 +1,7 @@ using FakeItEasy; using OSPSuite.BDDHelper; using OSPSuite.BDDHelper.Extensions; +using OSPSuite.Core; using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Services; using OSPSuite.Core.Services; @@ -25,6 +26,7 @@ public abstract class concern_for_LoadProjectFromSnapshotPresenter : ContextSpec protected ILogPresenter _logPresenter; protected IRegistrationTask _registrationTask; protected IQualiticationPlanRunner _qualificationPlanRunner; + private IStartOptions _startOptions; protected override void Context() { @@ -37,7 +39,19 @@ protected override void Context() _logPresenter = A.Fake(); _registrationTask = A.Fake(); _qualificationPlanRunner = A.Fake(); - sut = new LoadProjectFromSnapshotPresenter(_view, _logPresenter, _snapshotTask, _dialogCreator, _objectTypeResolver, _logger, _eventPublisher, _qualificationPlanRunner, _registrationTask); + _startOptions= A.Fake(); + + sut = new LoadProjectFromSnapshotPresenter( + _view, + _logPresenter, + _snapshotTask, + _dialogCreator, + _objectTypeResolver, + _logger, + _eventPublisher, + _qualificationPlanRunner, + _registrationTask, + _startOptions); } } @@ -55,7 +69,7 @@ protected override void Context() _qualificationPlan = new QualificationPlan(); _newProject.AddQualificationPlan(_qualificationPlan); A.CallTo(_dialogCreator).WithReturnType().Returns(_fileName); - A.CallTo(() => _snapshotTask.LoadProjectFromSnapshotFileAsync(_fileName)).Returns(_newProject); + A.CallTo(() => _snapshotTask.LoadProjectFromSnapshotFileAsync(_fileName, true)).Returns(_newProject); A.CallTo(() => _view.Display()) .Invokes(x => sut.StartAsync().Wait()); } From 125b951e9be336035fe040f0c2cc3d38e5746608 Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Fri, 1 Apr 2022 16:23:34 -0400 Subject: [PATCH 2/4] Fixes #2158 add check box disable run --- src/PKSim.CLI.Core/Services/SnapshotRunner.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/PKSim.CLI.Core/Services/SnapshotRunner.cs b/src/PKSim.CLI.Core/Services/SnapshotRunner.cs index e3004ce6b..f8179b8ae 100644 --- a/src/PKSim.CLI.Core/Services/SnapshotRunner.cs +++ b/src/PKSim.CLI.Core/Services/SnapshotRunner.cs @@ -40,8 +40,6 @@ public class SnapshotRunner : IBatchRunner //For testing purposes only public Func AllFilesFrom { get; set; } - - public SnapshotRunner( ICoreWorkspace workspace, ISnapshotTask snapshotTask, @@ -53,7 +51,7 @@ public SnapshotRunner( _workspacePersistor = workspacePersistor; _logger = logger; AllFilesFrom = allFilesFrom; - } + } public async Task RunBatchAsync(SnapshotRunOptions runOptions) { @@ -93,6 +91,7 @@ private async Task startSnapshotRun(IReadOnlyList fileMaps, Func fileMaps, Func Date: Fri, 1 Apr 2022 16:24:49 -0400 Subject: [PATCH 3/4] Use resharper suggestions --- .../Presenters/Snapshots/LoadFromSnapshotPresenter.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/PKSim.Presentation/Presenters/Snapshots/LoadFromSnapshotPresenter.cs b/src/PKSim.Presentation/Presenters/Snapshots/LoadFromSnapshotPresenter.cs index c0a08654b..6916fb927 100644 --- a/src/PKSim.Presentation/Presenters/Snapshots/LoadFromSnapshotPresenter.cs +++ b/src/PKSim.Presentation/Presenters/Snapshots/LoadFromSnapshotPresenter.cs @@ -48,7 +48,6 @@ public class LoadFromSnapshotPresenter : AbstractDisposablePresenter _model; public LoadFromSnapshotPresenter( @@ -67,12 +66,11 @@ public LoadFromSnapshotPresenter( _logger = logger; _logPresenter = logPresenter; _eventPublisher = eventPublisher; - _startOptions = startOptions; AddSubPresenters(_logPresenter); _view.Caption = PKSimConstants.UI.LoadObjectFromSnapshot(typeToLoad); _view.AddLogView(_logPresenter.BaseView); _view.BindTo(_loadFromSnapshotDTO); - _view.RunSimulationsSwitchVisible = _startOptions.IsDeveloperMode; + _view.RunSimulationsSwitchVisible = startOptions.IsDeveloperMode; } public override bool ShouldClose From 9272d589feddb3c2fb4c96efddeabe61a9368343 Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Fri, 1 Apr 2022 16:27:53 -0400 Subject: [PATCH 4/4] Use resharper suggestions --- .../Presentation/LoadFromSnapshotPresenterSpecs.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/PKSim.Tests/Presentation/LoadFromSnapshotPresenterSpecs.cs b/tests/PKSim.Tests/Presentation/LoadFromSnapshotPresenterSpecs.cs index 38db63814..bf9bbb809 100644 --- a/tests/PKSim.Tests/Presentation/LoadFromSnapshotPresenterSpecs.cs +++ b/tests/PKSim.Tests/Presentation/LoadFromSnapshotPresenterSpecs.cs @@ -5,6 +5,7 @@ using OSPSuite.Assets; using OSPSuite.BDDHelper; using OSPSuite.BDDHelper.Extensions; +using OSPSuite.Core; using OSPSuite.Core.Domain.Services; using OSPSuite.Core.Services; using OSPSuite.Presentation.Presenters; @@ -29,6 +30,7 @@ public abstract class concern_for_LoadFromSnapshotPresenter : ContextSpecificati protected ILogPresenter _logPresenter; protected LoadFromSnapshotDTO _loadFromSnapshotDTO; protected string _objectType = "Ind"; + protected IStartOptions _startOptions; protected override void Context() { @@ -39,6 +41,7 @@ protected override void Context() _logger = A.Fake(); _eventPublisher = A.Fake(); _logPresenter = A.Fake(); + _startOptions= A.Fake(); A.CallTo(() => _view.BindTo(A._)) .Invokes(x => _loadFromSnapshotDTO = x.GetArgument(0)); @@ -46,7 +49,7 @@ protected override void Context() A.CallTo(() => _logPresenter.CanClose).Returns(true); A.CallTo(() => _objectTypeResolver.TypeFor()).Returns(_objectType); - sut = new LoadFromSnapshotPresenter(_view, _logPresenter, _snapshotTask, _dialogCreator, _objectTypeResolver, _logger, _eventPublisher); + sut = new LoadFromSnapshotPresenter(_view, _logPresenter, _snapshotTask, _dialogCreator, _objectTypeResolver, _logger, _eventPublisher, _startOptions); } }