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 static void SetCells(Instance instance, ValidationRuleResult result)
        {
            var p_i = 0;

            //result.Rule = instance.Taxonomy.ValidationRules result.ID
            foreach (var p in result.Parameters)
            {
                p.Cells.Clear();
                foreach (var factid in p.FactIDs)
                {
                    var instancefact = instance.GetFactByIDStringForCell(factid);
                    var cells        = new List <string>();
                    if (instancefact.InstanceKey.Length > 0)
                    {
                        cells   = instance.GetCells(instancefact);
                        p.Value = instancefact.Value + ",";
                    }
                    else
                    {
                        cells = instance.GetCellsByTaxFactIndex(instancefact.TaxonomyKey);
                    }

                    p.Cells.Add(cells);
                }
                if (string.IsNullOrEmpty(p.Value))
                {
                    p.Value = result.Rule.Parameters[p_i].FallBackValue;
                }
                p.Value = p.Value.TrimEnd(',');


                p_i++;
            }
        }
示例#3
0
        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());
        }
        public static List <int> GetUncoveredDomains(Instance instance, ValidationRuleResult ruleresult)
        {
            var result   = new List <int>();
            var taxonomy = instance.Taxonomy;
            var rule     = ruleresult.Rule;
            var ruleparameterdictionary       = rule.Parameters.ToDictionary(i => i.Name);
            var ruleresultparameterdictionary = ruleresult.Parameters.ToDictionary(i => i.Name);
            var factparameterids        = ruleparameterdictionary.Where(i => !i.Value.IsGeneral).Select(i => i.Key).ToList();
            var mainaspectsofparameters = new List <List <int> >();

            foreach (var parmaeterid in factparameterids)
            {
                var rulep       = ruleparameterdictionary[parmaeterid];
                var p           = ruleresultparameterdictionary[parmaeterid];
                var mainaspects = new HashSet <int>();
                foreach (var fact in p.InstanceFacts)
                {
                    foreach (var part in fact.TaxonomyKey)
                    {
                        var mainaspectid = taxonomy.DimensionDomainsOfMembers.ContainsKey(part) ? taxonomy.DimensionDomainsOfMembers[part] : part;

                        if (!mainaspects.Contains(mainaspectid))
                        {
                            mainaspects.Add(mainaspectid);
                        }
                    }
                }

                var aspectsofparameter = mainaspects.Except(rulep.CoveredParts).ToList();
                //aspectsofparameter = aspectsofparameter.Except(rule.CoveredParts).ToList();
                mainaspectsofparameters.Add(aspectsofparameter);
            }
            List <int> commonmainaspects = null;

            foreach (var parameteraspects in mainaspectsofparameters)
            {
                if (commonmainaspects == null)
                {
                    commonmainaspects = parameteraspects.ToList();
                }
                else
                {
                    commonmainaspects = commonmainaspects.Intersect(parameteraspects).ToList();
                }
            }

            result = commonmainaspects;

            return(result);
        }
        public static void SetCells(Taxonomy taxonomy, ValidationRuleResult result)
        {
            foreach (var p in result.Parameters)
            {
                p.Cells.Clear();
                foreach (var factid in p.FactIDs)
                {
                    var taxfactid = Utilities.Converters.FastParse(factid.Substring(2));

                    var cells = taxonomy.GetCellsOfFact(taxfactid);
                    p.Cells.Add(cells);
                }
            }
        }
 public static ValidationRuleIssue GetIssue(ValidationRuleResult result)
 {
     foreach (var p in result.Parameters)
     {
         var ruleparameter = result.Rule.Parameters.FirstOrDefault(i => i.Name == p.Name);
         if (!ruleparameter.BindAsSequence)
         {
             if (p.FactIDs.Count > 1)
             {
                 return(new ValidationRuleIssue(ValidationRuleIssueType.NonSequencedMultipleFacts, result.ID, p.Name));
             }
         }
     }
     return(null);
 }
        public ValidationRuleResult Copy()
        {
            var source = this;
            var result = new ValidationRuleResult();

            result.IsOk       = source.IsOk;
            result.ID         = source.ID;
            result.HasAllFind = source.HasAllFind;
            result.FactGroup  = source.FactGroup;
            result.IsOk       = source.IsOk;
            result.Rule       = source.Rule;
            result.Parameters = source.Parameters.Select(i => i.Copy()).ToList();

            return(result);
        }
        public static void LoadTypedFacts(Instance instance, ValidationRuleResult ruleresult)
        {
            var taxonomy           = instance.Taxonomy;
            var rule               = ruleresult.Rule;
            var rulefactparameters = rule.Parameters.Where(i => !i.IsGeneral).ToList();

            foreach (var rulefactparameter in rulefactparameters)
            {
                var p = ruleresult.Parameters.FirstOrDefault(i => i.Name == rulefactparameter.Name);

                p.InstanceFacts = p.FactIDs.SelectMany(i => instance.GetFactsByIdString(i)).ToList();

                var newfactids = new List <string>();
                foreach (var fact in p.InstanceFacts)
                {
                    newfactids.Add(String.Format("I:{0}", fact.IX));
                }
                //foreach (var factid in p.FactIDs)
                //{
                //    var facts = instance.GetFactsByIdString(factid);
                //    if (facts.Count> 0)
                //    {
                //        foreach (var fact in facts)
                //        {
                //            newfactids.Add(String.Format("I:{0}", fact.IX));

                //        }
                //    }
                //    else
                //    {
                //        newfactids.Add(factid);
                //    }
                //}
                p.FactIDs = newfactids;
            }
        }
