示例#1
0
        /// <summary>
        ///    Copy the references for first and second Neighbor from <paramref name="sourcecNeighborhoodBuilder" /> to
        ///    <paramref name="targetNeighborhoodBuilder" />.
        /// </summary>
        /// <param name="sourcecNeighborhoodBuilder">The source neighborhood builder to copy neighbors from.</param>
        /// <param name="targetNeighborhoodBuilder">The neighborhood builder to copy neighbors to.</param>
        private void updateNeighborsReferences(INeighborhoodBuilder sourcecNeighborhoodBuilder, INeighborhoodBuilder targetNeighborhoodBuilder)
        {
            var objectPathFactory = new ObjectPathFactory(new AliasCreator());
            var firstPath         = objectPathFactory.CreateAbsoluteObjectPath(sourcecNeighborhoodBuilder.FirstNeighbor);
            var secondPath        = objectPathFactory.CreateAbsoluteObjectPath(sourcecNeighborhoodBuilder.SecondNeighbor);

            foreach (var topContainer in TopContainers)
            {
                var firstNeighbor  = firstPath.Resolve <IContainer>(topContainer);
                var secondNeighbor = secondPath.Resolve <IContainer>(topContainer);

                if (firstNeighbor != null)
                {
                    targetNeighborhoodBuilder.FirstNeighbor = firstNeighbor;
                }

                if (secondNeighbor != null)
                {
                    targetNeighborhoodBuilder.SecondNeighbor = secondNeighbor;
                }

                //both neighbors set. early exit
                if (targetNeighborhoodBuilder.FirstNeighbor != null && targetNeighborhoodBuilder.SecondNeighbor != null)
                {
                    return;
                }
            }
        }
示例#2
0
 protected override void Context()
 {
     base.Context();
     _neighborhoodBuilder =
         new NeighborhoodBuilder().WithName("N1")
         .WithFirstNeighbor(new Container().WithName("C1"))
         .WithSecondNeighbor(new Container().WithName("C2"));
 }
 protected override void Context()
 {
     base.Context();
     _individualNeighborhoods = new Container();
     _individualNeighborhoods.Add(new Container().WithName(_flatNeighborhoodFor3Comp.Name));
     _neighborhoodBuilder = A.Fake <INeighborhoodBuilder>();
     _flatNeighborhood    = new FlatNeighborhood {
         Name = "tralala"
     };
     _flatNeighborhoodFor3Comp.UsageInIndividual = CoreConstants.ORM.USAGE_IN_INDIVIDUAL_REQUIRED;
     A.CallTo(() => _neighborhoodRepository.NeighborhoodFrom(_flatNeighborhoodFor3Comp.Id)).Returns(_flatNeighborhood);
     A.CallTo(() => _neighborhoodBuilderFactory.Create()).Returns(_neighborhoodBuilder);
 }
        /// <summary>
        ///    Returns molecules which will be created in both neighbours of the neighbourhood
        /// </summary>
        private IEnumerable <string> moleculeNamesFor(INeighborhoodBuilder neighborhoodBuilder,
                                                      ICache <string, IList <string> > moleculesStartValuesForFloatingMolecules)
        {
            var pathToFirstNeighbor  = _objectPathFactory.CreateAbsoluteObjectPath(neighborhoodBuilder.FirstNeighbor).ToString();
            var pathToSecondNeighbor = _objectPathFactory.CreateAbsoluteObjectPath(neighborhoodBuilder.SecondNeighbor).ToString();

            // check if both neighbours has at least 1 molecule (if not - return empty list)
            if (!moleculesStartValuesForFloatingMolecules.Contains(pathToFirstNeighbor) ||
                !moleculesStartValuesForFloatingMolecules.Contains(pathToSecondNeighbor))
            {
                return(new List <string>());
            }

            return(moleculesStartValuesForFloatingMolecules[pathToFirstNeighbor]
                   .Intersect(moleculesStartValuesForFloatingMolecules[pathToSecondNeighbor]).ToList());
        }
 protected override void Context()
 {
     base.Context();
     _spatialStructure  = A.Fake <ISpatialStructure>();
     _parent            = A.Fake <IContainer>();
     _containerToRemove = A.Fake <IContainer>();
     _containerToRemove.ParentContainer = _parent;
     _firstNeighborRemove  = new NeighborhoodBuilder().WithFirstNeighbor(_containerToRemove).WithSecondNeighbor(A.Fake <IContainer>());
     _secondNeighborRemove = new NeighborhoodBuilder().WithFirstNeighbor(A.Fake <IContainer>()).WithSecondNeighbor(_containerToRemove);
     A.CallTo(() => _spatialStructure.Neighborhoods).Returns(new[]
     {
         new NeighborhoodBuilder().WithFirstNeighbor(A.Fake <IContainer>()).WithSecondNeighbor(A.Fake <IContainer>()),
         _firstNeighborRemove,
         _secondNeighborRemove
     });
 }
