Ejemplo n.º 1
0
        private static List <CalcLocalIdentity> GetDepIdsInSharedFormulaRange(CalcCalculationManager mgr, CalcRangeIdentity sharedFormulaRange, CalcLocalIdentity dityId)
        {
            int num;
            int num2;
            int num3;
            int num4;
            int num5;
            int num6;
            int num7;
            int num8;
            List <CalcLocalIdentity> list = new List <CalcLocalIdentity>();

            LocalId2Index(sharedFormulaRange, out num, out num2, out num3, out num4);
            ReferencePredenceVisitor visitor = new ReferencePredenceVisitor(mgr.Source, num, num2);

            visitor.Visit(mgr.GetExpression(sharedFormulaRange), num, num2);
            Dictionary <CalcLocalIdentity, bool> predenceIds = visitor.PredenceIds;

            LocalId2Index(dityId, out num5, out num6, out num7, out num8);
            foreach (KeyValuePair <CalcLocalIdentity, bool> pair in predenceIds)
            {
                int num9;
                int num10;
                int num11;
                int num12;
                CalcRangeIdentity key = pair.Key as CalcRangeIdentity;
                if ((key != null) && (key.IsFullRow || key.IsFullColumn))
                {
                    list.Clear();
                    list.Add(sharedFormulaRange);
                    return(list);
                }
                LocalId2Index(pair.Key, out num9, out num10, out num11, out num12);
                int rowIndex    = (num5 > num11) ? ((num + num5) - num11) : num;
                int columnIndex = (num6 > num12) ? ((num2 + num6) - num12) : num2;
                int num15       = (num + num7) - num9;
                num15 = (num15 > num3) ? num3 : num15;
                int num16 = (num2 + num8) - num10;
                num16 = (num16 > num4) ? num4 : num16;
                if (((rowIndex <= num3) && (num15 >= num)) && ((columnIndex <= num4) && (num16 >= num2)))
                {
                    if (!pair.Value)
                    {
                        list.Clear();
                        list.Add(sharedFormulaRange);
                        return(list);
                    }
                    CalcRangeIdentity item = new CalcRangeIdentity(rowIndex, columnIndex, (num15 - rowIndex) + 1, (num16 - columnIndex) + 1);
                    if (!list.Contains(item))
                    {
                        list.Add(item);
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the calculation manager.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="formulaStorage">The formula storage.</param>
        /// <param name="autoCreate">if set to <see langword="true" /> [auto create].</param>
        /// <returns></returns>
        public CalcCalculationManager GetCalculationManager(ICalcSource source, ICalcStorage <CalcLocalIdentity, CalcExpression> formulaStorage = null, bool autoCreate = true)
        {
            CalcCalculationManager manager;

            if (object.ReferenceEquals(source, null))
            {
                throw new ArgumentNullException("source");
            }
            if ((!this._calcManagers.TryGetValue(source, out manager) || object.ReferenceEquals(manager, null)) && autoCreate)
            {
                this._calcManagers[source] = manager = new CalcCalculationManager(this, source, formulaStorage);
                manager.UpdateStorage();
            }
            return(manager);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Recalculates this instance.
        /// </summary>
        /// <param name="maxCalcCount">The max iterator.</param>
        /// <param name="forceRecalculateAll">Whether force recalculate all formula in current manager.</param>
        /// <returns><see langword="true" /> if all dirty nodes have been recalculated, otherwise, <see langword="false" /></returns>
        public bool Recalculate(int maxCalcCount = 0xc350, bool forceRecalculateAll = false)
        {
            if (forceRecalculateAll)
            {
                this.ClearDirtyItem();
                foreach (CalcCalculationManager manager in this._calcManagers.Values)
                {
                    if (manager.FormulaCount > 0)
                    {
                        manager.InvalidateAllIdentity();
                        maxCalcCount += manager.FormulaCount;
                    }
                }
            }
            int num = 0;

            while ((this._headerDirtyItems != null) && (num < maxCalcCount))
            {
                DirtyItem dirtyItem        = this._headerDirtyItems;
                CalcCalculationManager mgr = this.GetCalculationManager(dirtyItem.Source, null, true);
                this.EvaluateFormula(mgr, dirtyItem);
                CalcNode objA = dirtyItem.Node;
                if (object.ReferenceEquals(objA, null))
                {
                    objA = mgr.Graph.GetNode(dirtyItem.Id);
                }
                if (!object.ReferenceEquals(objA, null))
                {
                    objA.ClearDirty();
                    if (dirtyItem == this._headerDirtyItems)
                    {
                        this.RemoveDirtyItem(dirtyItem);
                    }
                }
                else
                {
                    this.RemoveDirtyItem(dirtyItem);
                }
                num++;
            }
            return(num < maxCalcCount);
        }
Ejemplo n.º 4
0
        internal void DisposeCalculationManager(CalcCalculationManager mgr)
        {
            ICalcSource key = mgr.Source;

            if (key != null)
            {
                DirtyItem nextItem;
                if (this._calcManagers.ContainsKey(key))
                {
                    this._calcManagers.Remove(key);
                }
                for (DirtyItem item = this._headerDirtyItems; item != null; item = nextItem)
                {
                    nextItem = item.NextItem;
                    if (item.Source == key)
                    {
                        this.RemoveDirtyItem(item);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// hdt 唐忠宝增加
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="node"></param>
 public DirtyItem(CalcCalculationManager manager, CalcNode node)
 {
     this.Manager = manager;
     this.Node    = node;
 }
Ejemplo n.º 6
0
        internal bool EvaluateFormula(CalcCalculationManager mgr, DirtyItem dirtyItem)
        {
            CalcLocalIdentity id = dirtyItem.Id as CalcLocalIdentity;

            if (object.ReferenceEquals(id, null))
            {
                return(false);
            }
            CalcExpression objA = mgr.GetExpression(id);

            if (object.ReferenceEquals(objA, null))
            {
                return(false);
            }
            ICalcSource source = mgr.Source;
            Dictionary <CalcLocalIdentity, CalcExpression> dictionary = new Dictionary <CalcLocalIdentity, CalcExpression>();

            if ((id is CalcRangeIdentity) && mgr.Graph.IsSharedFormula(id as CalcRangeIdentity))
            {
                List <CalcLocalIdentity> dirtySubIds = new List <CalcLocalIdentity>();
                SharedFormulaDirtyItem   item        = dirtyItem as SharedFormulaDirtyItem;
                if ((item != null) && !item.IsFullRangeDirty)
                {
                    dirtySubIds = (dirtyItem as SharedFormulaDirtyItem).DirtySubIds;
                }
                else
                {
                    dirtySubIds.Add(id);
                }
                foreach (CalcLocalIdentity identity3 in dirtySubIds)
                {
                    int  num;
                    int  num2;
                    int  num3;
                    int  num4;
                    bool flag;
                    CalcRangeIdentity identity4 = identity3 as CalcRangeIdentity;
                    CalcReferenceHelper.Id2Range(source, identity3, out num, out num2, out num3, out num4, out flag);
                    for (int i = num; i < (num + num3); i++)
                    {
                        for (int j = num2; j < (num2 + num4); j++)
                        {
                            if ((identity4 != null) && (identity4.IsFullRow || identity4.IsFullColumn))
                            {
                                new FullBandMappingVisitor(identity4.IsFullRow, identity4.IsFullRow ? i : j).Visit(objA, 0, 0);
                            }
                            CalcCellIdentity identity5  = new CalcCellIdentity(i, j);
                            CalcExpression   expression = mgr.GetExpression(identity5);
                            if (((expression != null) && (expression == objA)) && !mgr.Graph.IsIsIntersectantWithArrayFormula(identity5))
                            {
                                dictionary[identity5] = objA;
                            }
                        }
                    }
                }
            }
            else
            {
                dictionary.Add(id, objA);
            }
            foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair in dictionary)
            {
                id = pair.Key;
                object obj2 = mgr.Evaluator.Evaluate(pair.Value, source.GetEvaluatorContext(id));
                while (!(id is CalcRangeIdentity) && ((obj2 is CalcReference) || (obj2 is CalcArray)))
                {
                    if (obj2 is CalcReference)
                    {
                        obj2 = ExtractValueFromReference(id, obj2);
                    }
                    if (obj2 is CalcArray)
                    {
                        obj2 = (obj2 as CalcArray).GetValue(0);
                    }
                }
                source.SetValue(id, obj2);
            }
            return(true);
        }