예제 #1
0
 protected override void Context()
 {
     CreateDimensionFactory();
     sut         = new DataTableToImportQuantityDTOMapperForSimulations(_dimensionFactory);
     _simulation = A.Fake <IMoBiSimulation>();
     _dataTable  = new DataTableProvider().ImportTables();
 }
        protected override void Context()
        {
            _simulation                = new MoBiSimulation();
            _buildingBlock             = new MoleculeBuildingBlock();
            _formulaParameter          = new Parameter().WithFormula(new ExplicitFormula()).WithName("formula");
            _formulaParameter.Value    = 9;
            _constantParameter         = new Parameter().WithFormula(new ConstantFormula(1.0)).WithName("constant");
            _unaffectedParameter       = new Parameter().WithFormula(new ConstantFormula(1.0)).WithName("unaffected");
            _unaffectedParameter.Value = 5.0;
            _constantParameter.Value   = 9;
            _simulation.Model          = new Model {
                Root = new Container {
                    _formulaParameter, _constantParameter, _unaffectedParameter
                }
            };
            _context = A.Fake <IMoBiContext>();

            sut = new ResetFixedConstantParametersToDefaultInSimulationCommand <MoleculeBuildingBlock>(_simulation, _buildingBlock);

            _affectedBuildingBlockRetriever = A.Fake <IAffectedBuildingBlockRetriever>();
            _formulaTask = A.Fake <IMoBiFormulaTask>();

            A.CallTo(() => _formulaTask.CreateNewFormula <ConstantFormula>(A <IDimension> ._)).Returns(new ConstantFormula());

            A.CallTo(() => _context.Resolve <IAffectedBuildingBlockRetriever>()).Returns(_affectedBuildingBlockRetriever);
            A.CallTo(() => _context.Resolve <IMoBiFormulaTask>()).Returns(_formulaTask);
            var buildingBlockInfo = new MoleculesInfo {
                BuildingBlock = _buildingBlock
            };

            A.CallTo(() => _affectedBuildingBlockRetriever.RetrieveFor(_constantParameter, _simulation)).Returns(buildingBlockInfo);
            A.CallTo(() => _affectedBuildingBlockRetriever.RetrieveFor(_formulaParameter, _simulation)).Returns(buildingBlockInfo);
        }
예제 #3
0
 protected override void Context()
 {
     base.Context();
     _simulation    = A.Fake <IMoBiSimulation>();
     _buildingBlock = A.Fake <IBuildingBlock>();
     sut.Initialize(_buildingBlock, _simulation);
 }
