Beispiel #1
0
        /// <summary>
        ///    Returns the entity of type <typeparamref name="T" /> with the given path relatve to the
        ///    <paramref name="refEntity" />. If the entity could not be resolved, returns null
        /// </summary>
        public static T TryResolve <T>(this IObjectPath objectPath, IEntity refEntity) where T : class
        {
            bool isFound;
            var  result = TryResolve <T>(objectPath, refEntity, out isFound);

            return(isFound ? result : null);
        }
 protected override void Context()
 {
     base.Context();
     _objectPath             = new ObjectPath("root2", "B");
     _pathWithModelNameFirst = _objectPath.Clone <IObjectPath>();
     _pathWithModelNameFirst.AddAtFront(_modelName);
 }
        private IObjectPath convertedPath(IObjectPath objectPath, IContainer rootContainer, bool addSimulationName)
        {
            if (!objectPath.Any())
            {
                return(objectPath);
            }

            //Path starts with the root element, this needs to be remove no matter what
            if (string.Equals(objectPath.ElementAt(0), Constants.ROOT))
            {
                return(removeFirstEntryOf(objectPath));
            }

            if (rootContainer == null)
            {
                return(objectPath);
            }

            //now this is an simulation absolute path (the second entry in the path is either Organism,  neighborhoods)
            if (rootContainer.ContainerType == ContainerType.Simulation && !addSimulationName)
            {
                return(removeFirstEntryOf(objectPath));
            }

            //the path is either relative or should stay as is. Return
            return(objectPath);
        }
Beispiel #4
0
 protected EditStartValuePathCommand(TBuildingBlock buildingBlock, TStartValue startValue, IObjectPath newContainerPath)
     : base(buildingBlock)
 {
     _newContainerPath   = newContainerPath;
     _originalStartValue = startValue;
     setCommandConstants();
 }
        public bool NegativeValuesAllowed(string modelName, IObjectPath containerPath, string moleculeName)
        {
            Start();

            var container = _flatContainerRepo.ContainerFrom(containerPath.ToString());

            return(negativeValuesAllowed(modelName, container.Id, moleculeName));
        }
        public bool IsPresent(string modelName, IObjectPath containerPath, string moleculeName)
        {
            Start();

            var container = _flatContainerRepo.ContainerFrom(containerPath.ToString());

            return(IsPresent(modelName, container.Id, moleculeName));
        }
 public AddStartValueToBuildingBlockCommand(IStartValuesBuildingBlock <T> startValuesBuildingBlock, T startValue)
     : base(startValuesBuildingBlock)
 {
     _startValue = startValue;
     CommandType = AppConstants.Commands.AddCommand;
     Description = AppConstants.Commands.AddedStartValue(startValue, startValuesBuildingBlock.Name);
     ObjectType  = new ObjectTypeResolver().TypeFor <T>();
     _objectPath = startValue.Path;
 }
 protected override void Context()
 {
     _applicationMoleculeBuilder    = A.Fake <IApplicationMoleculeBuilder>();
     _applicationMoleculeBuilder.Id = "ID";
     _newPath = A.Fake <IObjectPath>();
     _oldPath = A.Fake <IObjectPath>();
     _applicationMoleculeBuilder.RelativeContainerPath = _oldPath;
     sut = new EditRelativeContainerPathPropertyAtApplicationMoleculeBuilderCommand(_applicationMoleculeBuilder, _newPath, A.Fake <IBuildingBlock>());
 }
Beispiel #9
0
 protected override void Context()
 {
     sut = new ParameterResolver();
     _moleculeBuildingBlock = new MoleculeBuildingBlock();
     _spatialStructure      = new SpatialStructure {
         GlobalMoleculeDependentProperties = new Container()
     };
     _containerPath = new ObjectPath();
 }
        protected override void Because()
        {
            var compoundName = _simulation.CompoundNames.First();
            var parameter    = _simulation.Model.Root.EntityAt <IParameter>(compoundName, CoreConstantsForSpecs.Parameter.BLOOD_PLASMA_CONCENTRATION_RATIO);

            parameter.Value = 10;
            _parameterPath  = _entityPathResolver.ObjectPathFor(parameter);
            _psv            = _buildConfigurationTask.CreateFor(_simulation, shouldValidate: true, createAgingDataInSimulation: false).ParameterStartValues;
        }
