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);
        }
        protected override void DoExecute(IMoBiContext context)
        {
            var containerTask = context.Resolve <IContainerTask>();
            var msvBuildingBlockSynchronizer = context.Resolve <IQuantitySynchronizer>();
            var allMoleculeAmounts           = containerTask.CacheAllChildren <IMoleculeAmount>(_simulation.Model.Root);
            var moleculeStartValues          = _simulation.BuildConfiguration.MoleculeStartValues;

            foreach (var scaleDivisor in _scaleFactors)
            {
                var moleculeAmount = allMoleculeAmounts[scaleDivisor.QuantityPath];
                if (moleculeAmount == null)
                {
                    continue;
                }

                if (ValueComparer.AreValuesEqual(moleculeAmount.ScaleDivisor, scaleDivisor.Value))
                {
                    continue;
                }

                _oldScaleFactors.Add(new ScaleDivisor {
                    QuantityPath = scaleDivisor.QuantityPath, Value = moleculeAmount.ScaleDivisor
                });
                moleculeAmount.ScaleDivisor = scaleDivisor.Value;
                msvBuildingBlockSynchronizer.SynchronizeMoleculeStartValues(moleculeAmount, moleculeStartValues);
            }
        }
Пример #3
0
        private void updateReferencesToSimulation(IMoBiContext context)
        {
            var simulationReferenceUpdater = context.Resolve <ISimulationReferenceUpdater>();

            simulationReferenceUpdater.SwapSimulationInParameterAnalysables(_simulationToUpdate, _simulationToUpdate);

            var simulationParameterOriginIdUpdater = context.Resolve <ISimulationParameterOriginIdUpdater>();

            simulationParameterOriginIdUpdater.UpdateSimulationId(_simulationToUpdate);
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            _formulaTask = context.Resolve <IMoBiFormulaTask>();
            _affectedBuildingBlockRetriever = context.Resolve <IAffectedBuildingBlockRetriever>();

            var fixedParameters = fixedConstantParametersFromBuildingBlock();

            resetFixedParametersInSimulation(fixedParameters);

            context.PublishEvent(new ParameterChangedEvent(fixedParameters));
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            _entityPathResolver   = context.Resolve <IEntityPathResolver>();
            _cloneManagerForModel = context.Resolve <ICloneManagerForModel>();
            _formulaTask          = context.Resolve <IMoBiFormulaTask>();

            foreach (var quantity in AllQuantitiesToReset())
            {
                resetQuantity(quantity, QuantityUsedToFindPathFor(quantity), context);
            }
        }
        private void addContainerVolumeParameter(IMoBiContext context)
        {
            var volume = _container.GetSingleChildByName <IParameter>(Constants.Parameters.VOLUME);

            //switch from physical to logical. If volume was created here, this command is an inverse and volume should be removed
            if (_newContainerMode == ContainerMode.Logical)
            {
                if (_volumeParameterCreatedHere && volume != null)
                {
                    _container.RemoveChild(volume);
                    context.Unregister(volume);
                    context.PublishEvent(new RemovedEvent(volume, _container));
                }
            }
            //we switched from Logical to physical. Add volume parameter if not available
            else
            {
                if (volume != null)
                {
                    return;
                }
                var parameterFactory = context.Resolve <IParameterFactory>();
                volume = parameterFactory.CreateVolumeParameter();

                _container.Add(volume);
                context.Register(volume);
                _volumeParameterCreatedHere = true;
                context.PublishEvent(new AddedEvent <IParameter>(volume, _container));
            }
        }
 protected override void Context()
 {
     base.Context();
     _context = A.Fake <IMoBiContext>();
     _buildingBlockVersionUpdater = A.Fake <IBuildingBlockVersionUpdater>();
     A.CallTo(() => _context.Resolve <IBuildingBlockVersionUpdater>()).Returns(_buildingBlockVersionUpdater);
 }
        protected override void Context()
        {
            _parameterStartValueBuildingBlock = new ParameterStartValuesBuildingBlock().WithId("PSVBB");
            _objectPath = new ObjectPath("A", "B", "P");
            _parameter  = A.Fake <IParameter>().WithName("P").WithId("P");
            sut         = new AddParameterStartValueFromQuantityInSimulationCommand(_parameter, _parameterStartValueBuildingBlock);

            _context = A.Fake <IMoBiContext>();
            _parameterStartValuesCreator = A.Fake <IParameterStartValuesCreator>();
            _entityPathResolver          = A.Fake <IEntityPathResolver>();
            A.CallTo(() => _context.Resolve <IEntityPathResolver>()).Returns(_entityPathResolver);
            A.CallTo(() => _context.Resolve <IParameterStartValuesCreator>()).Returns(_parameterStartValuesCreator);
            A.CallTo(() => _context.Get <IParameter>(_parameter.Id)).Returns(_parameter);
            A.CallTo(() => _context.Get <IStartValuesBuildingBlock <IParameterStartValue> >(_parameterStartValueBuildingBlock.Id)).Returns(_parameterStartValueBuildingBlock);

            A.CallTo(() => _entityPathResolver.ObjectPathFor(_parameter, false)).Returns(_objectPath);
        }
