Example #1
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            _modelSerialization = context.Serialize(_simulationToUpdate.Model);
            _buildConfigurationSerialization = context.Serialize(_simulationToUpdate.MoBiBuildConfiguration);
            context.UnregisterSimulation(_simulationToUpdate);
            context.PublishEvent(new SimulationUnloadEvent(_simulationToUpdate));

            var oldIdCache = getEntityIdCache(_simulationToUpdate);

            _simulationToUpdate.Update(_updatedBuildConfiguration, _newModel);

            updateReferencesToSimulation(context);

            if (_simulationToUpdate.DiagramModel != null)
            {
                replaceDiagramModelNodeIds(_simulationToUpdate.DiagramModel, oldIdCache, getEntityIdCache(_simulationToUpdate));
            }

            context.Register(_simulationToUpdate);
            _wasChanged = _simulationToUpdate.HasChanged;
            _simulationToUpdate.HasChanged = _hasChanged;

            Description = AppConstants.Commands.UpdateCommandDescription(_changedBuildingBlockName, _simulationToUpdate, _changedBuildingBlockType);

            context.PublishEvent(new SimulationReloadEvent(_simulationToUpdate));
        }
Example #2
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;
            }
        }
        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));
            }
        }
Example #4
0
 protected override void ExecuteWith(IMoBiContext context)
 {
     base.ExecuteWith(context);
     Description = AppConstants.Commands.RemoveFromDescription(ObjectType, _itemToRemove.Alias, _parent.Name);
     _parent.RemoveObjectPath(_itemToRemove);
     context.PublishEvent(new RemovedFormulaUsablePathEvent(_parent, _itemToRemove));
     context.PublishEvent(new FormulaChangedEvent(_parent));
 }
 protected override void ExecuteWith(IMoBiContext context)
 {
     base.ExecuteWith(context);
     _parent.AddObjectPath(_pathToAdd);
     Description = AppConstants.Commands.AddToDescription(ObjectType, _pathToAdd.Alias, _parent.Name);
     context.PublishEvent(new AddedFormulaUsablePathEvent(_parent, _pathToAdd));
     context.PublishEvent(new FormulaChangedEvent(_parent));
 }
Example #6
0
        protected override void Context()
        {
            base.Context();
            _context = A.Fake <IMoBiContext>();
            A.CallTo(() => _context.PublishEvent(A <RemovedReactionModifierEvent> ._))
            .Invokes(x => { _removed = x.GetArgument <RemovedReactionModifierEvent>(0).ModifierName; });

            A.CallTo(() => _context.PublishEvent(A <AddedReactionModifierEvent> ._))
            .Invokes(x => { _added = x.GetArgument <AddedReactionModifierEvent>(0).ModifierName; });
        }
 public override void Execute(IMoBiContext context)
 {
     try
     {
         context.PublishEvent(new BulkUpdateStartedEvent());
         base.Execute(context);
     }
     finally
     {
         context.PublishEvent(new BulkUpdateFinishedEvent());
     }
 }
        private void addItemAsFormulaUsableInReactionFormula(IMoBiContext context)
        {
            var formula           = _parent.Formula;
            var formulaUsablePath = createPath(_moleculeName, formula.ObjectPaths.Select(x => x.Alias), context);

            //One element was already defined with the same path. Nothing to do
            if (formula.ObjectPaths.Select(x => x.PathAsString).Contains(formulaUsablePath.PathAsString))
            {
                return;
            }

            formula.AddObjectPath(formulaUsablePath);
            context.PublishEvent(new AddedFormulaUsablePathEvent(formula, formulaUsablePath));
            context.PublishEvent(new FormulaChangedEvent(formula));
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            _reaction.RemoveModifier(_oldModifier);
            _reaction.AddModifier(_newModifier);
            var reactionDiagramManager = _buildingBlock.DiagramManager.DowncastTo <IMoBiReactionDiagramManager>();

            if (reactionDiagramManager.IsInitialized)
            {
                reactionDiagramManager.RenameMolecule(_reaction, _oldModifier, _newModifier);
            }

            context.PublishEvent(new RemovedReactionModifierEvent(_reaction, _oldModifier));
            context.PublishEvent(new AddedReactionModifierEvent(_reaction, _newModifier));
        }