예제 #4
0
        private void synchronizeFixedParameterValues(IMoBiSimulation simulationToUpdate, PathCache <IQuantity> fixedValueQuantities, IBuildingBlock templateBuildingBlock)
        {
            var currentQuantities = new PathCache <IQuantity>(_entityPathResolver);

            currentQuantities.AddRange(simulationToUpdate.Model.Root.GetAllChildren <IQuantity>());

            foreach (var fixedValueQuantity in fixedValueQuantities.KeyValues)
            {
                //quantity does not exist anymore after update. Nothing to do
                var simulationQuantity = currentQuantities[fixedValueQuantity.Key];
                if (simulationQuantity == null)
                {
                    continue;
                }

                //building block corresponding to quantity could not be found. That should never happen
                var affectedBuildingBlock = _affectedBuildingBlockRetriever.RetrieveFor(simulationQuantity, simulationToUpdate);
                if (affectedBuildingBlock?.UntypedTemplateBuildingBlock == null)
                {
                    continue;
                }

                //The quantity previously fixed is part of the template building block. We should not reset the changes
                if (Equals(affectedBuildingBlock.UntypedTemplateBuildingBlock, templateBuildingBlock))
                {
                    continue;
                }

                synchronizeQuantities(fixedValueQuantity.Value, simulationQuantity);
            }
        }
        protected IMoBiCommand CreateCommitCommand(IMoBiSimulation simulation, IBuildingBlock templateBuildingBlock)
        {
            var typedTemplateBuildingBlock       = templateBuildingBlock.DowncastTo <T>();
            var cloneOfBuildingBlockInSimulation = _cloneManager.CloneBuildingBlock(_buildingBlockRetriever(simulation.BuildConfiguration));

            return(new UpdateTemplateBuildingBlockFromSimulationBuildingBlockCommand <T>(typedTemplateBuildingBlock, cloneOfBuildingBlockInSimulation, simulation));
        }
        protected override void Context()
        {
            _view = A.Fake <ICreateSimulationView>();
            _subPresenterManager           = A.Fake <ISubPresenterItemManager <ISimulationItemPresenter> >();
            _buildConfigurationPresenter   = _subPresenterManager.CreateFake(SimulationItems.BuildConfiguration);
            _moleculeStartValuesPresenter  = _subPresenterManager.CreateFake(SimulationItems.MoleculeStartValues);
            _parameterStartValuesPresenter = _subPresenterManager.CreateFake(SimulationItems.ParameterStartValues);
            _finalActionPresenter          = _subPresenterManager.CreateFake(SimulationItems.FinalOptions);

            A.CallTo(() => _subPresenterManager.AllSubPresenters).Returns(new ISimulationItemPresenter[] { _buildConfigurationPresenter, _moleculeStartValuesPresenter, _parameterStartValuesPresenter, _finalActionPresenter });
            _context          = A.Fake <IMoBiContext>();
            _modelConstructor = A.Fake <IModelConstructor>();
            _dialogCreator    = A.Fake <IDialogCreator>();
            A.CallTo(() => _modelConstructor.CreateModelFrom(A <IBuildConfiguration> ._, A <string> ._)).Returns(A.Fake <CreationResult>());


            _validationVisitor = A.Fake <IDimensionValidator>();
            _userSettings      = A.Fake <IUserSettings>();
            _userSettings.CheckCircularReference = true;
            _simulationFactory         = A.Fake <ISimulationFactory>();
            _buildConfigurationFactory = A.Fake <IBuildConfigurationFactory>();
            _heavyWorkManager          = new HeavyWorkManagerForSpecs();
            _forbiddenNameRetriever    = A.Fake <IForbiddenNamesRetriever>();
            sut = new CreateSimulationPresenter(_view, _context, _modelConstructor, _validationVisitor,
                                                _simulationFactory, _buildConfigurationFactory, _heavyWorkManager, _subPresenterManager, _dialogCreator,
                                                _forbiddenNameRetriever, _userSettings);

            _simulation = A.Fake <IMoBiSimulation>();
            A.CallTo(() => _simulationFactory.Create()).Returns(_simulation);
            _buildConfiguration = createBuildConfiguration();
            A.CallTo(() => _simulation.MoBiBuildConfiguration).Returns(_buildConfiguration);
            A.CallTo(() => _moleculeStartValuesPresenter.StartValues).Returns(A.Fake <IMoleculeStartValuesBuildingBlock>().WithId(_useId));
            A.CallTo(() => _parameterStartValuesPresenter.StartValues).Returns(A.Fake <IParameterStartValuesBuildingBlock>().WithId(_useId));
        }
