Esempio n. 1
0
 public void SaveFacts(List <InstanceFact> factstosave)
 {
     if (factstosave == null)
     {
         factstosave = new List <InstanceFact>();
     }
     foreach (var fact in factstosave)
     {
         fact.SetFromString(fact.FactString);
         InstanceFact factitem = null;
         var          intkeys  = this.GetFactIntKey(fact.FactString);
         if (FactDictionary.FactsByInstanceKey.ContainsKey(intkeys))
         {
             var factsforkey = FactDictionary.FactsByInstanceKey[intkeys];
         }
         if (factitem == null)
         {
             FactDictionary.AddFact(fact);
             Facts.Add(fact);
             factitem = fact;
         }
         else
         {
             factitem.Value = fact.Value;
         }
     }
     SaveToJson();
 }
Esempio n. 2
0
        public List <string> GetCells(InstanceFact fact)
        {
            var taxfactkey = fact.TaxonomyKey;
            var cells      = Taxonomy.GetCellsOfFact(taxfactkey);
            var result     = new List <string>();

            foreach (var cell in cells)
            {
                String instancecell = "";
                if (fact != null)
                {
                    instancecell = GetDynamicCellID(cell, fact);
                }

                if (!String.IsNullOrEmpty(instancecell))
                {
                    result.Add(instancecell);
                }
                else
                {
                    result.Add(cell);
                }
            }
            return(result);
        }
Esempio n. 3
0
        public InstanceFact GetFactByIDStringForCell(string factstring)
        {
            var t = factstring[0];

            if (t == 'I')
            {
                var id = Utilities.Converters.FastParse(factstring.Substring(2));
                if (id > -1 && id < this.Facts.Count)
                {
                    return(this.Facts[id]);
                }
            }
            else
            {
                var id  = Utilities.Converters.FastParse(factstring.Substring(2));
                var key = Taxonomy.FactsManager.GetFactKey(id);

                if (FactDictionary.FactsByTaxonomyKey.ContainsKey(key))
                {
                    var facts = FactDictionary.FactsByTaxonomyKey[key];
                    if (facts.Count == 1)
                    {
                        var ix = facts.FirstOrDefault();
                        return(FactDictionary.FactsByIndex[ix]);
                    }
                }
                var taxfact = new InstanceFact();
                taxfact.TaxonomyKey = key;
                return(taxfact);
            }
            return(null);
        }
Esempio n. 4
0
        public void AddFact(InstanceFact fact)
        {
            var ix = FactsByIndex.Count;

            fact.IX = ix;
            FactsByIndex.Add(ix, fact);
            //InstIndexToTaxIndex.Add(ix, this.Instance.Taxonomy.FactsManager.GetFactIndex(fact.TaxonomyKey));
            if (Instance.Contexts.Items.ContainsKey(fact.ContextID))
            {
                var instancecontext = Instance.Contexts.Items[fact.ContextID];
                var partcount       = instancecontext.DimensionIds.Count + 1;
                var taxfactkeylist  = new List <int>(partcount);
                var instfactkeylist = new List <int>(partcount);
                var conceptid       = Instance.GetPartID(fact.Concept.Content);

                if (instancecontext.DimensionIds != null)
                {
                    foreach (var id in instancecontext.DimensionIds)
                    {
                        instfactkeylist.Add(id);
                        var taxid = id;
                        if (Instance.CounterTypedFactMembers.ContainsKey(id))
                        {
                            taxid = Instance.CounterTypedFactMembers[id];
                        }
                        taxfactkeylist.Add(taxid);
                    }
                }
                //taxfactkeylist = taxfactkeylist.OrderBy(i => i).ToList();
                //instfactkeylist = instfactkeylist.OrderBy(i => i).ToList();

                taxfactkeylist.Insert(0, conceptid);
                instfactkeylist.Insert(0, conceptid);

                var taxfactkey  = taxfactkeylist.ToArray();
                var instfactkey = instfactkeylist.ToArray();
                if (!this.FactsByInstanceKey.ContainsKey(instfactkey))
                {
                    this.FactsByInstanceKey.Add(instfactkey, ix);
                }
                if (!this.FactsByTaxonomyKey.ContainsKey(taxfactkey))
                {
                    this.FactsByTaxonomyKey.Add(taxfactkey, new List <int>());
                }
                this.FactsByTaxonomyKey[taxfactkey].Add(ix);
                fact.InstanceKey = instfactkey;
                fact.TaxonomyKey = taxfactkey;
            }
            else
            {
                Utilities.Logger.WriteLine(String.Format("Context {0} not found!", fact.ContextID));
            }
        }
Esempio n. 5
0
        public List <int> GetTypedPartIds(InstanceFact fact)
        {
            var result = new List <int>();

            for (int i = 0; i < fact.TaxonomyKey.Length; i++)
            {
                if (TypedFactMembers.ContainsKey(fact.TaxonomyKey[i]))
                {
                    result.Add(fact.InstanceKey[i]);
                }
            }
            return(result);
        }
Esempio n. 6
0
        public string GetDynamicCellID(string cellID, InstanceFact fact)
        {
            var dynamiccellID = cellID;

            var cellobj = new Cell();

            cellobj.SetFromCellID(cellID);
            if (cellobj.IsDynamic)
            {
                var reportid = cellobj.Report;

                if (DynamicReportCells.ContainsKey(reportid))
                {
                    var dynamicdata = DynamicReportCells[reportid];
                    if (dynamicdata != null)
                    {
                        if (this.FactDictionary.FactsByInstanceKey.ContainsKey(fact.InstanceKey))
                        {
                            var ifactix  = this.FactDictionary.FactsByInstanceKey[fact.InstanceKey];
                            var ifact    = this.FactDictionary.FactsByIndex[ifactix];
                            var cells    = ifact.Cells;
                            var cellid   = "";
                            var cellobjs = cells.Select(s => { var cellobject = new Cell(); cellobject.SetFromCellID(s); return(cellobject); }).ToList();
                            cellobjs = cellobjs.Where(i => i.Report == cellobj.Report).ToList();
                            cellid   = cellobjs.Count > 0 ? cellobjs.FirstOrDefault().CellID : "";
                            if (string.IsNullOrEmpty(cellid))
                            {
                                return("");
                            }
                            cellobj.SetFromCellID(cellid);
                        }
                    }
                    else
                    {
                        Logger.WriteLine("No Dynamic Data found for " + reportid);
                    }
                }
            }
            return(cellobj.CellID);
        }