示例#1
0
 /// <summary>
 /// hdt 唐忠宝增加
 /// </summary>
 /// <param name="depNode"></param>
 internal void CreateDirtyItem(CalcNode depNode)
 {
     if (object.ReferenceEquals(depNode.Source, this.Source))
     {
         depNode.DirtyItem = new DirtyItem(this, depNode);
     }
     else
     {
         CalcGraph graph = this.Service.GetCalculationManager(depNode.Source, null, true).Graph;
         depNode.DirtyItem = new DirtyItem(graph.Manager, graph.GetNode(depNode.Id as CalcLocalIdentity));
     }
 }
示例#2
0
        /// <summary>
        /// hdt 唐忠宝增加
        /// </summary>
        /// <param name="id"></param>
        /// <param name="context"></param>
        /// <param name="node"></param>
        private void Invalidate(CalcLocalIdentity id, CalcEvaluatorContext context, CalcNode node = null)
        {
            DirtyItem header   = null;
            DirtyItem tailItem = null;

            this.InvalidateIntersecteds(id, context, node, ref header, ref tailItem);
            foreach (CalcNode node2 in this.Graph.GetAllVolantedNodes())
            {
                this.InvalidateIntersecteds(node2.Id as CalcLocalIdentity, context, node2, ref header, ref tailItem);
            }
            if (header != null)
            {
                this.InvalidateDependencies(ref header, ref tailItem);
            }
        }
示例#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);
        }
示例#4
0
        /// <summary>
        /// hdt 唐忠宝增加
        /// </summary>
        /// <param name="id"></param>
        /// <param name="context"></param>
        /// <param name="node"></param>
        /// <param name="header"></param>
        /// <param name="tailItem"></param>
        private void InvalidateIntersecteds(CalcLocalIdentity id, CalcEvaluatorContext context, CalcNode node, ref DirtyItem header, ref DirtyItem tailItem)
        {
            ICalcSource source = this.Source;

            if (node == null)
            {
                node = this.Graph.GetNode(id);
            }
            if (!object.ReferenceEquals(node, null))
            {
                if (node.DirtyItem != null)
                {
                    return;
                }
                if (node.DirtyItem == null)
                {
                    node.DirtyItem = new DirtyItem(this, node);
                }
                AddDirtyItem(ref header, ref tailItem, node.DirtyItem, null);
            }
            if (id is CalcCellIdentity)
            {
                foreach (CalcNode node2 in this.EnumerateIntersectedNodesExcludeSelf(id as CalcCellIdentity))
                {
                    if (((node2.Dependents != null) && (node2.Dependents.Count > 0)) && (node2.DirtyItem == null))
                    {
                        node2.DirtyItem = new DirtyItem(this, node2);
                        AddDirtyItem(ref header, ref tailItem, node2.DirtyItem, node);
                    }
                }
            }
            else
            {
                foreach (CalcNode node3 in this.Graph.EnumerateIntersectedNodesExcludeSelf(context, id))
                {
                    if (node3.DirtyItem == null)
                    {
                        node3.DirtyItem = new DirtyItem(this, node3);
                        AddDirtyItem(ref header, ref tailItem, node3.DirtyItem, node);
                    }
                }
            }
        }