예제 #7
0
        protected override void Context()
        {
            base.Context();
            _simulationToUpdate    = A.Fake <IMoBiSimulation>();
            _templateBuildingBlock = A.Fake <IBuildingBlock>();

            var rootContainer = createRootContainer();

            _simulationToUpdate.Model.Root = rootContainer;

            _originalParameterFixedNotBelongingToTemplate       = rootContainer.Parameter("P1");
            _originalParameterFixedNotBelongingToTemplate.Value = 5;

            _originalParameterFixedUpdatedByTemplate       = rootContainer.Parameter("P2");
            _originalParameterFixedUpdatedByTemplate.Value = 8;


            _buildingBlockInfoTemplate = A.Fake <IBuildingBlockInfo>();
            A.CallTo(() => _buildingBlockInfoTemplate.UntypedTemplateBuildingBlock).Returns(_templateBuildingBlock);

            //simulates the update command
            var container = createRootContainer();

            _updatedParameterFixedNotBelongingToTemplate = container.Parameter(_originalParameterFixedNotBelongingToTemplate.Name);
            _updatedParameterFixedUpdatedByTemplate      = container.Parameter(_originalParameterFixedUpdatedByTemplate.Name);

            A.CallTo(() => _affectedBuildingBlockRetriever.RetrieveFor(_updatedParameterFixedUpdatedByTemplate, _simulationToUpdate)).Returns(_buildingBlockInfoTemplate);
            A.CallTo(() => _affectedBuildingBlockRetriever.RetrieveFor(_updatedParameterFixedNotBelongingToTemplate, _simulationToUpdate)).Returns(A.Fake <IBuildingBlockInfo>());

            A.CallTo(() => _simulationToUpdate.Update(A <IMoBiBuildConfiguration> ._, A <IModel> ._)).Invokes(x => { _simulationToUpdate.Model.Root = container; });
        }
 protected override void ClearReferences()
 {
     _simulation  = null;
     _formulaTask = null;
     _affectedBuildingBlockRetriever = null;
     _buildingBlockFromSimulation    = null;
 }
 protected override void Context()
 {
     base.Context();
     _simulation = new MoBiSimulation();
     A.CallTo(() => _relatedItemSerializer.Deserialize(_relatedItem)).Returns(_simulation);
     A.CallTo(() => _simulationLoader.AddSimulationToProject(_simulation)).Returns(new MoBiMacroCommand());
 }
예제 #10
0
        public IMoBiCommand CreateBuildConfigurationBaseOn(IMoBiSimulation simulation, IBuildingBlock templateBuildingBlock)
        {
            //we create a build configuration where all current building block are referencing template building blocks
            BuildConfiguration = _buildConfigurationFactory.CreateFromReferencesUsedIn(simulation.MoBiBuildConfiguration, templateBuildingBlock);
            var tmpSimulation = new MoBiSimulation()
            {
                DiagramManager     = _diagramManagerFactory.Create <ISimulationDiagramManager>(),
                BuildConfiguration = BuildConfiguration,
                Creation           = simulation.Creation,
                Name = simulation.Name,
            };

            edit(tmpSimulation);
            _view.Caption = AppConstants.Captions.ConfigureSimulation(simulation.Name);
            _view.Display();
            if (_view.Canceled)
            {
                return(new MoBiEmptyCommand());
            }

            //Set the selected MSV AND PSV as per user inputs
            UpdateStartValueInfo <IMoleculeStartValuesBuildingBlock, IMoleculeStartValue>(BuildConfiguration.MoleculeStartValuesInfo, SelectedMoleculeStartValues);
            UpdateStartValueInfo <IParameterStartValuesBuildingBlock, IParameterStartValue>(BuildConfiguration.ParameterStartValuesInfo, SelectedParameterStartValues);


            return(_commands);
        }