Example #10
0
        public (bool valid, string validationMessage) Validate(string formulaString, FormulaWithFormulaString formula, IBuildingBlock buildingBlock)
        {
            var(valid, validationMessage) = formula.IsValid(formulaString);

            if (valid)
            {
                _context.PublishEvent(new FormulaValidEvent(formula, buildingBlock));
            }
            else
            {
                _context.PublishEvent(new FormulaInvalidEvent(formula, buildingBlock, validationMessage));
            }

            return(valid, validationMessage);
        }
Example #11
0
        public void Remove(FormulaBuilderDTO formulaDTO)
        {
            var formula = getFormulaForDTO(formulaDTO);

            if (formula == null)
            {
                return;
            }
            if (_formulaUsageChecker.FormulaUsedIn(_buildingBlock, formula))
            {
                _dialogCreator.MessageBoxInfo(AppConstants.Exceptions.FormulaInUse(formula));
                return;
            }

            var result = _dialogCreator.MessageBoxYesNo(AppConstants.Captions.ReallyDeleteFormula(formula.Name));

            if (result == ViewResult.No)
            {
                return;
            }

            AddCommand(new RemoveFormulaFromFormulaCacheCommand(_buildingBlock, formula).Run(_context));
            //Ensure that if an invalid formula is removed, the invalid message is removed as well
            _context.PublishEvent(new FormulaValidEvent(formula, _buildingBlock));
            Edit(_buildingBlock);
        }
Example #12
0
 protected override void DoExecute(IMoBiContext context)
 {
     _buildingBlock.RemoveChartTemplate(_chartTemplate.Name);
     _serializationStream = context.Serialize(_chartTemplate);
     Description          = AppConstants.Commands.RemoveChartTemplateFromBuildingBlock(_chartTemplate.Name, _buildingBlock.Name);
     context.PublishEvent(new BuildingBlockChartTemplatesModifiedEvent(_buildingBlock));
 }
Example #13
0
 protected override void ExecuteWith(IMoBiContext context)
 {
     base.ExecuteWith(context);
     _changedUsedCalculationMethod.CalculationMethod = NewCalculationMethod;
     context.PublishEvent(new ChangedCalculationMethodEvent(_moleculeBuilder));
     context.ProjectChanged();
 }
 protected override void ExecuteWith(IMoBiContext context)
 {
     base.ExecuteWith(context);
     _oldCoefficient = _reactionPartner.StoichiometricCoefficient;
     _reactionPartner.StoichiometricCoefficient = _newCoefficient;
     context.PublishEvent(new EditReactionPartnerEvent(_reaction, _reactionPartner));
 }
 protected override void ExecuteWith(IMoBiContext context)
 {
     base.ExecuteWith(context);
     Description = AppConstants.Commands.RemoveFromDescription(ObjectType, _itemToRemove.Name, _parent.Name, context.TypeFor(_buildingBlock), _buildingBlock.Name);
     RemoveFrom(_itemToRemove, _parent, context);
     context.Unregister(_itemToRemove);
     context.PublishEvent(new RemovedEvent(_itemToRemove, _parent));
 }
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            var formula = context.Get <IFormula>(_formulaId);

            formula.FormulaUsablePathBy(_alias).Dimension = context.DimensionFactory.Dimension(_newDimension);
            context.PublishEvent(new FormulaChangedEvent(formula));
        }
Example #17
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            var project = context.CurrentProject;

            context.Register(_simulation);
            project.AddSimulation(_simulation);
            context.PublishEvent(new SimulationAddedEvent(_simulation));
        }
Example #18
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            var formula = context.Get <ExplicitFormula>(_formulaId);

            formula.FormulaString = _newFormulaString;
            context.PublishEvent(new FormulaChangedEvent(formula));
        }
Example #19
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);

            SetUnitAndPoints();

            context.PublishEvent(new TableFormulaUnitChangedEvent(_tableFormula));
        }
Example #20
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            var result = _simulation.Results;

            _simulation.Results = null;
            Description         = AppConstants.Commands.RemoveFromDescription(ObjectType, result.Name, _simulation.Name);
            context.PublishEvent(new RemovedDataEvent(result));
        }
 protected override void Context()
 {
     base.Context();
     _project = A.Fake <IMoBiProject>();
     _context = A.Fake <IMoBiContext>();
     A.CallTo(() => _context.CurrentProject).Returns(_project);
     A.CallTo(() => _context.PublishEvent(A <RemovedEvent> ._))
     .Invokes(x => _event = x.GetArgument <RemovedEvent>(0));
 }
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            var descriptorCriteria = _descriptorCriteriaRetriever(_taggedObject);

            RemoveTagCondition(descriptorCriteria);
            context.PublishEvent(new RemoveTagConditionEvent(_taggedObject));
            Description = AppConstants.Commands.RemoveTagFromConditionDescription(ObjectType, _tag, _taggedObject.Name);
        }