示例#5
0
 /// <summary>
 /// Invalidates the specified id.
 /// </summary>
 /// <param name="id">The data address.</param>
 /// <param name="autoCalculate">if set to <see langword="true" /> automatically calculate immediately.</param>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="id" /> is <see langword="null" />.</exception>
 public void Invalidate(CalcLocalIdentity id, bool autoCalculate = true)
 {
     if (object.ReferenceEquals(id, null))
     {
         throw new ArgumentNullException("id");
     }
     if (!this.Graph.IsEmpty)
     {
         CalcNode objA = this.Graph.GetNode(id);
         if (!object.ReferenceEquals(objA, null))
         {
             objA.MarkAsDirty(this.Service, autoCalculate, true, true, true);
         }
         else if (objA == null)
         {
             CalcNode.CreateTempNode(this.Source, id).MarkAsDirty(this.Service, autoCalculate, true, true, true);
         }
         else
         {
             CalcCellIdentity identity = id as CalcCellIdentity;
             if (!object.ReferenceEquals(identity, null))
             {
                 foreach (CalcNode node2 in this.Graph.GetAllDependentRangeNodes(identity.RowIndex, identity.ColumnIndex, 1, 1))
                 {
                     node2.MarkAsDirty(this.Service, autoCalculate, false, true, true);
                 }
             }
             else
             {
                 CalcRangeIdentity identity2 = id as CalcRangeIdentity;
                 if (!object.ReferenceEquals(identity2, null))
                 {
                     if (identity2.IsFullColumn && identity2.IsFullRow)
                     {
                         this.InvalidateAllIdentity();
                         return;
                     }
                     if (!identity2.IsFullColumn && !identity2.IsFullRow)
                     {
                         foreach (CalcNode node3 in this.Graph.GetAllDependentRangeNodes(identity2.RowIndex, identity2.ColumnIndex, identity2.RowCount, identity2.ColumnCount))
                         {
                             node3.MarkAsDirty(this.Service, autoCalculate, true, true, true);
                         }
                         for (int i = 0; i < identity2.RowCount; i++)
                         {
                             for (int j = 0; j < identity2.ColumnCount; j++)
                             {
                                 CalcNode node = this.Graph.GetNode(new CalcCellIdentity(identity2.RowIndex + i, identity2.ColumnIndex + j));
                                 if (!object.ReferenceEquals(node, null))
                                 {
                                     node.MarkAsDirty(this.Service, autoCalculate, false, true, true);
                                 }
                             }
                         }
                     }
                     else
                     {
                         int columnIndex;
                         int columnCount;
                         if (identity2.IsFullColumn)
                         {
                             columnIndex = identity2.ColumnIndex;
                             columnCount = identity2.ColumnCount;
                         }
                         else
                         {
                             columnIndex = identity2.RowIndex;
                             columnCount = identity2.RowCount;
                         }
                         foreach (CalcNode node5 in this.Graph.GetBandDependentNodes(columnIndex, columnCount, identity2.IsFullRow))
                         {
                             node5.MarkAsDirty(this.Service, autoCalculate, true, true, true);
                         }
                         CalcReference reference = this.Evaluator.Evaluate(new CalcRangeExpression(columnIndex, columnCount, false, false, true), this.Source.GetEvaluatorContext(identity2)) as CalcReference;
                         if (!object.ReferenceEquals(reference, null) && (reference.RangeCount == 1))
                         {
                             for (int k = 0; k < reference.GetRowCount(0); k++)
                             {
                                 for (int m = 0; m < reference.GetColumnCount(0); m++)
                                 {
                                     CalcNode node6 = this.Graph.GetNode(new CalcCellIdentity(reference.GetRow(0) + k, reference.GetColumn(0) + m));
                                     if (!object.ReferenceEquals(node6, null))
                                     {
                                         node6.MarkAsDirty(this.Service, autoCalculate, false, true, true);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         foreach (CalcLocalIdentity identity3 in this.Graph.GetAllVolantedIdeneities())
         {
             this.Graph.EnsureNode(identity3, null).MarkAsDirty(this.Service, autoCalculate, true, true, true);
         }
         if (autoCalculate)
         {
             this.Service.Recalculate(0xc350, false);
         }
     }
 }
示例#6
0
        /// <summary>
        /// hdt 唐忠宝增加
        /// </summary>
        /// <param name="header"></param>
        /// <param name="tailItem"></param>
        private void GetAllDirtyItems(ref DirtyItem header, ref DirtyItem tailItem)
        {
            DirtyItem nextItem;
            DirtyItem removingItem = header;

            while (removingItem != null)
            {
                nextItem = removingItem.NextItem;
                DirtyItem previousItem = removingItem.PreviousItem;
                CalcNode  objB         = removingItem.Node;
                if (objB.NodeType != NodeType.None)
                {
                    objB.DirtyItem.DirtyFlag = true;
                }
                else
                {
                    objB.DirtyItem = null;
                    RemoveDirtyItem(ref header, ref tailItem, removingItem);
                }
                if ((objB.Dependents == null) || (objB.Dependents.Count == 0))
                {
                    removingItem = nextItem;
                }
                else
                {
                    foreach (KeyValuePair <CalcNode, CalcNode> pair in objB.Dependents)
                    {
                        if (((pair.Key.DirtyItem == null) && !object.ReferenceEquals(pair.Key, objB)) && ((pair.Key.Id is CalcCellIdentity) || (pair.Key.Id is CalcExternalCellIdentity)))
                        {
                            this.CreateDirtyItem(pair.Key);
                            AddDirtyItem(ref header, ref tailItem, pair.Key.DirtyItem, objB);
                            CalcLocalIdentity id    = pair.Key.Id as CalcLocalIdentity;
                            CalcGraph         graph = pair.Key.DirtyItem.Manager.Graph;
                            if (object.ReferenceEquals(id, null))
                            {
                                id = (pair.Key.Id as CalcExternalIdentity).ConvertToLocal();
                            }
                            foreach (CalcNode node2 in graph.Manager.EnumerateIntersectedNodesExcludeSelf(id as CalcCellIdentity))
                            {
                                node2.DirtyItem = new DirtyItem(this, node2);
                                AddDirtyItem(ref header, ref tailItem, node2.DirtyItem, pair.Key);
                            }
                        }
                    }
                    if (nextItem == null)
                    {
                        if ((previousItem == null) && (removingItem != header))
                        {
                            removingItem = header;
                        }
                        else if ((previousItem != null) && (removingItem != previousItem.NextItem))
                        {
                            removingItem = previousItem.NextItem;
                        }
                        else
                        {
                            removingItem = null;
                        }
                        continue;
                    }
                    removingItem = nextItem;
                }
            }
            for (removingItem = header; removingItem != null; removingItem = nextItem)
            {
                nextItem = removingItem.NextItem;
                CalcNode node = removingItem.Node;
                if (removingItem.Node.Dependents != null)
                {
                    foreach (KeyValuePair <CalcNode, CalcNode> pair2 in removingItem.Node.Dependents)
                    {
                        if ((pair2.Key.DirtyItem != null) && !object.ReferenceEquals(pair2.Key, node))
                        {
                            if (removingItem.DependencyCellTemp == null)
                            {
                                removingItem.DependencyCellTemp = new HashSet <CalcNode>();
                            }
                            if (!removingItem.DependencyCellTemp.Contains(pair2.Key))
                            {
                                removingItem.DependencyCellTemp.Add(pair2.Key);
                                pair2.Key.DirtyItem.PredencyItemCount++;
                            }
                        }
                    }
                }
            }
        }
示例#7
0
 /// <summary>
 /// hdt 唐忠宝增加
 /// </summary>
 /// <param name="header"></param>
 /// <param name="tailItem"></param>
 /// <param name="addingItem"></param>
 /// <param name="predencyNode"></param>
 private static void AddDirtyItem(ref DirtyItem header, ref DirtyItem tailItem, DirtyItem addingItem, CalcNode predencyNode)
 {
     if (header == null)
     {
         header = tailItem = addingItem;
     }
     else
     {
         addingItem.PreviousItem = tailItem;
         tailItem.NextItem       = addingItem;
         tailItem = addingItem;
     }
     if (!object.ReferenceEquals(predencyNode, null) && (predencyNode.DirtyItem != null))
     {
         DirtyItem dirtyItem = predencyNode.DirtyItem;
         if (dirtyItem.DependencyCellTemp == null)
         {
             dirtyItem.DependencyCellTemp = new HashSet <CalcNode>();
         }
         if (!dirtyItem.DependencyCellTemp.Contains(tailItem.Node))
         {
             dirtyItem.DependencyCellTemp.Add(tailItem.Node);
             tailItem.PredencyItemCount++;
         }
     }
 }
示例#8
0
 public SharedFormulaDirtyItem(CalcService service, ICalcSource source, CalcLocalIdentity id, CalcNode node) : base(service, source, id, node)
 {
     this.DirtySubIds  = new List <CalcLocalIdentity>();
     this.DirtySubIds2 = new List <CalcLocalIdentity>();
 }
示例#9
0
 public DirtyItem(CalcService service, ICalcSource source, CalcLocalIdentity id, CalcNode node)
 {
     this.Service = service;
     this.Source  = source;
     this.Id      = id;
     this.Node    = node;
 }
示例#10
0
 /// <summary>
 /// hdt 唐忠宝增加
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="node"></param>
 public DirtyItem(CalcCalculationManager manager, CalcNode node)
 {
     this.Manager = manager;
     this.Node    = node;
 }