Example #1
0
        public override List <ValidationRuleResult> GetAllInstanceResults(Instance instance)
        {
            var taxonomy   = instance.Taxonomy;
            var allresults = GetAllResults();
            var results    = new List <ValidationRuleResult>();

            ValidationRuleHelper.LoadTypedFacts(instance, allresults);

            var instanceresults = ValidationRuleHelper.ExecuteImplicitFiltering(instance, allresults);

            ValidationRuleHelper.SetCells(instance, instanceresults);

            results = instanceresults;
            return(results);
        }
Example #2
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 void ExecuteExplicitFiltering(Taxonomy taxonomy, ValidationRule rule)
        {
            if (rule.ID.Contains("es_v308"))
            {
            }
            var          tables           = rule.Tables.Select(i => taxonomy.Tables.FirstOrDefault(t => t.ID == i)).ToList();
            IntervalList tableintevallist = null;

            foreach (var table in tables)
            {
                tableintevallist = tableintevallist == null ? new IntervalList() : tableintevallist;
                tableintevallist = Utilities.Objects.MergeSorted(tableintevallist, table.FactindexList, null);
                //tableintevallist.Clear();
            }
            var         hastableinfo        = tableintevallist != null ? tableintevallist.Count > 0 : false;
            IList <int> allfactsintevallist = new IntervalList(0, taxonomy.FactsManager.FactsOfPages.Count);

            if (hastableinfo)
            {
                allfactsintevallist = tableintevallist;
            }
            var ruletypeddimension = rule.BaseQuery.DictFilterIndexes.Where(i => taxonomy.IsTyped(i));

            foreach (var parameter in rule.Parameters)
            {
                parameter.TaxFacts.Clear();
                IList <int> sdata = tableintevallist;
                if (!parameter.IsGeneral)
                {
                    if (parameter.BaseQuery.DictFilterIndexes.Count == 0)
                    {
                        sdata = allfactsintevallist;
                    }
                    parameter.Data            = parameter.BaseQuery.ToIntervalList(taxonomy.FactsOfParts, sdata);
                    parameter.TypedDimensions = parameter.BaseQuery.DictFilterIndexes.Where(i => taxonomy.IsTyped(i)).ToList();
                    parameter.TypedDimensions = parameter.TypedDimensions.Concat(ruletypeddimension).Distinct().ToList();
                    parameter.CoveredParts    = parameter.BaseQuery.GetAspects(taxonomy);
                    if (parameter.FallBackValue == "()"
                        /*&& parameter.TypedDimensions.Count>0 */
                        && !parameter.BindAsSequence)
                    {
                        parameter.BindAsSequence = true;
                    }
                }
            }
            bool        hasfacts = false;
            var         ix       = 0;
            IList <int> data     = tableintevallist;

            if (rule.BaseQuery.DictFilterIndexes.Count == 0)
            {
                data = allfactsintevallist;
            }
            rule.TypedDimensions = rule.BaseQuery.DictFilterIndexes.Where(i => taxonomy.IsTyped(i)).ToList();
            rule.CoveredParts    = rule.BaseQuery.GetAspects(taxonomy);

            var singlefactparameters = rule.Parameters.Where(i => !i.IsGeneral && !i.BindAsSequence).ToList();
            var multifactparameters  = rule.Parameters.Where(i => !i.IsGeneral && i.BindAsSequence).ToList();

            //Utilities.Logger.WriteToFile(String.Format("EnumerateIntervals {0} on {1}", rule.BaseQuery, data));

            foreach (var group in rule.BaseQuery.EnumerateIntervals(taxonomy.FactsOfParts, 0, data, false))
            {
                //Utilities.Logger.WriteToFile("Joining rule with parameters...");
                foreach (var parameter in rule.Parameters)
                {
                    if (!parameter.IsGeneral)
                    {
                        IntervalList facts = (IntervalList)Utilities.Objects.IntersectSorted(parameter.Data, group, null);
                        //var facts = factsq.ToList();
                        if (facts.Count > 0)
                        {
                            hasfacts = true;
                        }
                        else
                        {
                        }
                        parameter.TaxFacts.Add(facts.ToList());
                    }
                }

                ix++;
                //Utilities.Logger.WriteToFile("End joining rule with parameters");
            }
            ValidationRuleHelper.SetParamerterTypes(taxonomy, rule);
            if (!hasfacts)
            {
                Utilities.Logger.WriteLine(String.Format("{0}: Rule has no facts!", rule.ID));
            }
        }