private IFormula checkFormula(IFormulaCache formulaCache, IFormula formula) { if (formula.IsExplicit()) { return(checkFormulaByType(formulaCache, (ExplicitFormula)formula, AreEqualExplicitFormula)); } if (formula.IsBlackBox()) { return(checkFormulaByType(formulaCache, (BlackBoxFormula)formula, AreEqualBalckBoxFormula)); } if (formula.IsTable()) { return(checkFormulaByType(formulaCache, (TableFormula)formula, AreEqualTableFormula)); } if (formula.IsTableWithOffSet()) { return(checkFormulaByType(formulaCache, (TableFormulaWithOffset)formula, AreEqualTableFormulaWithOffset)); } if (formula.IsDynamic()) { return(checkFormulaByType(formulaCache, (SumFormula)formula, AreEqualSumFormula)); } return(formula); }
/// <summary> /// Returns true if the formula can be added to a <see cref="FormulaCache" /> otherwise false /// </summary> public static bool IsCachable(this IFormula formula) { return(formula.IsExplicit() || formula.IsBlackBox() || formula.IsDynamic() || formula.IsTable() || formula.IsTableWithOffSet() || formula.IsTableWithXArgument()); }
protected void CheckFormulaIn(IUsingFormula entity, IFormula formulaToCheck, ResolveErrorBehavior resolveErrorBehavior) { var entityAbsolutePath = _objectPathFactory.CreateAbsoluteObjectPath(entity).ToPathString(); var builder = _buildConfiguration.BuilderFor(entity); var objectWithError = builder ?? entity; var entityType = _objectTypeResolver.TypeFor(entity); if (formulaToCheck.IsBlackBox()) { addNotificationType(NotificationType.Error, objectWithError, Validation.FormulaIsBlackBoxIn(entity.Name, entityAbsolutePath)); return; } foreach (var objectPath in formulaToCheck.ObjectPaths) { CheckPath(entity, objectPath, resolveErrorBehavior); } }
protected void CheckFormulaIn(IUsingFormula entity, IFormula formulaToCheck, ResolveErrorBehavior resolveErrorBehavior) { var entityAbsolutePath = _objectPathFactory.CreateAbsoluteObjectPath(entity).ToPathString(); var builder = _buildConfiguration.BuilderFor(entity); var objectWithError = builder ?? entity; // Dynamic formula may contain object path that will be resolved per instance. It cannot be checked here if (formulaToCheck.IsDynamic()) { return; } if (formulaToCheck.IsBlackBox()) { addNotificationType(NotificationType.Error, objectWithError, Validation.FormulaIsBlackBoxIn(entity.Name, entityAbsolutePath)); return; } foreach (var objectPath in formulaToCheck.ObjectPaths) { CheckPath(entity, objectPath, resolveErrorBehavior); } }
public bool FormulasAreTheSame(IFormula firstFormula, IFormula secondFormula) { if (firstFormula == null && secondFormula == null) { return(true); } if (firstFormula == null || secondFormula == null) { return(false); } var firstType = firstFormula.GetType(); var secondType = secondFormula.GetType(); if (firstType != secondType) { return(false); } //nothing more to check for distributed formula or black box formula if (firstFormula.IsDistributed() || firstFormula.IsBlackBox() || firstFormula.IsDynamic()) { return(true); } if (firstFormula.IsConstant()) { var firstConstFormula = firstFormula.DowncastTo <ConstantFormula>(); var secondConstFormula = secondFormula.DowncastTo <ConstantFormula>(); return(firstConstFormula.Value == secondConstFormula.Value); } if (firstFormula.IsExplicit()) { var firstExplicit = firstFormula.DowncastTo <ExplicitFormula>(); var secondExplicit = secondFormula.DowncastTo <ExplicitFormula>(); if (!string.Equals(firstExplicit.FormulaString, secondExplicit.FormulaString)) { return(false); } //check that formula have the same references using the same alias var firstObjectPathCache = new Cache <string, IFormulaUsablePath>(x => x.Alias); firstObjectPathCache.AddRange(firstExplicit.ObjectPaths); var secondObjectPathCache = new Cache <string, IFormulaUsablePath>(x => x.Alias); secondObjectPathCache.AddRange(secondExplicit.ObjectPaths); if (firstObjectPathCache.Count() != secondObjectPathCache.Count()) { return(false); } foreach (var keyValue in firstObjectPathCache.KeyValues) { if (!secondObjectPathCache.Contains(keyValue.Key)) { return(false); } var path = secondObjectPathCache[keyValue.Key]; if (!path.Equals(keyValue.Value)) { return(false); } } } return(true); }