示例#6
0
        protected override void Context()
        {
            _spatialStructureDiagramManager = A.Fake <ISpatialStructureDiagramManager>();
            _spatialStructure = new MoBiSpatialStructure {
                DiagramManager = _spatialStructureDiagramManager
            }.WithName("SpSt");
            _spatialStructure.NeighborhoodsContainer = new Container().WithName(Constants.NEIGHBORHOODS);
            _parent            = new Container().WithName("Top").WithMode(ContainerMode.Logical).WithId(_parentId);
            _containerToRemove = new Container().WithName("A").WithMode(ContainerMode.Physical).WithParentContainer(_parent);
            _otherContainer    = new Container().WithName("B").WithMode(ContainerMode.Physical).WithParentContainer(_parent);
            _spatialStructure.AddTopContainer(_parent);
            _neighborhood = new NeighborhoodBuilder().WithFirstNeighbor(_containerToRemove).WithSecondNeighbor(_otherContainer).WithName("A2B");
            _spatialStructure.AddNeighborhood(_neighborhood);
            _context = A.Fake <IMoBiContext>();

            sut = new RemoveContainerFromSpatialStructureCommand(_parent, _containerToRemove, _spatialStructure);
        }
        private bool addNeighborhood(INeighborhoodBuilder neighborhoodBuilder, MoBiMacroCommand command, IMoBiSpatialStructure spatialStructure)
        {
            var forbiddenNames = spatialStructure.NeighborhoodsContainer.Children.Select(x => x.Name).Union(AppConstants.UnallowedNames).ToList();

            if (forbiddenNames.Contains(neighborhoodBuilder.Name))
            {
                string newName = _dialogCreator.AskForInput(AppConstants.Dialog.AskForChangedName(neighborhoodBuilder.Name, ObjectTypes.NeighborhoodBuilder), AppConstants.Captions.NewName, neighborhoodBuilder.Name, forbiddenNames);

                if (string.IsNullOrEmpty(newName))
                {
                    return(false);
                }
                neighborhoodBuilder.Name = newName;
            }
            command.AddCommand(new AddContainerToSpatialStructureCommand(spatialStructure.NeighborhoodsContainer, neighborhoodBuilder, spatialStructure).Run(Context));
            return(true);
        }
