public IMoleculeAmount MapFrom(IMoleculeBuilder moleculeBuilder, IContainer targetContainer, IBuildConfiguration buildConfiguration)
        {
            //molecule amount always in amount
            var moleculeAmount = _objectBaseFactory.Create <IMoleculeAmount>()
                                 .WithName(moleculeBuilder.Name)
                                 .WithDescription(moleculeBuilder.Description)
                                 .WithContainerType(ContainerType.Molecule)
                                 .WithIcon(moleculeBuilder.Icon)
                                 .WithQuantityType(moleculeBuilder.QuantityType)
                                 .WithDimension(_amountDimension)
                                 .WithDisplayUnit(_amountDimension.UnitOrDefault(_amountDimension.DefaultUnit.Name));

            buildConfiguration.AddBuilderReference(moleculeAmount, moleculeBuilder);

            createMoleculeAmountDefaultFormula(moleculeBuilder, buildConfiguration, moleculeAmount);

            //map parameters. Only parameters having BuildMode="Local" will
            //be added to the molecule amount. Global/Property-Parameters
            //will be filled in elsewhere (by the GlobalProperties-Mapper)
            var allLocalParameters = moleculeBuilder.Parameters
                                     .Where(x => x.BuildMode == ParameterBuildMode.Local)
                                     .Where(x => x.ContainerCriteria?.IsSatisfiedBy(targetContainer) ?? true);

            allLocalParameters.Each(x => moleculeAmount.Add(_parameterMapper.MapFrom(x, buildConfiguration)));

            _keywordReplacerTask.ReplaceIn(moleculeAmount);
            return(moleculeAmount);
        }
 private void addHelpParametersFor(ICoreCalculationMethod calculationMethod, IList <IMoleculeBuilder> allMoleculesUsingMethod)
 {
     foreach (var helpParameter in calculationMethod.AllHelpParameters())
     {
         var containerDescriptor = calculationMethod.DescriptorFor(helpParameter);
         foreach (var molecule in allMoleculesUsingMethod)
         {
             foreach (var container in allMoleculeContainersFor(containerDescriptor, molecule))
             {
                 var exisitingParameter = container.GetSingleChildByName <IParameter>(helpParameter.Name);
                 //does not exist yet
                 if (exisitingParameter == null)
                 {
                     var parameter = _parameterMapper.MapFrom(helpParameter, _buildConfiguration);
                     container.Add(parameter);
                     replaceKeyWordsIn(parameter, molecule.Name);
                 }
                 else if (!formulasAreTheSameForParameter(exisitingParameter, helpParameter.Formula, molecule.Name))
                 {
                     throw new OSPSuiteException(Error.HelpParameterAlreadyDefinedWithAnotherFormula(calculationMethod.Name, _objectPathFactory.CreateAbsoluteObjectPath(helpParameter).ToString()));
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        private void createEventGroupStructure(IEventGroupBuilder eventGroupBuilder, IEventGroup eventGroup, IBuildConfiguration buildConfiguration)
        {
            foreach (var childBuilder in eventGroupBuilder.Children)
            {
                //nothing to do for these entities that should not be copied in the model structure
                if (doesNotBelongIntoModel(childBuilder))
                {
                    continue;
                }

                if (childBuilder.IsAnImplementationOf <IEventGroupBuilder>())
                {
                    var childEventGroup = MapFrom(childBuilder.DowncastTo <IEventGroupBuilder>(), buildConfiguration);
                    eventGroup.Add(childEventGroup);

                    if (childBuilder.IsAnImplementationOf <IApplicationBuilder>())
                    {
                        createApplication(childBuilder.DowncastTo <IApplicationBuilder>(), childEventGroup, buildConfiguration);
                    }
                }

                else if (childBuilder.IsAnImplementationOf <IEventBuilder>())
                {
                    eventGroup.Add(_eventMapper.MapFrom(childBuilder.DowncastTo <IEventBuilder>(), buildConfiguration));
                }

                else if (childBuilder.IsAnImplementationOf <IParameter>())
                {
                    eventGroup.Add(_parameterMapper.MapFrom(childBuilder.DowncastTo <IParameter>(), buildConfiguration));
                }

                else if (childBuilder.IsAnImplementationOf <IContainer>())
                {
                    eventGroup.Add(_containerMapper.MapFrom(childBuilder.DowncastTo <IContainer>(), buildConfiguration));
                }

                else
                {
                    eventGroup.Add(_cloneManagerForModel.Clone(childBuilder));
                }
            }
        }
        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);
        }
        public IEvent MapFrom(IEventBuilder eventBuilder, IBuildConfiguration buildConfiguration)
        {
            var modelEvent = _objectBaseFactory.Create <IEvent>()
                             .WithName(eventBuilder.Name)
                             .WithDimension(eventBuilder.Dimension)
                             .WithDescription(eventBuilder.Description)
                             .WithFormula(_formulaMapper.MapFrom(eventBuilder.Formula, buildConfiguration));

            buildConfiguration.AddBuilderReference(modelEvent, eventBuilder);

            eventBuilder.Assignments
            .SelectMany(x => _assignmentMapper.MapFrom(x, buildConfiguration))
            .Each(modelEvent.AddAssignment);

            foreach (var param in eventBuilder.Parameters)
            {
                modelEvent.Add(_parameterMapper.MapFrom(param, buildConfiguration));
            }

            modelEvent.OneTime = eventBuilder.OneTime;

            return(modelEvent);
        }
Exemplo n.º 6
0
 public IEnumerable <IParameter> MapFrom(IEnumerable <IParameter> parameterBuilders, IBuildConfiguration buildConfiguration, params ParameterBuildMode[] parameterBuildModesToMap)
 {
     return(parameterBuilders.Where(p => canBeMapped(p, parameterBuildModesToMap))
            .Select(parameterBuilder => _parameterMapper.MapFrom(parameterBuilder, buildConfiguration)).ToList());
 }