Beispiel #11
0
 private void updateObjectPath(IObjectPath path)
 {
     if (!path.First().Equals(_oldName))
     {
         return;
     }
     path.Remove(_oldName);
     path.AddAtFront(_newName);
 }
        public IMoleculeBuilder Resolve(IObjectPath containerPath, string moleculeName, ISpatialStructure spatialStructure, IMoleculeBuildingBlock moleculeBuildingBlock)
        {
            if (!canResolveMolecule(moleculeBuildingBlock, moleculeName) || !canResolvePhysicalContainer(containerPath, spatialStructure))
            {
                return(null);
            }

            return(moleculeBuildingBlock[moleculeName]);
        }
        protected ChangeStartValueNameCommand(TBuildingBlock buildingBlock, IObjectPath path, string newValue)
            : base(buildingBlock)
        {
            _newValue           = newValue;
            _originalStartValue = buildingBlock[path];
            _oldValue           = _originalStartValue.Name;

            SetCommandParameters(newValue, _oldValue);
        }
 public UpdateParameterStartValueInBuildingBlockCommand(
     IParameterStartValuesBuildingBlock parameterStartValuesBuildingBlock,
     IObjectPath path,
     double?value) : base(parameterStartValuesBuildingBlock)
 {
     CommandType = AppConstants.Commands.UpdateCommand;
     ObjectType  = ObjectTypes.ParameterStartValue;
     _path       = path;
     _value      = value;
 }
Beispiel #15
0
        public IObjectPath CreateModelPathFor(IObjectPath objectPath, IContainer rootContainer)
        {
            var keywordReplacer = new KeywordReplacerCollection();

            addCommonModelReplacersTo(keywordReplacer, rootContainer);
            var modelPath = objectPath.Clone <IObjectPath>();

            keywordReplacer.ReplaceIn(modelPath);
            return(modelPath);
        }
Beispiel #16
0
        private IObjectPath generateNewPath(IObjectPath containerPath)
        {
            var newPath = new ObjectPath();

            foreach (var element in containerPath)
            {
                newPath.Add(element.Equals(_oldName) ? _newName : element);
            }
            return(newPath);
        }
Beispiel #17
0
 protected override void Context()
 {
     base.Context();
     _dimension           = A.Fake <IDimension>();
     _parameterPath       = new ObjectPath(new[] { "Container", "Parameter" });
     _startValue          = 1.2;
     _parameterStartValue = new ParameterStartValue {
         Path = _parameterPath, StartValue = _startValue, Dimension = _dimension, Formula = null
     };
     A.CallTo(() => _dimension.BaseUnitValueToUnitValue(_dimension.DefaultUnit, _startValue)).Returns(_startValue);
 }