예제 #11
0
        private ICommand <IMoBiContext> updateSimulation(
            IMoBiSimulation simulationToUpdate,
            IMoBiBuildConfiguration buildConfigurationReferencingTemplates,
            IMoBiCommand configurationCommands,
            IBuildingBlock templateBuildingBlock       = null,
            PathCache <IQuantity> fixedValueQuantities = null)
        {
            //create model using referencing templates
            var model = createModelAndValidate(simulationToUpdate.Model.Name, buildConfigurationReferencingTemplates);

            var simulationBuildConfiguration = createBuildConfigurationToUseInSimulation(buildConfigurationReferencingTemplates);

            var updateSimulationCommand = templateBuildingBlock == null
            ? // is null when we a simulation is being configured. Otherwise this is the template building block to user
                                          new UpdateSimulationCommand(simulationToUpdate, model, simulationBuildConfiguration)
            : new UpdateSimulationCommand(simulationToUpdate, model, simulationBuildConfiguration, templateBuildingBlock);

            updateSimulationCommand.Run(_context);

            synchronizeFixedParameterValues(simulationToUpdate, templateBuildingBlock, fixedValueQuantities);

            var macro = new MoBiMacroCommand
            {
                Description = updateSimulationCommand.Description,
                CommandType = updateSimulationCommand.CommandType,
                ObjectType  = updateSimulationCommand.ObjectType
            };

            macro.Add(configurationCommands);
            macro.Add(updateSimulationCommand);
            return(macro);
        }
예제 #12
0
        public ICommand UpdateSimulationFrom(IMoBiSimulation simulationToUpdate, IBuildingBlock templateBuildingBlock)
        {
            IMoBiBuildConfiguration buildConfigurationReferencingTemplate;
            IMoBiCommand            configurationCommands = null;
            var fixedValueQuantities = new PathCache <IQuantity>(_entityPathResolver);

            if (triggersReconfiguration(templateBuildingBlock))
            {
                using (var presenter = _applicationController.Start <IConfigureSimulationPresenter>())
                {
                    configurationCommands = presenter.CreateBuildConfigurationBaseOn(simulationToUpdate, templateBuildingBlock);
                    if (configurationCommands.IsEmpty())
                    {
                        return(new MoBiEmptyCommand());
                    }

                    buildConfigurationReferencingTemplate = presenter.BuildConfiguration;
                }
            }
            else
            {
                buildConfigurationReferencingTemplate = createBuildConfigurationUsingTemplates(simulationToUpdate, templateBuildingBlock);
                fixedValueQuantities.AddRange(simulationToUpdate.Model.Root.GetAllChildren <IQuantity>(x => x.IsFixedValue));
            }

            return(updateSimulation(simulationToUpdate, buildConfigurationReferencingTemplate, configurationCommands, templateBuildingBlock, fixedValueQuantities));
        }
예제 #13
0
 public OutputSelections OutputSelectionsFor(IMoBiSimulation simulation)
 {
     using (var presenter = _applicationController.Start <IOutputSelectionsPresenter>())
     {
         return(presenter.StartSelection(simulation));
     }
 }
예제 #14
0
 private static MoBiMacroCommand createLoadCommand(IMoBiSimulation simulation)
 {
     return(new MoBiMacroCommand
     {
         Description = AppConstants.Commands.AddToProjectDescription("PK-Sim Simulation", simulation.Name)
     });
 }
 public RemoveSimulationCommand(IMoBiSimulation simulation)
 {
     _simulation = simulation;
     ObjectType  = ObjectTypes.Simulation;
     CommandType = AppConstants.Commands.DeleteCommand;
     Description = AppConstants.Commands.RemoveFromProjectDescription(ObjectType, simulation.Name);
 }
예제 #16
0
        private static Cache <string, string> getEntityIdCache(IMoBiSimulation simulationToUpdate)
        {
            var idCache = new Cache <string, string>();

            simulationToUpdate.Model.Root.GetAllChildren <IEntity>().Each(x => idCache.Add(x.EntityPath(), x.Id));
            return(idCache);
        }