Пример #9
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            var reactionDiagramManager = _buildingBlock.DiagramManager.DowncastTo <IMoBiReactionDiagramManager>();
            var diagramUpdater         = context.Resolve <IDiagramUpdater>();

            diagramUpdater.RemoveMoleculeNodeFromDiagram(_moleculeNodeId, reactionDiagramManager, _buildingBlock.DiagramModel);
        }
Пример #10
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            var groupRepository = context.Resolve <IGroupRepository>();

            _oldGroup           = groupRepository.GroupByName(_quantity.GroupName);
            _quantity.GroupName = _newGroup.Name;
            Description         = AppConstants.Commands.EditDescription(ObjectType, AppConstants.Captions.Group, _oldGroup.DisplayName, _newGroup.DisplayName, _quantity.Name);
        }
        protected override void Context()
        {
            base.Context();
            _project = A.Fake <IProject>();
            _parameterIdentification = A.Fake <ParameterIdentification>();
            _context = A.Fake <IMoBiContext>();
            _simulationReferenceUpdater         = A.Fake <ISimulationReferenceUpdater>();
            _simulationParameterOriginIdUpdater = A.Fake <ISimulationParameterOriginIdUpdater>();

            A.CallTo(() => _context.PublishEvent(A <SimulationUnloadEvent> ._))
            .Invokes(x => _event = x.GetArgument <SimulationUnloadEvent>(0));

            A.CallTo(() => _context.Project).Returns(_project);
            A.CallTo(() => _context.Resolve <ISimulationReferenceUpdater>()).Returns(_simulationReferenceUpdater);
            A.CallTo(() => _context.Resolve <ISimulationParameterOriginIdUpdater>()).Returns(_simulationParameterOriginIdUpdater);
            A.CallTo(() => _project.AllParameterIdentifications).Returns(new[] { _parameterIdentification });
            _parameterIdentification.AddSimulation(_simulation);
        }
        private void manageSimulationChange(IMoBiContext context)
        {
            WasChanged             = _simulation.HasChanged;
            _simulation.HasChanged = _changed;
            _simulation.MarkResultsOutOfDate();
            var buildConfigurationUpdater = context.Resolve <IBuildConfigurationUpdater>();

            buildConfigurationUpdater.UpdateBuildingConfiguration(_changedObject, _simulation, Increment);
        }
        protected override void Context()
        {
            _moleculeDimension = A.Fake <IDimension>();
            _kinetic           = new ExplicitFormula();
            _reaction          = new ReactionBuilder {
                Formula = _kinetic
            };
            _reactionBuildingBlock = A.Fake <IMoBiReactionBuildingBlock>();
            _reactionBuildingBlock.DiagramManager = A.Fake <IMoBiReactionDiagramManager>();
            _reactionPartner = new ReactionPartnerBuilder("A", 1);
            sut = new AddReactionPartnerToEductCollection(_reactionBuildingBlock, _reactionPartner, _reaction);

            _context            = A.Fake <IMoBiContext>();
            _dimensionRetriever = A.Fake <IReactionDimensionRetriever>();
            A.CallTo(() => _context.Resolve <IAliasCreator>()).Returns(new AliasCreator());
            A.CallTo(() => _context.Resolve <IReactionDimensionRetriever>()).Returns(_dimensionRetriever);
            A.CallTo(() => _context.Resolve <IObjectPathFactory>()).Returns(new ObjectPathFactory(new AliasCreator()));
            A.CallTo(() => _dimensionRetriever.MoleculeDimension).Returns(_moleculeDimension);
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            _moleculeBuilder.QuantityType = _newType;
            var iconRepository = context.Resolve <IIconRepository>();

            // Reset Icon so Iconrepository can retrieve the new icon based on type
            _moleculeBuilder.Icon = string.Empty;
            _moleculeBuilder.Icon = iconRepository.IconFor(_moleculeBuilder);
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            if (_buildingBlock == null)
            {
                return;
            }
            var buildingBlockVersionUpdater = context.Resolve <IBuildingBlockVersionUpdater>();

            buildingBlockVersionUpdater.UpdateBuildingBlockVersion(_buildingBlock, ShouldIncrementVersion);
        }
        protected override IMoleculeStartValue CreateNewStartValue(IMoBiContext context)
        {
            var moleculeStartValueCreator = context.Resolve <IMoleculeStartValuesCreator>();
            var containerPath             = _objectPath.Clone <IObjectPath>();
            var lastIndex = containerPath.Count - 1;
            var name      = containerPath[lastIndex];

            containerPath.RemoveAt(lastIndex);

            return(moleculeStartValueCreator.CreateMoleculeStartValue(containerPath, name, _quantity.Dimension, _quantity.DisplayUnit, _quantity.ValueOrigin));
        }
        private IFormulaUsablePath createPath(string moleculeName, IEnumerable <string> usedAliases, IMoBiContext context)
        {
            var dimensionRetriever = context.Resolve <IReactionDimensionRetriever>();
            var aliasCreator       = context.Resolve <IAliasCreator>();
            var objectPathFactory  = context.Resolve <IObjectPathFactory>();

            var pathToRefernecedObject = new List <string> {
                ObjectPath.PARENT_CONTAINER, moleculeName
            };

            //in case of concentration, we need to add a reference to the concentration parameter
            if (dimensionRetriever.SelectedDimensionMode == ReactionDimensionMode.ConcentrationBased)
            {
                pathToRefernecedObject.Add(AppConstants.Parameters.CONCENTRATION);
            }

            return(objectPathFactory.CreateFormulaUsablePathFrom(pathToRefernecedObject)
                   .WithDimension(dimensionRetriever.MoleculeDimension)
                   .WithAlias(aliasCreator.CreateAliasFrom(moleculeName, usedAliases)));
        }
        protected override void Context()
        {
            _context               = A.Fake <IMoBiContext>();
            _liver                 = new Container().WithName("LIVER");
            _simulation            = A.Fake <IMoBiSimulation>();
            _simulation.Model.Root = new Container().WithContainerType(ContainerType.Simulation);
            _simulation.Model.Root.Add(_liver);
            _moleculeStartValues = new MoleculeStartValuesBuildingBlock();
            _simulation.BuildConfiguration.MoleculeStartValues = _moleculeStartValues;
            sut = new ResetMoleculeValuesToDefaultFromStartValuesInSimulationCommand(_simulation);

            _formulaTask          = A.Fake <IMoBiFormulaTask>();
            _entityPathResolver   = new EntityPathResolver(new ObjectPathFactory(new AliasCreator()));
            _cloneManagerForModel = A.Fake <ICloneManagerForModel>();

            A.CallTo(_formulaTask).WithReturnType <ConstantFormula>().Returns(new ConstantFormula());
            A.CallTo(() => _context.Resolve <IMoBiFormulaTask>()).Returns(_formulaTask);
            A.CallTo(() => _context.Resolve <IEntityPathResolver>()).Returns(_entityPathResolver);
            A.CallTo(() => _context.Resolve <ICloneManagerForModel>()).Returns(_cloneManagerForModel);
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            var entityPathResolver = context.Resolve <IEntityPathResolver>();

            _objectPath = entityPathResolver.ObjectPathFor(_quantity);

            if (_startValuesBuildingBlock[_objectPath] != null)
            {
                return;
            }

            _startValuesBuildingBlock.Add(CreateNewStartValue(context));
        }