Beispiel #18
0
 protected override void Context()
 {
     base.Context();
     _context            = A.Fake <IMoBiContext>();
     _buildingBlock      = new MoleculeStartValuesBuildingBlock();
     _moleculeStartValue = new MoleculeStartValue();
     _path = new ObjectPath("A", "B");
     _moleculeStartValue.ContainerPath = _path;
     _moleculeStartValue.Name          = "Name";
     _buildingBlock.Add(_moleculeStartValue);
 }
 public EditRelativeContainerPathPropertyAtApplicationMoleculeBuilderCommand(IApplicationMoleculeBuilder applicationMoleculeBuilder, IObjectPath newPath, IBuildingBlock buildingBlock)
     : base(buildingBlock)
 {
     _applicationMoleculeBuilder   = applicationMoleculeBuilder;
     _applicationMoleculeBuilderId = _applicationMoleculeBuilder.Id;
     _newPath    = newPath;
     _oldPath    = applicationMoleculeBuilder.RelativeContainerPath;
     ObjectType  = ObjectTypes.ApplicationMoleculeBuilder;
     CommandType = AppConstants.Commands.EditCommand;
     Description = AppConstants.Commands.EditDescription(ObjectType, AppConstants.Captions.RelativeContainerPath, _oldPath.PathAsString, newPath.PathAsString, applicationMoleculeBuilder.Name);
 }
 public EditPathAtUsablePathCommand(IFormula formula, IObjectPath newObjectPath, IFormulaUsablePath formulaPathToUpdate, IBuildingBlock buildingBlock) : base(buildingBlock)
 {
     _newObjectPath       = newObjectPath;
     _formulaId           = formula.Id;
     _formulaPathToUpdate = formulaPathToUpdate;
     //we need a clone here to save the old path before updating it
     _oldObjectPath = _formulaPathToUpdate.Clone <IFormulaUsablePath>();
     _alias         = _formulaPathToUpdate.Alias;
     Description    = AppConstants.Commands.EditFormulaUsablePath(_oldObjectPath.PathAsString, newObjectPath.PathAsString, _alias, formula.Name, buildingBlock.Name);
     ObjectType     = ObjectTypes.FormulaUsablePath;
     CommandType    = AppConstants.Commands.EditCommand;
 }
 public IParameter GetPossibleParameterFromProject(IObjectPath parameterPath)
 {
     foreach (var topContainer in Context.CurrentProject.SpatialStructureCollection.SelectMany(spatialStructure => spatialStructure.TopContainers))
     {
         var parameter = parameterPath.TryResolve <IParameter>(topContainer, out _);
         if (parameter != null)
         {
             return(parameter);
         }
     }
     return(null);
 }
        public override bool CanResolveParameters()
        {
            var root = _formulaUsable?.RootContainer;

            if (root == null)
            {
                return(false);
            }

            _useablePath = _pathFactory.CreateObjectPathFrom(root.Name, _formulaUsable.Name, AppConstants.Parameters.MOLECULAR_WEIGHT);
            return(_useablePath.TryResolve <IFormulaUsable>(root) != null);
        }
        private IParameterStartValue trySetValue(IObjectPath objectPath, double value)
        {
            var parameterStartValue = _defaultStartValues[objectPath];

            if (parameterStartValue == null)
            {
                throw new Exception($"Parameter not found : {objectPath}");
            }

            parameterStartValue.StartValue = value;
            return(parameterStartValue);
        }
Beispiel #24
0
 protected override void Context()
 {
     base.Context();
     _dimension           = A.Fake <IDimension>();
     _parameterPath       = new ObjectPath(new[] { "Container", "Parameter" });
     _parameterStartValue = new ParameterStartValue {
         Path = _parameterPath, StartValue = 0.0, Dimension = _dimension
     };
     _formula = A.Fake <ExplicitFormula>();
     _parameterStartValue.Formula = _formula;
     _formulaString         = "Hello Again";
     _formula.FormulaString = _formulaString;
 }
Beispiel #25
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);
 }
Beispiel #26
0
        private bool canResolveMoleculeContainerPath(IObjectPath containerPath)
        {
            if (!containerPath.Any())
            {
                return(false);
            }

            var templatePath = containerPath.Clone <IObjectPath>();

            templatePath.RemoveAt(getMoleculeNameIndex(containerPath));

            return(resolveContainerPathInSpatialStructure(templatePath) != null);
        }
        protected override void ExecuteWith(IMoBiContext context)
        {
            var entityPathResolver = context.Resolve <IEntityPathResolver>();

            _objectPath = entityPathResolver.ObjectPathFor(_quantity);

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

            _startValuesBuildingBlock.Add(CreateNewStartValue(context));
        }
        private void trySetFormula(IObjectPath objectPath, IFormula formula)
        {
            var parameterStartValue = _defaultStartValues[objectPath];

            if (parameterStartValue != null)
            {
                parameterStartValue.Formula = formula;
            }
            else
            {
                throw new Exception(string.Format("Parameter not found : {0}", objectPath));
            }
        }
Beispiel #29
0
        private IParameter resolveMoleculeParameterInSpatialStructure(IObjectPath containerPath, string name)
        {
            if (!containerPath.Any() || !canResolveMoleculeContainerPath(containerPath))
            {
                return(null);
            }

            var templatePath = containerPath.Clone <IObjectPath>();

            templatePath.RemoveAt(getMoleculeNameIndex(containerPath));
            templatePath.Add(Constants.MOLECULE_PROPERTIES);
            return(resolveParameterInSpatialStructure(templatePath, name));
        }
      private bool isRelativePath(IObjectPath objectPath)
      {
         if (!objectPath.Any())
            return false;

         if (objectPath[0] == ObjectPath.PARENT_CONTAINER)
            return true;

         if (objectPath.Count == 1)
            return true;

         return false;
      }