예제 #17
0
        protected override void Context()
        {
            base.Context();
            _project                      = A.Fake <IMoBiProject>();
            _simulationTransfer           = A.Fake <SimulationTransfer>();
            _simulationTransfer.Favorites = new Favorites {
                "Fav1", "Fav2"
            };
            _simulation = A.Fake <IMoBiSimulation>();
            _simulationTransfer.Simulation = _simulation;
            _newBuildingBlock      = A.Fake <IPassiveTransportBuildingBlock>();
            _existingBuildingBlock = A.Fake <IMoBiReactionBuildingBlock>().WithId("Existing");
            _existingBBInfo        = new ReactionBuildingBlockInfo()
            {
                BuildingBlock = _existingBuildingBlock, TemplateBuildingBlockId = "Existing"
            };
            _newBBInfo = new PassiveTransportBuildingBlockInfo()
            {
                BuildingBlock = _newBuildingBlock, TemplateBuildingBlockId = "New"
            };

            A.CallTo(() => _project.ReactionBlockCollection).Returns(new[] { _existingBuildingBlock });
            var moBiBuildConfiguration = A.Fake <IMoBiBuildConfiguration>();

            A.CallTo(() => _simulation.MoBiBuildConfiguration).Returns(moBiBuildConfiguration);
            A.CallTo(() => moBiBuildConfiguration.AllBuildingBlockInfos()).Returns(new IBuildingBlockInfo[] { _existingBBInfo, _newBBInfo });
            moBiBuildConfiguration.ReactionsInfo         = _existingBBInfo;
            moBiBuildConfiguration.PassiveTransportsInfo = _newBBInfo;
            A.CallTo(() => _dialogCreator.AskForFileToOpen(AppConstants.Dialog.LoadSimulation, Constants.Filter.PKML_FILE_FILTER, Constants.DirectoryKey.MODEL_PART, null, null)).Returns("File");
            A.CallTo(() => _serializationTask.Load <SimulationTransfer>(A <string> ._, A <bool> ._)).Returns(_simulationTransfer);
            A.CallTo(() => _context.CurrentProject).Returns(_project);
            A.CallTo(() => _nameCorrector.CorrectName(A <IEnumerable <IPassiveTransportBuildingBlock> > ._, _newBuildingBlock)).Returns(true);
        }
 public CommitSimulationChangesToBuildingBlockUICommand Initialize(IBuildingBlock templateBuildingBlock, IMoBiSimulation simulation)
 {
     _templateBuildingBlock = templateBuildingBlock;
     _simulation            = simulation;
     _commitTask            = _commitTaskRetriever.TaskFor(templateBuildingBlock);
     return(this);
 }
예제 #19
0
        private void startSimulationRun(IMoBiSimulation simulation)
        {
            _simulation = simulation;
            _context.PublishEvent(new SimulationRunStartedEvent());
            _context.PublishEvent(new ProgressInitEvent(100, AppConstants.SimulationRun));
            _simModelManager = _simModelManagerFactory.Create();

            try
            {
                addEvents();
                updatePersistableFor(simulation);
                var results = _simModelManager.RunSimulation(_simulation);
                _simulation.HasChanged = true;
                showWarningsIfAny(results);

                if (results.Success)
                {
                    _displayUnitUpdater.UpdateDisplayUnitsIn(results.Results);
                    copyResultsToSimulation(results, _simulation);
                }

                addCommand(getSimulationResultLabel(results));
            }
            finally
            {
                removeEvents();
                _context.PublishEvent(new SimulationRunFinishedEvent(_simulation));
                _simulation = null;
            }
        }
예제 #20
0
        public void Compute(IMoBiSimulation simulation)
        {
            var buildConfiguration = _buildConfigurationFactory.CreateFromReferencesUsedIn(simulation.MoBiBuildConfiguration);

            buildConfiguration.ShowProgress = false;

            _logger.AddDebug("Creating new simulation from loaded building blocks");
            var results = _modelConstructor.CreateModelFrom(buildConfiguration, "BatchRun");

            if (results.IsInvalid)
            {
                _logger.AddWarning(results.ValidationResult.Messages.SelectMany(x => x.Details).ToString());
            }

            var newSimulation = new MoBiSimulation
            {
                BuildConfiguration = buildConfiguration,
                Model = results.Model,
                Id    = "Sim"
            };

            _context.Register(newSimulation);
            _logger.AddDebug("Running simulation");
            _simModelManager.RunSimulation(newSimulation);
        }