Example #23
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            var formula = context.Get <IFormula>(_formulaId);

            formula.FormulaUsablePathBy(_oldAlias).Alias = _newAlias;

            context.PublishEvent(new FormulaChangedEvent(formula));
        }
Example #24
0
 // Note": We use a function here to ensure that evaluation of RHSDimension is only performed if there is a RHS
 private void updateFormulaDimension(IFormula formula, Func <IDimension> dimensionRetriever, IMoBiContext context)
 {
     if (formula == null)
     {
         return;
     }
     formula.Dimension = dimensionRetriever();
     context.PublishEvent(new FormulaChangedEvent(_parameter.Formula));
 }
        protected override void ExecuteWith(IMoBiContext context)
        {
            var project = context.CurrentProject;

            removeFromProject(project);
            context.Unregister(_buildingBlock);
            _serializationStream = context.Serialize(_buildingBlock);
            context.PublishEvent(new RemovedEvent(_buildingBlock, project));
        }
 private void updateFormulaDimension(IFormula formula, IDimension dimension, IMoBiContext context)
 {
     if (formula == null)
     {
         return;
     }
     formula.Dimension = dimension;
     context.PublishEvent(new FormulaChangedEvent(_parameter.Formula));
 }
        public virtual void Merge(ICache <string, T> merge, ICache <string, T> target, Func <T, T, bool> areElementsEquivalent = null)
        {
            var resolved            = 0;
            var conflictResolution  = areElementsEquivalent ?? ((x, y) => false);
            var conflictingElements = GetConflictingElements(merge, target, conflictResolution).ToList();

            var option = MergeConflictOptions.SkipOnce;

            foreach (var key in conflictingElements)
            {
                resolved++;
                if (!option.IsAppliedToAll())
                {
                    option = prompt(merge[key], target[key], conflictingElements.Count() - resolved);
                }

                if (option.IsClone())
                {
                    if (option.IsAutoRename())
                    {
                        _nameCorrector.AutoCorrectName(AppConstants.UnallowedNames.Union(target.Select(targetEntity => targetEntity.Name)), merge[key]);
                    }
                    else
                    {
                        if (!_nameCorrector.CorrectName(AppConstants.UnallowedNames.Union(target.Select(targetEntity => targetEntity.Name)), merge[key]))
                        {
                            return;
                        }
                    }
                    _cloneAction(merge[key], key);
                }
                else if (option.IsMerge())
                {
                    _mergeAction(target[key], merge[key]);
                }

                else if (option.IsSkip())
                {
                    continue;
                }

                else if (option == MergeConflictOptions.Cancel)
                {
                    _context.PublishEvent(new MergeCanceledEvent());
                    _cancelAction();
                    return;
                }
                else
                {
                    _removeAction(target[key]);
                    _addAction(merge[key]);
                }
            }

            GetElementsToAdd(merge, target).Each(_addAction);
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            context.CurrentProject.RemoveSimulation(_simulation);
            context.UnregisterSimulation(_simulation);
            context.PublishEvent(new SimulationRemovedEvent(_simulation));

            //Do not serialize Results
            _simulation.Results  = null;
            _serializationStream = context.Serialize(_simulation);
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            var descriptorCrieria = _descriptorCriteriaRetriever(_taggedObject);
            var newTagCondition   = CreateNewTagCondition();

            descriptorCrieria.Add(newTagCondition);
            context.PublishEvent(new AddTagConditionEvent(_taggedObject));
            Description = AppConstants.Commands.AddToConditionDescription(ObjectType, _tag, _taggedObject.Name);
        }
Example #30
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            _parent.RemovePoint(_itemToRemove);
            double xValueInDisplayUnit = _parent.XDisplayValueFor(_itemToRemove.X);
            double yValueInDisplayUnit = _parent.YDisplayValueFor(_itemToRemove.Y);

            Description = AppConstants.Commands.RemoveValuePointDescription(xValueInDisplayUnit, yValueInDisplayUnit, _parent.Name, _parent.XDisplayUnit, _parent.YDisplayUnit);
            context.PublishEvent(new RemovedValuePointEvent(_parent, _itemToRemove));
        }