private static IParameter searchParameterInContainers(IObjectPath parameterPath, IMoBiSpatialStructure spatialStructure) { if (spatialStructure == null) { return(null); } IParameter parameter = null; foreach (var top in spatialStructure.TopContainers) { parameter = parameterPath.Resolve <IParameter>(top); if (parameter != null) { break; } } if (parameter == null) { parameter = parameterPath.Resolve <IParameter>(spatialStructure.NeighborhoodsContainer); } return(parameter); }
/// <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, success will be set to false and the returned value is null. /// </summary> public static T TryResolve <T>(this IObjectPath objectPath, IEntity refEntity, out bool success) where T : class { try { var result = objectPath.Resolve <T>(refEntity); success = result != null; return(result); } catch (Exception) { success = false; return(null); } }
protected void CheckPath(IUsingFormula entity, IObjectPath objectPathToCheck, ResolveErrorBehavior resolveErrorBehavior) { var builder = _buildConfiguration.BuilderFor(entity); var objectWithError = builder ?? entity; var entityAbsolutePath = _objectPathFactory.CreateAbsoluteObjectPath(entity).ToString(); var entityType = _objectTypeResolver.TypeFor(entity); if (containsKeyWords(objectPathToCheck)) { addNotificationType(NotificationType.Error, objectWithError, Validation.PathContainsReservedKeywords(entity.Name, entityType, entityAbsolutePath, objectPathToCheck.ToPathString())); return; } //found, we continue if (objectPathToCheck.Resolve <IFormulaUsable>(entity) != null) { return; } string message = Validation.ErrorUnableToFindReference(entity.Name, entityType, entityAbsolutePath, objectPathToCheck.ToPathString()); if (resolveErrorBehavior == ResolveErrorBehavior.Error) { addNotificationType(NotificationType.Error, objectWithError, message); } else { var parent = entity.ParentContainer; parent?.RemoveChild(entity); if (resolveErrorBehavior == ResolveErrorBehavior.Delete) { return; } addNotificationType(NotificationType.Warning, objectWithError, message); } }
protected override void Context() { base.Context(); _project = A.Fake <IMoBiProject>(); _startValue = A.Fake <IParameterStartValue>(); _parameterPath = A.Fake <IObjectPath>(); _parentBuidlidingBlock = A.Fake <IParameterStartValuesBuildingBlock>(); _parentBuidlidingBlock.Id = "Parent"; _para = A.Fake <IParameter>().WithName("Para").WithDimension(A.Fake <IDimension>()); A.CallTo(() => _startValue.Path).Returns(_parameterPath); _simulation = A.Fake <IMoBiSimulation>(); A.CallTo(() => _project.Simulations).Returns(new[] { _simulation, }); _buildConfiguration = A.Fake <IMoBiBuildConfiguration>(); _buildConfiguration.ParameterStartValuesInfo = new ParameterStartValuesBuildingBlockInfo(); _buildConfiguration.ParameterStartValuesInfo.TemplateBuildingBlock = _parentBuidlidingBlock; _model = A.Fake <IModel>(); _root = A.Fake <IContainer>(); A.CallTo(() => _simulation.MoBiBuildConfiguration).Returns(_buildConfiguration); A.CallTo(() => _simulation.Model).Returns(_model); A.CallTo(() => _parameterPath.Resolve <IParameter>(_root)).Returns(_para); _model.Root = _root; A.CallTo(() => _context.CurrentProject).Returns(_project); }
public void resolve_should_return_root() { _objectPath.Resolve <IContainer>(_reak).ShouldBeEqualTo(_topContainer); }
public void resolved_path_should_return_ourself() { _path.Resolve <IUsingFormula>(_parameter).ShouldBeEqualTo(_parameter); }
public void should_retrieve_parameter_in_simulation() { A.CallTo(() => _parameterPath.Resolve <IParameter>(_root)).MustHaveHappened(); }