예제 #21
0
 private void updateSimulationTo313(IMoBiSimulation sim)
 {
     _modelUpdater.UpdateModel(sim.Model);
     _spatialStructureUpdater.UpdateSpatialStructre((IMoBiSpatialStructure)sim.MoBiBuildConfiguration.SpatialStructure);
     _parameterStartValuesUpdater.UpdateParameterStartvalues(sim.MoBiBuildConfiguration.ParameterStartValues, sim);
     sim.HasChanged = true;
 }
예제 #22
0
 protected override void Context()
 {
     base.Context();
     _simulation = A.Fake <IMoBiSimulation>();
     _simulationRunFinishedEvent = new SimulationRunFinishedEvent(_simulation);
     sut.Edit(_simulation);
     A.CallTo(() => _view.ShowsResults).Returns(false);
 }
예제 #23
0
 protected override void Context()
 {
     base.Context();
     _simulation = A.Fake <IMoBiSimulation>();
     sut.Edit(_simulation);
     _favoritesView = A.Fake <IEditParameterListView>();
     A.CallTo(() => _editFavoritePresenter.BaseView).Returns(_favoritesView);
 }
        public ICommand AddOuputIntervalTo(ISimulationSettings simulationSettings, IMoBiSimulation simulation)
        {
            var schema   = simulationSettings.OutputSchema;
            var interval = _outputIntervalFactory.CreateDefault();

            interval.Name = _containerTask.CreateUniqueName(schema, interval.Name);
            return(getAddCommand(schema, interval, simulationSettings, simulation).Run(_context));
        }
예제 #25
0
 public AddSimulationCommand(IMoBiSimulation simulation)
 {
     _simulation   = simulation;
     _simulationId = _simulation.Id;
     ObjectType    = ObjectTypes.Simulation;
     CommandType   = AppConstants.Commands.AddCommand;
     Description   = AppConstants.Commands.AddToProjectDescription(ObjectType, simulation.Name);
 }
예제 #26
0
        public ICommand AddSimulationToProject(IMoBiSimulation simulation)
        {
            var loadCommand           = createLoadCommand(simulation);
            var shouldCloneSimulation = _context.CurrentProject.Simulations.ExistsById(simulation.Id);

            addSimulationToProject(simulation, loadCommand, shouldCloneSimulation);
            return(loadCommand.Run(_context));
        }
예제 #27
0
 protected override void Context()
 {
     base.Context();
     _simulation = new MoBiSimulation().WithId("Id");
     sut.AddSimulation(_simulation);
     sut.GetOrCreateClassifiableFor <ClassifiableSimulation, IMoBiSimulation>(_simulation);
     sut.AllClassifiables.Count.ShouldBeEqualTo(1);
 }
 protected override void ClearReferences()
 {
     _simulation               = null;
     _cloneManagerForModel     = null;
     _formulaTask              = null;
     _entityPathResolver       = null;
     _startValuesBuildingBlock = null;
 }
예제 #29
0
 protected override void Context()
 {
     base.Context();
     _settings = A.Fake <OutputSelections>();
     A.CallTo(() => _settings.HasSelection).Returns(false);
     _simulation = A.Fake <IMoBiSimulation>();
     A.CallTo(() => _outputSelectionsRetriever.OutputSelectionsFor(_simulation)).Returns(null);
 }
 protected override void Context()
 {
     base.Context();
     _simulation = A.Fake <IMoBiSimulation>();
     _chartTemplateManagerPresenter = A.Fake <IChartTemplateManagerPresenter>();
     A.CallTo(() => _applicationController.Start <IChartTemplateManagerPresenter>()).Returns(_chartTemplateManagerPresenter);
     A.CallTo(_chartTemplateManagerPresenter).WithReturnType <bool>().Returns(false);
 }