示例#9
0
        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());
        }
示例#10
0
        /*
         * public List<ValidationRuleResult> GetAllInstanceResultsOld(Instance instance)
         * {
         *  if (this.ID.Contains("de_sprv_vrdp-bi_3260"))
         *  {
         *  }
         *  var taxonomy = instance.Taxonomy;
         *  var allresults = GetAllResults();
         *  var allinstanceresults = new List<ValidationRuleResult>();
         *  var resultstoremove = new List<ValidationRuleResult>();
         *  var resultstoadd = new List<ValidationRuleResult>();
         *  var hastyped = this.Parameters.Any(i => i.TypedDimensions.Count > 0);
         *
         *
         *  if (!hastyped)
         *  {
         *      var allfactsindexes = this.Parameters.SelectMany(i => i.TaxFacts.SelectMany(j => j)).ToList();
         *
         *      foreach (var factindex in allfactsindexes)
         *      {
         *          var factindexintervallist = new IntervalList(factindex);
         *          var existing = Utilities.Objects.IntersectSorted(factindexintervallist, taxonomy.TypedIntervals, null);
         *          if (existing.Intervals.Count > 0)
         *          {
         *              hastyped = true;
         *              break;
         *          }
         *      }
         *  }
         *  //var hastyped = this.Parameters.Any(i => i.TaxFacts.Any(j=>Taxonomy.IsTyped() > 0);
         *  if (this.Parameters.Count == 1 && this.Parameters.FirstOrDefault().IsGeneral)//.StringValue == "filingindicators")
         *  {
         *      if (allresults.Count == 1)
         *      {
         *          var theresult = allresults.FirstOrDefault();
         *          resultstoremove.Add(theresult);
         *          var finds = instance.FilingIndicators.Where(i => i.Filed).ToList();
         *          foreach (var find in finds)
         *          {
         *              var findresult = new ValidationRuleResult();
         *              resultstoadd.Add(findresult);
         *
         *              findresult.ID = theresult.ID;
         *              findresult.Parameters.AddRange(theresult.Parameters.Select(p => p.Copy()));
         *              findresult.Parameters.FirstOrDefault().Value = find.ID;
         *          }
         *      }
         *      if (allresults.Count == 0)
         *      {
         *          foreach (var find in instance.FilingIndicators)
         *          {
         *              var findresult = new ValidationRuleResult();
         *              resultstoadd.Add(findresult);
         *
         *              findresult.ID = this.ID;
         *              foreach (var p in Parameters)
         *              {
         *                  var sp = new SimpleValidationParameter();
         *                  sp.Name = p.Name;
         *                  sp.BindAsSequence = p.BindAsSequence;
         *                  sp.Value = p.StringValue;
         *                  findresult.Parameters.Add(sp);
         *                  if (p.IsGeneral && p.StringValue == "filingindicators")
         *                  {
         *                      sp.Value = find.ID;
         *                  }
         *              }
         *          }
         *      }
         *  }
         *
         *  foreach (var result in allresults)
         *  {
         *
         *      if (hastyped)
         *      {
         *          //resultstoadd.AddRange(ValidationRuleHelper.GetTypedResults(instance, this, result));
         *          resultstoadd.AddRange(ValidationRuleHelper.ResolveTypedFacts(instance, result));
         *          resultstoremove.Add(result);
         *
         *      }
         *
         *  }
         *  allinstanceresults = allresults;
         *  foreach (var r in resultstoremove)
         *  {
         *      allinstanceresults.Remove(r);
         *
         *  }
         *  allinstanceresults.AddRange(resultstoadd);
         *  foreach (var result in allinstanceresults)
         *  {
         *      foreach (var p in result.Parameters)
         *      {
         *          if (p.Cells.Any(c1 => c1.Any(c2 => c2.Contains(Literals.DynamicCode))))
         *          {
         *              for (int i = 0; i < p.FactIDs.Count; i++)
         *              {
         *                  var cells = p.Cells.Count==p.FactIDs.Count ? p.Cells[i] : p.Cells.FirstOrDefault();
         *                  var fid = p.FactIDs[i];
         *                  var fk = instance.GetFactKeyByIndexString(fid);
         *                  //var dcells = instance.GetDynamicCellID(cells.FirstOrDefault(), fs);
         *                  var dcells = instance.GetDynamicCellID(cells.FirstOrDefault(), fk);
         *                  cells.Clear();
         *                  cells.Add(dcells);
         *
         *              }
         *          }
         *          var mFactIDs = p.FactIDs.ToList();
         *          var ix = 0;
         *          foreach (var factidentfier in p.FactIDs)
         *          {
         *              var parts = factidentfier.Split(":");
         *              if (parts[0] == "T")
         *              {
         *                  var tix = Utilities.Converters.FastParse(parts[1]);
         *                  var taxkey = instance.Taxonomy.FactsManager.GetFactKey(tix);
         *                  var facts = instance.GetFactsByTaxKey(taxkey);
         *                  if (facts.Count == 1)
         *                  {
         *                      var fact = facts.FirstOrDefault();
         *                      mFactIDs[ix] = string.Format("I:{0}", fact.IX);
         *                  }
         *              }
         *              ix++;
         *          }
         *          p.FactIDs = mFactIDs;
         *      }
         *  }
         *
         *  return allinstanceresults;
         * }
         */
        /*
         * public List<ValidationRuleResult> GetAllInstanceResultsOld(Instance instance)
         * {
         *  if (this.ID.Contains("0149"))
         *  {
         *  }
         *  var allresults = GetAllResults();
         *  var allinstanceresults = new List<ValidationRuleResult>();
         *  var resultstoremove = new List<ValidationRuleResult>();
         *  var resultstoadd = new List<ValidationRuleResult>();
         *  var hastyped = false;
         *  var waschecked = false;
         *  if (this.Parameters.Count == 1 && this.Parameters.FirstOrDefault().IsGeneral)//.StringValue == "filingindicators")
         *  {
         *      if (allresults.Count == 1)
         *      {
         *          var theresult = allresults.FirstOrDefault();
         *          resultstoremove.Add(theresult);
         *          var finds = instance.FilingIndicators.Where(i => i.Filed).ToList();
         *          foreach (var find in finds)
         *          {
         *              var findresult = new ValidationRuleResult();
         *              resultstoadd.Add(findresult);
         *
         *              findresult.ID = theresult.ID;
         *              findresult.Parameters.AddRange(theresult.Parameters.Select(p => p.Copy()));
         *              findresult.Parameters.FirstOrDefault().Value = find.ID;
         *          }
         *      }
         *      if (allresults.Count == 0)
         *      {
         *          foreach (var find in instance.FilingIndicators)
         *          {
         *              var findresult = new ValidationRuleResult();
         *              resultstoadd.Add(findresult);
         *
         *              findresult.ID = this.ID;
         *              foreach (var p in Parameters)
         *              {
         *                  var sp = new SimpleValidationParameter();
         *                  sp.Name = p.Name;
         *                  sp.BindAsSequence = p.BindAsSequence;
         *                  sp.Value = p.StringValue;
         *                  findresult.Parameters.Add(sp);
         *                  if (p.IsGeneral && p.StringValue == "filingindicators")
         *                  {
         *                      sp.Value = find.ID;
         *                  }
         *              }
         *          }
         *      }
         *  }
         *
         *  foreach (var result in allresults)
         *  {
         *      var facts = new List<FactBase>();
         *      if (!waschecked)
         *      {
         *          waschecked = true;
         *          //facts = result.Parameters.SelectMany(i => i.Facts).Select(i => FactBase.GetFactFrom(i)).ToList();
         *          facts = result.Parameters.SelectMany(i => i.FactIDs).Select(i => FactBase.GetFactFrom(
         *              Taxonomy.GetFactStringKey(Taxonomy.FactsManager.GetFactKey(Utilities.Converters.FastParse(i.Substring(2)))
         *               ))).ToList();
         *          hastyped = facts.Any(i => i.Dimensions.Any(j => j.IsTyped));
         *      }
         *      if (hastyped)
         *      {
         *          //facts = result.Parameters.SelectMany(i => i.Facts).Select(i => FactBase.GetFactFrom(i)).ToList();
         *          facts = result.Parameters.SelectMany(i => i.FactIDs).Select(i => FactBase.GetFactFrom(
         *                Taxonomy.GetFactStringKey(Taxonomy.FactsManager.GetFactKey(Utilities.Converters.FastParse(i.Substring(2)))
         *                 ))).ToList();
         *          var resultfactgroup = result.FactGroup;
         *
         *          //instance.TypedFactMembers.ContainsKey()
         *
         *          foreach (var firstfact in facts)
         *          {
         *              var instancefacts = instance.GetFactsByTaxKey(firstfact.GetFactKey());
         *              var typestoreplace = new Dictionary<string, string>();
         *              var typestoreplaceids = new Dictionary<int, int>();
         *              if (instancefacts.Count > 0)
         *              {
         *                  resultstoremove.Add(result);
         *                  var typedids = instance.GetTypedPartDomainIds(instancefacts[0]);
         *                  foreach (var typedid in typedids)
         *                  {
         *                      typestoreplaceids.Add(typedid, -2);
         *                  }
         *                  //var typedfacts = instancefacts[0].Dimensions.Where(i => i.IsTyped).Select(i => i.ToStringForKey());
         *                  //foreach (var typedfact in typedfacts)
         *                  //{
         *                  //    var key = typedfact.Substring(typedfact.IndexOf(":"));
         *                  //    typestoreplace.Add(key, "");
         *                  //}
         *
         *              }
         *              //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
         *              for (int i = 0; i < instancefacts.Count; i++)
         *              {
         *                  var instancefact = instancefacts[i];
         *                  var facttypedids = instance.GetTypedPartIds(instancefact);
         *                  var tix=0;
         *                  var tkeys = typestoreplaceids.Keys.ToList();
         *                  foreach (var tid in tkeys)
         *                  {
         *                      typestoreplaceids[tid] = facttypedids[tix];
         *                      tix++;
         *                  }
         *                  //foreach (var tdim in typedimensions)
         *                  //{
         *                  //    var key = tdim.ToStringForKey();
         *                  //    key = key.Substring(key.IndexOf(":"));
         *                  //    typestoreplace[key] = tdim.DomainMemberFullName.Substring(tdim.DomainMemberFullName.IndexOf(":"));
         *                  //}
         *
         *                  var dynamicresult = new ValidationRuleResult();
         *                  resultstoadd.Add(dynamicresult);
         *                  dynamicresult.FactGroup = new List<string>() { instancefact.GetFactString() };
         *
         *                  dynamicresult.ID = result.ID;
         *                  dynamicresult.Parameters.AddRange(result.Parameters.Select(p => p.Copy()));
         *                  dynamicresult.Message = result.Message;
         *                  foreach (var p in dynamicresult.Parameters)
         *                  {
         *                      p.Cells.Clear();
         *                      //for (var f_ix = 0; f_ix < p.Facts.Count; f_ix++)
         *                      for (var f_ix = 0; f_ix < p.FactIDs.Count; f_ix++)
         *                      {
         *
         *                          var factid = Utilities.Converters.FastParse(p.FactIDs[f_ix].Substring(2));
         *                          var factkey = Taxonomy.FactsManager.GetFactKey(factid).ToList().ToArray();
         *                          for (int fp_ix = 0; fp_ix < factkey.Length; fp_ix++)
         *                          {
         *                              var fp = factkey[fp_ix];
         *                              if (typestoreplaceids.ContainsKey(fp))
         *                              {
         *                                  factkey[fp_ix] = typestoreplaceids[fp];
         *                              }
         *                          }
         *
         *                          //p.Facts[f_ix] = newfactstring;
         *                          var instfact = instance.GetFactsByInstKey(factkey).FirstOrDefault();
         *                          var strkey = instfact != null ? instance.GetFactStringKey(instfact.InstanceKey) : "";
         *                          var inst_ix = instfact == null ? -1 : instfact.IX;
         *                          if (inst_ix == -1)
         *                          {
         *
         *                          }
         *                          p.FactIDs[f_ix] = String.Format("I:{0}", inst_ix);
         *
         *                          if (instfact!=null && Taxonomy.HasFact(instfact.TaxonomyKey))
         *                          {
         *                              var cellist = new List<string>();
         *                              p.Cells.Add(cellist);
         *                              var cells = Taxonomy.GetCellsOfFact(instfact.TaxonomyKey);
         *                              cellist.Clear();
         *                              foreach (var cell in cells)
         *                              {
         *                                  cellist.Add(instance.GetDynamicCellID(cell, instfact));
         *                              }
         *                          }
         *
         *                      }
         *                  }
         *
         *              }
         *          }
         *      }
         *
         *  }
         *  allinstanceresults = allresults;
         *  foreach (var r in resultstoremove)
         *  {
         *      allinstanceresults.Remove(r);
         *
         *  }
         *  allinstanceresults.AddRange(resultstoadd);
         *  foreach (var result in allinstanceresults)
         *  {
         *      foreach (var p in result.Parameters)
         *      {
         *          if (p.Cells.Any(c1 => c1.Any(c2 => c2.Contains(Literals.DynamicCode))))
         *          {
         *              for (int i = 0; i < p.FactIDs.Count;i++ )
         *              {
         *                  var cells = p.Cells[i];
         *                  var fid = p.FactIDs[i];
         *                  var fk = instance.GetFactKeyByIndexString(fid);
         *                  var dcells = instance.GetDynamicCellID(cells.FirstOrDefault(), fk);
         *                  cells.Clear();
         *                  cells.Add(dcells );
         *
         *              }
         *          }
         *          var mFactIDs = p.FactIDs.ToList();
         *          var ix=0;
         *          foreach (var factidentfier in p.FactIDs)
         *          {
         *              var parts = factidentfier.Split(":");
         *              if (parts[0] == "T")
         *              {
         *                  var tix = Utilities.Converters.FastParse(parts[1]);
         *                  var taxkey = instance.Taxonomy.FactsManager.GetFactKey(tix);
         *                  var facts = instance.GetFactsByTaxKey(taxkey);
         *                  if (facts.Count==1)
         *                  {
         *                      var fact = facts.FirstOrDefault();
         *                      mFactIDs[ix] = string.Format("I:{0}", fact.IX);
         *                  }
         *              }
         *              ix++;
         *          }
         *          p.FactIDs = mFactIDs;
         *      }
         *  }
         *
         *  return allinstanceresults;
         * }
         */
        public void ValidateResult(ValidationRuleResult result, Instance instance)
        {
            var HasAtLeastOneValue = false;
            var HasMissingValue    = false;

            foreach (var p in result.Parameters)
            {
                var rp = Parameters.FirstOrDefault(i => i.Name == p.Name);
                if (rp.IsGeneral)
                {
                    if (rp.StringValue == "filingindicators" && rp.BindAsSequence)
                    {
                        rp.StringValues = instance.FilingIndicators.Select(i => i.ID).ToArray();
                        rp.StringValue  = Utilities.Strings.ArrayToString(rp.StringValues);
                    }
                    continue;
                }

                rp.CurrentFacts.Clear();
                rp.StringValue = "";
                if (rp.BindAsSequence)
                {
                    var facts = new List <InstanceFact>();

                    foreach (var factstring in p.FactIDs)
                    {
                        var factininstance = instance.GetFactByIDString(factstring);
                        if (factininstance != null)
                        {
                            facts.Add(factininstance);
                        }
                        else
                        {
                        }
                    }
                    if (facts.Count > 0)
                    {
                        HasAtLeastOneValue = true;
                    }

                    //facts = Getf p.Facts;
                    var instancefacts = facts; // GetInstanceFacts(facts);
                    //set the cells

                    rp.CurrentFacts.AddRange(instancefacts.ToArray());
                    var stringvalues = instancefacts.Select(i => i.Value);
                    var decimals     = instancefacts.Select(i => i.Decimals).ToArray();

                    if (rp.Type == TypeEnum.String)
                    {
                        rp.StringValues = stringvalues.ToArray(); //GetValues(parameterfactgroup.Facts).ToArray();
                        rp.StringValue  = Utilities.Strings.ArrayToString(rp.StringValues);
                    }
                    if (rp.Type == TypeEnum.Numeric)
                    {
                        rp.DecimalValues = stringvalues.Select(i => LogicalModel.Validation.Functions.GetNumber(i)).ToArray();// GetValues(parameterfactgroup.Facts).Select(i => double.Parse(i)).ToArray();
                        rp.StringValue   = Utilities.Strings.ArrayToString(rp.DecimalValues);
                        rp.Decimals      = decimals;
                    }
                    if (rp.Type == TypeEnum.Boolean)
                    {
                        rp.StringValues = stringvalues.ToArray(); //GetValues(parameterfactgroup.Facts).ToArray();
                        rp.StringValue  = Utilities.Strings.ArrayToString(rp.StringValues);
                    }
                }
                else
                {
                    if (p.FactIDs.Count > 0)
                    {
                        var fact = instance.GetFactByIDString(p.FactIDs.FirstOrDefault());
                        if (fact != null)
                        {
                            var instancefacts = new List <InstanceFact>()
                            {
                                fact
                            };
                            var factkey = fact.GetFactKey();


                            HasAtLeastOneValue = true;
                            InstanceFact realfact = instancefacts.FirstOrDefault();

                            rp.CurrentFacts.Add(realfact);
                            rp.StringValue  = realfact.Value;
                            rp.StringValues = new string[] { realfact.Value };
                            rp.Decimals     = new string[] { realfact.Decimals };

                            //		Decimal.MaxValue	79228162514264337593543950335	decimal
                            if (rp.Type == TypeEnum.Numeric)
                            {
                                if (rp.StringValue.Length > 29 || !Utilities.Strings.IsNumeric(rp.StringValue))
                                {
                                    //var cells = Utilities.Strings.ArrayToString(rp.CurrentCells.ToArray());
                                    Logger.WriteLine(String.Format("Invalid Value Detected at {2}: {0} Cells: {1}", rp.StringValue, "", this.ID));
                                    rp.StringValue = "";
                                    return;
                                }
                            }
                        }
                    }
                }
                if (String.IsNullOrEmpty(rp.StringValue.Trim()))
                {
                    HasMissingValue = true;
                }
                if (!HasAtLeastOneValue)
                {
                }
                p.Value = rp.StringValue;
            }

            if (HasAtLeastOneValue && !HasMissingValue)
            {
                Boolean partialresult = true;

                //var formula = Taxonomy.SimpleValidationRules.FirstOrDefault(i => i.ID == this.ID);
                try
                {
                    partialresult = Function(Parameters);
                }
                catch (Exception ex)
                {
                    if (ex is DivideByZeroException)
                    {
                        partialresult = false;
                    }
                }
                if (!partialresult)
                {
                    if (this.ID.Contains("-bi"))
                    {
                    }
                    result.ID   = this.ID;
                    result.IsOk = false;
                    var me       = this;
                    var allfinds = new List <string>();
                    foreach (var table in this.Tables)
                    {
                        var tbl = Taxonomy.Tables.FirstOrDefault(i => i.ID == table);

                        allfinds.Add(tbl.FilingIndicator);
                    }
                    allfinds = allfinds.Distinct().ToList();
                    var isok = true;
                    foreach (var find in allfinds)
                    {
                        var hasdata = false;
                        var tg      = Taxonomy.Module.TableGroups.FirstOrDefault(i => i.Item.FilingIndicator == find);
                        if (tg != null)
                        {
                            foreach (var tableid in tg.Item.TableIDs)
                            {
                                var tbl = Taxonomy.Tables.FirstOrDefault(i => i.ID == tableid);

                                if (tbl.InstanceFactsCount > 0)
                                {
                                    hasdata = true;
                                    break;
                                }
                            }
                        }
                        if (!hasdata)
                        {
                            isok = false;
                            break;
                        }
                    }
                    result.HasAllFind = isok ? "1" : "2";
                }
            }
        }