示例#8
0
        protected override void Context()
        {
            base.Context();
            _rootContainer      = A.Fake <IContainer>().WithName("ROOT");
            _buildConfiguration = A.Fake <IBuildConfiguration>();
            _model               = A.Fake <IModel>();
            _model.Root          = _rootContainer;
            _neighborhoodBuilder = A.Fake <INeighborhoodBuilder>().WithName("tralala");
            _neighborhoodBuilder.FirstNeighbor  = A.Fake <IContainer>();
            _neighborhoodBuilder.SecondNeighbor = A.Fake <IContainer>();
            A.CallTo(() => _neighborhoodBuilder.MoleculeProperties).Returns(A.Fake <IContainer>());
            var para1 = A.Fake <IParameter>();
            var para2 = A.Fake <IParameter>();

            A.CallTo(() => _neighborhoodBuilder.Parameters).Returns(new[] { para1, para2 });
            _clonePara1 = A.Fake <IParameter>();
            _clonePara2 = A.Fake <IParameter>();
            var firstNeighborBuilderPath  = A.Fake <IObjectPath>();
            var secondNeighborBuilderPath = A.Fake <IObjectPath>();

            A.CallTo(() => _objectPathFactory.CreateAbsoluteObjectPath(_neighborhoodBuilder.FirstNeighbor)).Returns(firstNeighborBuilderPath);
            A.CallTo(() => _objectPathFactory.CreateAbsoluteObjectPath(_neighborhoodBuilder.SecondNeighbor)).Returns(secondNeighborBuilderPath);
            var firstNeighborModelPath  = A.Fake <IObjectPath>();
            var secondNeighborModelPath = A.Fake <IObjectPath>();

            _firstNeighborInModel  = A.Fake <IContainer>();
            _secondNeighborInModel = A.Fake <IContainer>();
            A.CallTo(() => _keywordReplacerTask.CreateModelPathFor(firstNeighborBuilderPath, _model.Root)).Returns(firstNeighborModelPath);
            A.CallTo(() => _keywordReplacerTask.CreateModelPathFor(secondNeighborBuilderPath, _model.Root)).Returns(secondNeighborModelPath);
            A.CallTo(() => firstNeighborModelPath.Resolve <IContainer>(_rootContainer)).Returns(_firstNeighborInModel);
            A.CallTo(() => secondNeighborModelPath.Resolve <IContainer>(_rootContainer)).Returns(_secondNeighborInModel);
            _moleculeContainer = A.Fake <IContainer>();
            A.CallTo(() => _containerMapper.MapFrom(_neighborhoodBuilder.MoleculeProperties, _buildConfiguration)).Returns(_moleculeContainer);
            _molecule1     = "molecule1";
            _molecule2     = "molecule2";
            _moleculeNames = new List <string> {
                _molecule1, _molecule2
            };
            A.CallTo(() => _objectBaseFactory.Create <INeighborhood>()).Returns(A.Fake <INeighborhood>());
            A.CallTo(() => _parameterMapper.MapFrom(para1, _buildConfiguration)).Returns(_clonePara1);
            A.CallTo(() => _parameterMapper.MapFrom(para2, _buildConfiguration)).Returns(_clonePara2);
        }
        public INeighborhood MapFrom(INeighborhoodBuilder neighborhoodBuilder, IModel model,
                                     IBuildConfiguration buildConfiguration,
                                     IEnumerable <string> moleculeNames,
                                     IEnumerable <string> moleculeNamesWithCopyPropertiesRequired)
        {
            var neighborhood = _objectBaseFactory.Create <INeighborhood>();

            neighborhood.UpdatePropertiesFrom(neighborhoodBuilder, _cloneManagerForModel);
            buildConfiguration.AddBuilderReference(neighborhood, neighborhoodBuilder);
            neighborhood.FirstNeighbor  = resolveReference(model, neighborhoodBuilder.FirstNeighbor);
            neighborhood.SecondNeighbor = resolveReference(model, neighborhoodBuilder.SecondNeighbor);
            if (neighborhoodBuilder.MoleculeProperties != null)
            {
                moleculeNames.Each(moleculeName => neighborhood.Add(
                                       createMoleculePropertiesFor(neighborhoodBuilder, moleculeName, model.Root, buildConfiguration, moleculeNamesWithCopyPropertiesRequired)));
            }

            //Add neighorhood parameter to the neighborhood (clone the existing parmeter)
            neighborhoodBuilder.Parameters.Each(param => neighborhood.Add(_parameterMapper.MapFrom(param, buildConfiguration)));
            return(neighborhood);
        }
        protected override void Context()
        {
            base.Context();
            _neighborhood   = A.Fake <INeighborhoodBuilder>().WithName("toto");
            _organism       = A.Fake <PKSim.Core.Model.Organism>();
            _firstNeighbor  = A.Fake <IContainer>();
            _secondNeighbor = A.Fake <IContainer>();
            _neighborhoods  = new List <INeighborhoodBuilder> {
                _neighborhood
            };
            var flatNeighborhood = new FlatNeighborhood {
                FirstNeighborId = 1, SecondNeighborId = 2
            };

            A.CallTo(() => _flatNeighborhoodRepository.NeighborhoodFrom(_neighborhood.Name)).Returns(flatNeighborhood);
            var containerPath1 = A.Fake <IObjectPath>();
            var containerPath2 = A.Fake <IObjectPath>();

            A.CallTo(() => _flatContainerRepository.ContainerPathFrom(flatNeighborhood.FirstNeighborId)).Returns(containerPath1);
            A.CallTo(() => _flatContainerRepository.ContainerPathFrom(flatNeighborhood.SecondNeighborId)).Returns(containerPath2);
            A.CallTo(() => containerPath1.Resolve <IContainer>(_organism)).Returns(_firstNeighbor);
            A.CallTo(() => containerPath2.Resolve <IContainer>(_organism)).Returns(_secondNeighbor);
        }
