Exemplo n.º 1
0
        public void Clone(Simulation simulationToClone)
        {
            if (_buildingBlockInSimulationManager.StatusFor(simulationToClone) != BuildingBlockStatus.Green)
            {
                throw new PKSimException(PKSimConstants.Error.SimulationCloneOnlyAvailableWhenBuildingBlocksAreUptodate);
            }

            _buildingBlockTask.Load(simulationToClone);

            using (var presenter = _applicationController.Start <ICloneSimulationPresenter>())
            {
                var cloneCommand = presenter.CloneSimulation(simulationToClone);
                //User cancel action. return
                if (cloneCommand.IsEmpty())
                {
                    return;
                }

                var clone = presenter.Simulation;

                _simulationResultsTask.CloneResults(simulationToClone, clone);
                clone.Creation.AsCloneOf(simulationToClone);
                _simulationSettingsRetriever.SynchronizeSettingsIn(clone);

                var addCommand = new AddBuildingBlockToProjectCommand(clone, _executionContext).Run(_executionContext);
                addCommand.Description = PKSimConstants.Command.CloneEntity(PKSimConstants.ObjectTypes.Simulation, simulationToClone.Name, clone.Name);
                _buildingBlockTask.AddCommandToHistory(addCommand);

                //after clone => we go in edit mode
                _buildingBlockTask.Edit(clone);
            }
        }
        public void Clone(Simulation simulationToClone)
        {
            if (_buildingBlockInProjectManager.StatusFor(simulationToClone) != BuildingBlockStatus.Green)
            {
                throw new PKSimException(PKSimConstants.Error.SimulationCloneOnlyAvailableWhenBuildingBlocksAreUptodate);
            }

            _buildingBlockTask.Load(simulationToClone);

            using (var presenter = _applicationController.Start <ICloneSimulationPresenter>())
            {
                var cloneCommand = presenter.CloneSimulation(simulationToClone);
                //User cancel action. return
                if (cloneCommand.IsEmpty())
                {
                    return;
                }

                var clone = presenter.Simulation;

                _simulationResultsTask.CloneResults(simulationToClone, clone);

                // The simulation must be renamed after results are added to the simulation
                _renameBuildingBlockTask.RenameSimulation(clone, presenter.CloneName);

                clone.Creation.AsCloneOf(simulationToClone);
                _simulationSettingsRetriever.SynchronizeSettingsIn(clone);

                var addCommand = _buildingBlockTask.AddToProject(clone, editBuildingBlock: true, addToHistory: false);
                addCommand.Description = PKSimConstants.Command.CloneEntity(PKSimConstants.ObjectTypes.Simulation, simulationToClone.Name, clone.Name);
                _buildingBlockTask.AddCommandToHistory(addCommand);
            }
        }
Exemplo n.º 3
0
        private void configure(Simulation simulationToConfigure, Func <IConfigureSimulationPresenter, IPKSimCommand> configureAction)
        {
            _buildingBlockTask.Load(simulationToConfigure);
            using (var presenter = _applicationController.Start <IConfigureSimulationPresenter>())
            {
                var activeSubject    = _activeSubjectRetriever.Active <IPKSimBuildingBlock>();
                var configureCommand = configureAction(presenter);

                //User cancel action. return
                if (configureCommand.IsEmpty())
                {
                    return;
                }

                //Before swapping simulation=>update results and charts information from the original simulation
                var simulation = presenter.Simulation;
                _simulationResultsTask.CopyResults(simulationToConfigure, simulation);
                _simulationSettingsRetriever.SynchronizeSettingsIn(simulation);

                //We have the same simulation=> we should update the id
                simulation.Id = simulationToConfigure.Id;
                _parameterIdUpdater.UpdateSimulationId(simulation);

                //was the presenter open for the simulation? if yes
                var presenterWasOpen = _applicationController.HasPresenterOpenedFor(simulationToConfigure);
                simulation.Creation.CreationMode = CreationMode.Configure;
                var swapSimulationCommand = new SwapSimulationCommand(simulationToConfigure, simulation, _executionContext).Run(_executionContext);

                swapSimulationCommand.ReplaceNameTemplateWithName(simulation.Name);
                swapSimulationCommand.ReplaceTypeTemplateWithType(PKSimConstants.ObjectTypes.Simulation);

                _buildingBlockTask.AddCommandToHistory(swapSimulationCommand);

                //no active presenter: nothing to do
                if (activeSubject == null)
                {
                    return;
                }

                //presenter was not open, nothing to do
                if (!presenterWasOpen)
                {
                    return;
                }

                //edit the simulation back, since it was edited
                _buildingBlockTask.Edit(simulation);

                //now, was the simulation the active presenter? if no, we need to active the other presenter
                if (activeSubject != simulationToConfigure)
                {
                    _buildingBlockTask.Edit(activeSubject);
                }
            }
        }