public static void SetResult(Instance instance, ValidationRuleResult result, SimpleValidationParameter referenceparameter, InstanceFact referencefact) { var taxonomy = instance.Taxonomy; var factparameters = result.Rule.Parameters.Where(i => !i.IsGeneral && i.Name != referenceparameter.Name).Select(i => i.Name).ToList(); var resultfactparameters = result.Parameters.Where(i => factparameters.Contains(i.Name)); var referencetypeddomains = instance.GetTypedPartDomainIds(referencefact); foreach (var p in resultfactparameters) { var facts = p.FactIDs.SelectMany(i => { return(instance.GetFactsByIdString(i)); }).ToArray().ToList(); p.FactIDs.Clear(); foreach (var fact in facts) { var typeddomains = instance.GetTypedPartDomainIds(fact); var commontypeddomains = typeddomains.Intersect(referencetypeddomains).ToList(); var commontypemmembersoffact = instance.GetTypedPartIds(fact, commontypeddomains); var commontypemmembersofreference = instance.GetTypedPartIds(referencefact, commontypeddomains); if (ValidationRuleHelper.listcomparer.Equals(commontypemmembersoffact, commontypemmembersofreference)) { p.FactIDs.Add(string.Format("I:{0}", fact.IX)); } } } }
public string ValidateByTypedDimension(InstanceFact fact, List <ValidationRuleResult> results, StringBuilder sb) { var typeddimensions = fact.Dimensions.Where(i => i.IsTyped).ToList(); foreach (var typeddimension in typeddimensions) { var member = typeddimension.DomainMember; var fulldomain = typeddimension.Domain; var ruleid = "v_tax_" + fulldomain; var rule = TaxonomyRules.FirstOrDefault(i => i.ID == ruleid) as TypedDimensionValidationRule; if (rule != null) { if (!rule.IsOk(member)) { var result = new ValidationRuleResult(); result.ID = rule.ID; var p = new SimpleValidationParameter(); p.Name = String.Format("{0}, context {1}", typeddimension.Domain, fact.ContextID); //p.Facts.Add(fact.FactString); p.FactIDs.Add(String.Format("I:{0}", fact.IX)); p.Value = member; result.Parameters.Add(p); results.Add(result); } } } return(sb.ToString()); }
internal SimpleValidationParameter Copy() { var sp = new SimpleValidationParameter(); foreach (var item in _Cells) { sp.Cells.Add(item.ToArray().ToList()); } //sp.Facts.AddRange(_Facts); sp.FactIDs = new List <string>(_FactIDs.ToArray()); sp.Name = this.Name; sp.Value = this.Value; sp.BindAsSequence = this.BindAsSequence; return(sp); }
public string ValidateByConcept(InstanceFact fact, List <ValidationRuleResult> results, StringBuilder sb) { var concept = fact.Concept; var conceptkey = fact.Concept.Content.ToLower(); var conceptstr = fact.Concept.Name.ToLower(); var cells = Utilities.Strings.ArrayToString(fact.Cells.ToArray()); var ruleid = "v_tax_" + fact.Concept.Content; var rule = TaxonomyRules.FirstOrDefault(i => i.ID == ruleid) as ConceptValidationRule; if (rule != null) { if (!rule.IsOk(fact)) { var result = new ValidationRuleResult(); result.ID = rule.ID; var p = new SimpleValidationParameter(); p.Name = "a"; p.Value = fact.Value; //p.Facts.Add(fact.FactString); p.FactIDs.Add(String.Format("I:{0}", fact.IX)); var cellidlist = new List <String>(); foreach (var cell in fact.Cells) { cellidlist.Add(TaxonomyEngine.CurrentEngine.CurrentInstance.GetDynamicCellID(cell, fact)); } p.Cells.Add(cellidlist); result.Parameters.Add(p); results.Add(result); } } return(sb.ToString()); }
public List <ValidationRuleResult> GetAllResults() { var results = new List <ValidationRuleResult>(); var factgroups = Parameters.FirstOrDefault().TaxFacts; for (int i = 0; i < factgroups.Count; i++) { var vruleresult = new ValidationRuleResult(); vruleresult.Rule = this; results.Add(vruleresult); vruleresult.ID = this.ID; foreach (var p in Parameters) { if (p.IsGeneral) { continue; } p.Clear(); //p.CurrentCells.Clear(); var itemfacts = new List <string>(); var itemfactids = new List <int>(); var sp = new SimpleValidationParameter(); sp.Name = p.Name; sp.BindAsSequence = p.BindAsSequence; vruleresult.Parameters.Add(sp); //TODO IList <int> facts = null; if (i >= p.TaxFacts.Count && p.TaxFacts.Count == 1) { facts = p.TaxFacts[0]; } else { facts = p.TaxFacts[i]; } if (p.BindAsSequence) { //set the cells itemfactids.AddRange(facts); itemfacts.AddRange(facts.Select(f => Taxonomy.GetFactStringKey(Taxonomy.FactsManager.GetFactKey(f)))); foreach (var tax_fact in itemfactids) { //var cellist = new List<string>(); //sp.Cells.Add(cellist); //var taxfactkey = Taxonomy.FactsManager.GetFactKey(tax_fact); //if (Taxonomy.HasFact(taxfactkey)) //{ // var cells = Taxonomy.GetCellsOfFact(taxfactkey); // cellist.AddRange(cells); //} } } else { if (facts.Count > 1) { //TODO //Logger.WriteLine("Issue with " + this.ID + " parameter " + p.Name); } else { if (facts.Count == 1) { var factkey = Taxonomy.GetFactStringKey(Taxonomy.FactsManager.GetFactKey(facts.FirstOrDefault())); itemfacts.Add(factkey); var factid = facts.FirstOrDefault(); itemfactids.Add(factid); //set the cells //var cells = new List<String>(); //sp.Cells.Add(cells); ; //if (Taxonomy.HasFact(factkey)) //{ // cells.AddRange(Taxonomy.GetCellsOfFact(factkey)); //} } } } //sp.Facts.AddRange(itemfacts); sp.FactIDs.AddRange(itemfactids.Select(f => String.Format("T:{0}", f))); //p.FactIDs.Add(String.Format("I:{0}", fact.IX)); // } } //results = ValidationRuleHelper.ExecuteImplicitFiltering(Taxonomy, results); //Taxonomy.SetCells(results); ValidationRuleHelper.SetCells(Taxonomy, results); return(results); }