示例#11
0
        private void addChildrenFromNeigborhood(List <IObjectBaseDTO> children, INeighborhoodBuilder neighborhood)
        {
            if (neighborhood == null)
            {
                return;
            }

            var firstContainer  = neighborhood.FirstNeighbor;
            var secondContainer = neighborhood.SecondNeighbor;

            if (firstContainer == null || secondContainer == null)
            {
                return;
            }

            if (!Equals(firstContainer.ParentContainer, secondContainer.ParentContainer))
            {
                firstContainer  = firstContainer.ParentContainer;
                secondContainer = secondContainer.ParentContainer;
            }

            children.Add(_objectBaseDTOMapper.MapFrom(firstContainer));
            children.Add(_objectBaseDTOMapper.MapFrom(secondContainer));
        }
        private IContainer createMoleculePropertiesFor(INeighborhoodBuilder neighborhoodBuilder,
                                                       string moleculeName, IContainer rootContainer,
                                                       IBuildConfiguration buildConfiguration,
                                                       IEnumerable <string> moleculeNamesWithCopyPropertiesRequired)
        {
            //Create a new model container from the neighborhood container
            var moleculePropertiesContainer = _containerMapper.MapFrom(neighborhoodBuilder.MoleculeProperties, buildConfiguration);

            moleculePropertiesContainer.ContainerType = ContainerType.Molecule;

            //Assigment molecule properties subcontainer name from <MOLECULE_PROPERTIES>
            //to concrete molecule name
            moleculePropertiesContainer.Name = moleculeName;

            _keywordReplacerTask.ReplaceIn(moleculePropertiesContainer, rootContainer, moleculeName);

            //remove children if molecule properties should not be copied
            if (!moleculeNamesWithCopyPropertiesRequired.Contains(moleculeName))
            {
                moleculePropertiesContainer.RemoveChildren();
            }

            return(moleculePropertiesContainer);
        }
示例#13
0
 private INeighborhoodBuilder neighborhoodBuilderSourceFor(INeighborhoodBuilder neighborhoodBuilder, IEnumerable <INeighborhoodBuilder> sourceNeighborhoods)
 {
     return(sourceNeighborhoods.FindByName(neighborhoodBuilder.Name));
 }
 protected override void Because()
 {
     _result = sut.Create();
 }
示例#15
0
 public void AddNeighborhood(INeighborhoodBuilder neighborhoodBuilder)
 {
     NeighborhoodsContainer.Add(neighborhoodBuilder);
 }
示例#16
0
 private void addNeighborhood(INeighborhoodBuilder neighborhood, ISpatialStructure spatialStructure, OriginData originData, ModelProperties modelProperties, IFormulaCache formulaCache)
 {
     spatialStructure.AddNeighborhood(neighborhood);
     _parameterContainerTask.AddModelParametersTo(neighborhood, originData, modelProperties, formulaCache);
     _parameterContainerTask.AddModelParametersTo(neighborhood.MoleculeProperties, originData, modelProperties, formulaCache);
 }
示例#17
0
 public void RemoveNeighborhood(INeighborhoodBuilder neighborhoodBuilder)
 {
     NeighborhoodsContainer.RemoveChild(neighborhoodBuilder);
 }
 protected override void Because()
 {
     _result = sut.CreateBetween(_firstNeighbor, _secondNeighbor);
 }
 public NeighborhoodBuilderDTO MapFrom(INeighborhoodBuilder neighborhoodBuilder)
 {
     return(Map <NeighborhoodBuilderDTO>(neighborhoodBuilder));
 }