Пример #20
0
 protected override void Context()
 {
     _formula       = new ExplicitFormula("A+B").WithId("id");
     _buildingBlock = A.Fake <IBuildingBlock>();
     _context       = A.Fake <IMoBiContext>();
     _newObjectPath = new FormulaUsablePath("NEW", "PATH").WithAlias("C1");
     _oldObjectPath = new FormulaUsablePath("OLD", "PATH").WithAlias("C1");
     sut            = new EditPathAtUsablePathCommand(_formula, _newObjectPath, _oldObjectPath, _buildingBlock);
     _formula.AddObjectPath(_oldObjectPath);
     A.CallTo(() => _context.Get <IFormula>(_formula.Id)).Returns(_formula);
     _buildingBlockVersionUpdater = A.Fake <IBuildingBlockVersionUpdater>();
     A.CallTo(() => _context.Resolve <IBuildingBlockVersionUpdater>()).Returns(_buildingBlockVersionUpdater);
 }
Пример #21
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            OldName          = _objectBase.Name;
            _objectBase.Name = _newName;
            if (_objectBase.IsAnImplementationOf <IBuildingBlock>())
            {
                var renameBuildingBlockTask = context.Resolve <IRenameBuildingBlockTask>();
                renameBuildingBlockTask.RenameInSimulationUsingTemplateBuildingBlock(_objectBase.DowncastTo <IBuildingBlock>());
            }

            context.PublishEvent(new RenamedEvent(_objectBase));
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            var displayUnitRetriever = context.Resolve <IDisplayUnitRetriever>();

            _parameter.Dimension   = _newDimension;
            _parameter.DisplayUnit = _newDisplayUnit ?? displayUnitRetriever.PreferredUnitFor(_parameter);

            updateFormulaDimension(_parameter.Formula, _newDimension, context);
            updateFormulaDimension(_parameter.RHSFormula, context.DimensionFactory.RHSDimensionFor(_newDimension), context);

            Description = AppConstants.Commands.SetParameterDimension(_parameter.EntityPath(), _oldDimension.Name, _newDimension.Name);
            context.PublishEvent(new QuantityChangedEvent(_parameter));
        }
        private void removeNeighborhoods(IContainer entityToRemove, ICache <string, IObjectBase> removedIds, IMoBiSpatialStructure spatialStructure, IMoBiContext context)
        {
            var containerTask         = context.Resolve <IContainerTask>();
            var neighborhoodsToDelete = containerTask.AllNeighborhoodBuildersConnectedWith(spatialStructure, entityToRemove).ToList();

            foreach (var neighborhoodBuilder in neighborhoodsToDelete)
            {
                if (!removedIds.Contains(neighborhoodBuilder.Id))
                {
                    spatialStructure.RemoveNeighborhood(neighborhoodBuilder);
                    removedIds.Add(neighborhoodBuilder);
                }
            }
        }