示例#11
0
        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);
        }
        public static List <ValidationRuleResult> ExpandResult(Taxonomy taxonomy, Dictionary <int, int[]> factkeydict, ValidationRuleResult ruleresult, List <int> groupaspects)
        {
            var result = new List <ValidationRuleResult>();
            var rule   = taxonomy.ValidationRules.FirstOrDefault(i => i.ID == ruleresult.ID);
            var ruleparameterdictionary       = rule.Parameters.ToDictionary(i => i.Name);
            var ruleresultparameterdictionary = ruleresult.Parameters.ToDictionary(i => i.Name);
            var factparameterids = ruleparameterdictionary.Where(i => !i.Value.IsGeneral).Select(i => i.Key).ToList();

            //get the projection
            var projections = new Dictionary <int[], Dictionary <string, List <int[]> > >(new IntArrayEqualityComparer());

            foreach (var parmaeterid in factparameterids)
            {
                var rulep = ruleparameterdictionary[parmaeterid];
                var p     = ruleresultparameterdictionary[parmaeterid];

                foreach (var fact in p.FactIDs)
                {
                    var factid      = Utilities.Converters.FastParse(fact.Substring(2));
                    var taxonomykey = factkeydict[factid];
                    var key         = GetPartsOfMainParts(taxonomy, taxonomykey, groupaspects);
                    var keyarray    = key.ToArray();
                    if (!projections.ContainsKey(keyarray))
                    {
                        projections.Add(keyarray, new Dictionary <string, List <int[]> >());
                    }
                    var paramdict = projections[keyarray];
                    if (!paramdict.ContainsKey(parmaeterid))
                    {
                        paramdict.Add(parmaeterid, new List <int[]>());
                    }
                    paramdict[parmaeterid].Add(taxonomykey);
                }
            }

            //doing the implicit filtering
            var ic = new IntArrayComparer();

            if (projections.Count > 0)
            {
                foreach (var projectionkey in projections)
                {
                    var projectedresult = ruleresult.Copy();
                    result.Add(projectedresult);

                    foreach (var p in projectedresult.Parameters)
                    {
                        //var pfacts = ruleresult.Parameters.FirstOrDefault(i => i.Name == p.Name).InstanceFacts;
                        //var facts = pfacts.Where(i => ic.Contains(i.InstanceKey, projectionkey));
                        var paramdict = projections[projectionkey.Key];

                        if (paramdict.ContainsKey(p.Name))
                        {
                            var facts = paramdict[p.Name];
                            p.FactIDs = facts.Select(i => String.Format("T:{0}", taxonomy.FactsManager.GetFactIndex(i))).ToList();
                            p.InstanceFacts.Clear();
                            //p.InstanceFacts = facts.ToList();
                        }
                        else
                        {
                            p.FactIDs.Clear();
                            p.InstanceFacts.Clear();
                            p.Value = ruleparameterdictionary[p.Name].FallBackValue;
                        }
                    }
                    //SetCells(instance, projectedresult);
                }
            }
            else
            {
                result.Add(ruleresult);
            }
            return(result);
        }
        public static List <int> GetUncoveredDomains(Taxonomy taxonomy, Dictionary <int, int[]> factkeydict, ValidationRuleResult ruleresult)
        {
            var result = new List <int>();
            var rule   = taxonomy.ValidationRules.FirstOrDefault(i => i.ID == ruleresult.ID);
            var ruleparameterdictionary       = rule.Parameters.ToDictionary(i => i.Name);
            var ruleresultparameterdictionary = ruleresult.Parameters.ToDictionary(i => i.Name);
            var factparameterids        = ruleparameterdictionary.Where(i => !i.Value.IsGeneral).Select(i => i.Key).ToList();
            var mainaspectsofparameters = new List <List <int> >();

            var factindexes = rule.Parameters.SelectMany(i => i.TaxFacts).SelectMany(i => i).OrderBy(i => i).ToList();

            foreach (var factindex in factindexes)
            {
                var key = taxonomy.FactsManager.GetFactKey(factindex);
                if (!factkeydict.ContainsKey(factindex))
                {
                    factkeydict.Add(factindex, null);
                }
                factkeydict[factindex] = key;
            }


            foreach (var parmaeterid in factparameterids)
            {
                var rulep       = ruleparameterdictionary[parmaeterid];
                var p           = ruleresultparameterdictionary[parmaeterid];
                var mainaspects = new HashSet <int>();
                foreach (var fact in p.FactIDs)
                {
                    var factid      = Utilities.Converters.FastParse(fact.Substring(2));
                    var taxonomykey = factkeydict[factid];
                    foreach (var part in taxonomykey)
                    {
                        var mainaspectid = taxonomy.DimensionDomainsOfMembers.ContainsKey(part) ? taxonomy.DimensionDomainsOfMembers[part] : part;

                        if (!mainaspects.Contains(mainaspectid))
                        {
                            mainaspects.Add(mainaspectid);
                        }
                    }
                }

                var aspectsofparameter = mainaspects.Except(rulep.CoveredParts).ToList();
                //aspectsofparameter = aspectsofparameter.Except(rule.CoveredParts).ToList();
                mainaspectsofparameters.Add(aspectsofparameter);
            }
            List <int> commonmainaspects = null;

            foreach (var parameteraspects in mainaspectsofparameters)
            {
                if (commonmainaspects == null)
                {
                    commonmainaspects = parameteraspects.ToList();
                }
                else
                {
                    commonmainaspects = commonmainaspects.Intersect(parameteraspects).ToList();
                }
            }

            result = commonmainaspects;

            return(result);
        }