Пример #24
0
        public virtual void GetLocalisationReferences()
        {
            using (var selectLocalisationPresenter = _context.Resolve <ISelectLocalisationPresenter>())
            {
                var localisation = selectLocalisationPresenter.Select(_localisation);
                if (localisation == null)
                {
                    return;
                }

                _refObject         = localisation;
                _view.Localisation = _objectPathFactory.CreateAbsoluteObjectPath(localisation).PathAsString;
                selectInView(_refObject);
            }
        }
        protected override void Context()
        {
            _context       = A.Fake <IMoBiContext>();
            _buildingBlock = A.Fake <IBuildingBlock>();
            _container     = new Container {
                Mode = _oldContainerMode, Id = "Container"
            };
            A.CallTo(() => _context.Get <IContainer>(_container.Id)).Returns(_container);
            _volumeParameter = new Parameter().WithName(Constants.Parameters.VOLUME);
            var parameterFactory = A.Fake <IParameterFactory>();

            A.CallTo(() => parameterFactory.CreateVolumeParameter()).Returns(_volumeParameter);
            A.CallTo(() => _context.Resolve <IParameterFactory>()).Returns(parameterFactory);
            sut = new SetContainerModeCommand(_buildingBlock, _container, _newContainerMode);
        }
Пример #26
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            var buildingBlockInfo             = _simulation.MoBiBuildConfiguration.BuildingInfoForTemplate(oldTemplateBuildingBlock);
            var buildingBlockUsedInSimulation = buildingBlockInfo.UntypedBuildingBlock;

            //Update simulation info and save the old one for undo
            buildingBlockInfo.SimulationChanges = 0;

            base.ExecuteWith(context);

            var bbInfoUpdater = context.Resolve <IBuilingBlockReferenceUpdater>();

            bbInfoUpdater.UpdateTemplateReference(context.CurrentProject, newTemplateBuildingBlock);

            //increment the version of the template building block to be the version of the swapped building block +1
            newTemplateBuildingBlock.Version = oldTemplateBuildingBlock.Version + 1;
            //make sure building block used in Simulation and new template have the same version
            buildingBlockUsedInSimulation.Version = newTemplateBuildingBlock.Version;

            //notify version changed
            var buildingBlockVersionUpdater = context.Resolve <IBuildingBlockVersionUpdater>();

            buildingBlockVersionUpdater.UpdateBuildingBlockVersion(newTemplateBuildingBlock, newTemplateBuildingBlock.Version);
        }
 protected override void Context()
 {
     _simulation = A.Fake <IMoBiSimulation>();
     _buildingBlockInfoUpdater                                 = A.Fake <IBuilingBlockReferenceUpdater>();
     _oldTemplateBuildingBlock                                 = A.Fake <IParameterStartValuesBuildingBlock>().WithName("OLD TEMPLATE");
     _clonedSimulationBuildingBlock                            = A.Fake <IParameterStartValuesBuildingBlock>().WithName("CLONE SIMULATION");
     _oldTemplateBuildingBlock.Version                         = 7;
     _clonedSimulationBuildingBlock.Version                    = 4;
     _simulationBuildingBlockInfo                              = A.Fake <IBuildingBlockInfo>();
     _simulationBuildingBlockInfo.SimulationChanges            = 5;
     _simulationBuildingBlockInfo.UntypedTemplateBuildingBlock = _oldTemplateBuildingBlock;
     _simulationBuildingBlock = A.Fake <IBuildingBlock>();
     _simulationBuildingBlockInfo.UntypedBuildingBlock = _simulationBuildingBlock;
     _simulationBuildingBlock.Version = _clonedSimulationBuildingBlock.Version;
     _simulationBuildingBlock.Name    = "TRALALA";
     A.CallTo(_simulation.MoBiBuildConfiguration).WithReturnType <IBuildingBlockInfo>().Returns(_simulationBuildingBlockInfo);
     _context = A.Fake <IMoBiContext>();
     A.CallTo(() => _context.Resolve <IBuilingBlockReferenceUpdater>()).Returns(_buildingBlockInfoUpdater);
     sut = new UpdateTemplateBuildingBlockFromSimulationBuildingBlockCommand <IParameterStartValuesBuildingBlock>(_oldTemplateBuildingBlock, _clonedSimulationBuildingBlock, _simulation);
 }
        protected override IParameterStartValue CreateNewStartValue(IMoBiContext context)
        {
            var parameterStartValueCreator = context.Resolve <IParameterStartValuesCreator>();

            return(parameterStartValueCreator.CreateParameterStartValue(_objectPath, _quantity));
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            var configuration = context.Resolve <IApplicationConfiguration>();

            Description = Command.CreateProjectDescription(configuration.Version);
        }
 protected override void Context()
 {
     base.Context();
     _context = A.Fake <IMoBiContext>();
     A.CallTo(() => _context.Resolve <IIconRepository>()).Returns(new IconRepository());
 }