Exemplo n.º 1
0
        internal void ResumeCalcGraph()
        {
            Exception      exception = null;
            CalcExpression expr      = null;

            foreach (KeyValuePair <CalcLocalIdentity, Tuple <CalcExpression, bool> > pair in this._tmpFormulas)
            {
                CalcLocalIdentity key = pair.Key;
                expr = pair.Value.Item1;
                try
                {
                    this.Graph.SetNode(key, expr, this.Source.GetEvaluatorContext(key), this.Source, pair.Value.Item2);
                    this._formulas[key] = expr;
                }
                catch (Exception exception2)
                {
                    if (exception == null)
                    {
                        exception = exception2;
                    }
                }
            }
            this._tmpFormulas.Clear();
            if (exception != null)
            {
                throw exception;
            }
        }
Exemplo n.º 2
0
 public DirtyItem(CalcService service, ICalcSource source, CalcLocalIdentity id, CalcNode node)
 {
     this.Service = service;
     this.Source  = source;
     this.Id      = id;
     this.Node    = node;
 }
Exemplo n.º 3
0
        private void GetBaseIndex(CalcLocalIdentity lid, out int row, out int column)
        {
            CalcCellIdentity objA = lid as CalcCellIdentity;

            if (!object.ReferenceEquals(objA, null))
            {
                row    = objA.RowIndex;
                column = objA.ColumnIndex;
            }
            else
            {
                CalcRangeIdentity identity2 = lid as CalcRangeIdentity;
                if (!object.ReferenceEquals(identity2, null))
                {
                    row    = identity2.RowIndex;
                    row    = (row < 0) ? 0 : row;
                    column = identity2.ColumnIndex;
                    column = (column < 0) ? 0 : column;
                }
                else
                {
                    row    = -1;
                    column = -1;
                }
            }
        }
Exemplo n.º 4
0
 private static object ExtractValueFromReference(CalcLocalIdentity localId, object value)
 {
     for (CalcReference reference = value as CalcReference; (reference != null) && !(localId is CalcRangeIdentity); reference = value as CalcReference)
     {
         CalcCellIdentity objA = localId as CalcCellIdentity;
         int rowCount          = reference.GetRowCount(0);
         int columnCount       = reference.GetColumnCount(0);
         if (((reference.RangeCount <= 0) || (rowCount <= 0)) || (columnCount <= 0))
         {
             value = CalcErrors.Reference;
         }
         else
         {
             try
             {
                 if (!object.ReferenceEquals(objA, null))
                 {
                     if ((reference.RangeCount != 1) || ((rowCount > 1) && (columnCount > 1)))
                     {
                         value = CalcErrors.Value;
                     }
                     else
                     {
                         int rowOffset    = objA.RowIndex - reference.GetRow(0);
                         int columnOffset = objA.ColumnIndex - reference.GetColumn(0);
                         if ((rowCount == 1) && (columnCount == 1))
                         {
                             value = reference.GetValue(0, 0, 0);
                         }
                         else if (((rowCount == 1) && (columnCount > 1)) && ((columnOffset >= 0) && (columnOffset < columnCount)))
                         {
                             value = reference.GetValue(0, 0, columnOffset);
                         }
                         else if (((rowCount > 1) && (columnCount == 1)) && ((rowOffset >= 0) && (rowOffset < rowCount)))
                         {
                             value = reference.GetValue(0, rowOffset, 0);
                         }
                         else
                         {
                             value = CalcErrors.Value;
                         }
                     }
                 }
                 else
                 {
                     value = reference.GetValue(0, 0, 0);
                 }
             }
             catch (InvalidCastException)
             {
                 value = CalcErrors.Value;
             }
         }
     }
     return(value);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Gets the value at specified position which indicated by <paramref name="id" />.
 /// </summary>
 /// <param name="id">A <see cref="T:Dt.CalcEngine.CalcIdentity" /> indicates the identity of a address.</param>
 /// <returns>
 /// An <see cref="T:System.Object" /> indicates the value.
 /// If the <paramref name="id" /> is not recognized, return <see cref="F:Dt.CalcEngine.CalcErrors.Reference" />.
 /// </returns>
 public virtual object GetValue(CalcIdentity id)
 {
     if (id is CalcExternalIdentity)
     {
         CalcExternalIdentity identity = id as CalcExternalIdentity;
         ICalcSource          source   = identity.Source;
         if (source != null)
         {
             CalcLocalIdentity identity3;
             CalcLocalIdentity identity2 = identity.ConvertToLocal();
             if ((this.ArrayFormulaMode || (this.RowCount > 1)) || (this.ColumnCount > 1))
             {
                 identity3 = new CalcRangeIdentity(this.Row, this.Column, this.RowCount, this.ColumnCount);
             }
             else
             {
                 identity3 = new CalcCellIdentity(this.Row, this.Column);
             }
             return(source.GetEvaluatorContext(identity3).GetValue(identity2));
         }
     }
     else if ((this.Source != null) && (id is CalcLocalIdentity))
     {
         CalcRangeIdentity objA = id as CalcRangeIdentity;
         if (object.ReferenceEquals(objA, null))
         {
             return(this.Source.GetValue(id as CalcLocalIdentity));
         }
         if (objA._isFullColumn && objA._isFullRow)
         {
             return(this.Source.GetValue(new CalcCellIdentity(this.Row, this.Column)));
         }
         if (objA._isFullColumn)
         {
             return(this.Source.GetValue(new CalcCellIdentity(this.Row, objA._columnIndex)));
         }
         if (objA._isFullRow)
         {
             return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, this.Column)));
         }
         if (((objA._rowCount == 1) && (objA._columnIndex <= this.Column)) && (this.Column < (objA._columnIndex + objA._columnCount)))
         {
             return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, this.Column)));
         }
         if (((objA._columnCount == 1) && (objA._rowIndex <= this.Row)) && (this.Row < (objA._rowIndex + objA._rowCount)))
         {
             return(this.Source.GetValue(new CalcCellIdentity(this.Row, objA._columnIndex)));
         }
         if ((objA._rowCount == 1) && (objA._columnCount == 1))
         {
             return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, objA._columnIndex)));
         }
         return(CalcErrors.Value);
     }
     return(CalcErrors.Reference);
 }
Exemplo n.º 6
0
        private CalcExpression GetExpressionCore(CalcLocalIdentity id)
        {
            Tuple <CalcExpression, bool> tuple;
            CalcExpression objB = this._formulas[id];

            if ((object.ReferenceEquals(null, objB) && this.Service.IsGraphSuspended) && this._tmpFormulas.TryGetValue(id, out tuple))
            {
                objB = tuple.Item1;
            }
            return(objB);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Normalizes the specified node to convert all external reference to internal reference.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="node">The node.</param>
 /// <returns>
 /// If <paramref name="node" /> is external identity, return a new node which identity is not external, otherwise, return <paramref name="node" />.
 /// </returns>
 internal static CalcNode Normalize(CalcService service, CalcNode node)
 {
     if (!object.ReferenceEquals(node, null) && (node.Id is CalcExternalIdentity))
     {
         CalcExternalIdentity id        = node.Id as CalcExternalIdentity;
         CalcGraph            graph     = service.GetCalculationManager(id.Source, null, true).Graph;
         CalcLocalIdentity    identity2 = id.ConvertToLocal();
         node = graph.GetNode(identity2) ?? new CalcNode(id.Source, identity2);
     }
     return(node);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the formula.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>A <see langword="string" /> indicates the formula.</returns>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="id" /> is <see langword="null" />.</exception>
        public string GetFormula(CalcLocalIdentity id)
        {
            if (object.ReferenceEquals(id, null))
            {
                throw new ArgumentNullException("id");
            }
            CalcExpression objA = this.GetExpression(id);

            if (!object.ReferenceEquals(objA, null))
            {
                return(this.Parser.Unparse(objA, this.Source.GetParserContext(id)));
            }
            return(null);
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Clears the expression.
 /// </summary>
 /// <param name="id">The id.</param>
 public void ClearExpression(CalcLocalIdentity id)
 {
     if (object.ReferenceEquals(id, null))
     {
         throw new ArgumentNullException("id");
     }
     if ((this.Service.IsGraphSuspended && (this._tmpFormulas.Count > 0)) && this._tmpFormulas.ContainsKey(id))
     {
         this._tmpFormulas.Remove(id);
     }
     else
     {
         this._formulas.RemoveAt(id);
         this.Graph.RemoveNode(id);
     }
 }
Exemplo n.º 11
0
            private void AddPredenceIds(CalcLocalIdentity id, bool isFullRelative)
            {
                bool flag;

                if (this.PredenceIds.TryGetValue(id, out flag))
                {
                    if (!isFullRelative && flag)
                    {
                        this.PredenceIds[id] = isFullRelative;
                    }
                }
                else
                {
                    this.PredenceIds.Add(id, isFullRelative);
                }
            }
Exemplo n.º 12
0
 /// <summary>
 /// Gets the reference at specified position which indicated by <paramref name="id" />.
 /// </summary>
 /// <param name="id">A <see cref="T:Dt.CalcEngine.CalcIdentity" /> indicates the identity of a address.</param>
 /// <returns>
 /// An <see cref="T:System.Object" /> indicates the reference.
 /// If the <paramref name="id" /> is not recognized, return <see cref="F:Dt.CalcEngine.CalcErrors.Reference" />.
 /// </returns>
 public virtual object GetReference(CalcIdentity id)
 {
     if (id is CalcExternalIdentity)
     {
         CalcExternalIdentity identity = id as CalcExternalIdentity;
         ICalcSource          source   = identity.Source;
         if (source != null)
         {
             return(source.GetReference(identity.ConvertToLocal()));
         }
     }
     else
     {
         if (id is CalcSheetRangeIdentity)
         {
             IMultiSourceProvider provider = this.Source as IMultiSourceProvider;
             if (provider == null)
             {
                 return(CalcErrors.Reference);
             }
             try
             {
                 CalcSheetRangeIdentity identity2  = id as CalcSheetRangeIdentity;
                 CalcLocalIdentity      identity3  = identity2.ConvertToLocal();
                 List <CalcReference>   references = new List <CalcReference>();
                 foreach (ICalcSource source2 in provider.GetCalcSources(identity2.StartSource, identity2.EndSource))
                 {
                     CalcReference item = source2.GetReference(identity3) as CalcReference;
                     if (item != null)
                     {
                         references.Add(item);
                     }
                 }
                 return(new SheetRangeReference(references));
             }
             catch
             {
                 return(CalcErrors.Reference);
             }
         }
         if ((this.Source != null) && (id is CalcLocalIdentity))
         {
             return(this.Source.GetReference(id as CalcLocalIdentity));
         }
     }
     return(CalcErrors.Reference);
 }
Exemplo n.º 13
0
        private static bool IsContains(CalcLocalIdentity id1, CalcLocalIdentity id2)
        {
            CalcRangeIdentity rangeId = id1 as CalcRangeIdentity;

            if (rangeId == null)
            {
                return(false);
            }
            CalcRangeIdentity identity2 = id2 as CalcRangeIdentity;
            CalcCellIdentity  identity3 = id2 as CalcCellIdentity;

            if (identity3 != null)
            {
                return(IsContains(rangeId, identity3.RowIndex, identity3.ColumnIndex, 1, 1));
            }
            return((identity2 != null) && IsContains(rangeId, identity2.RowIndex, identity2.ColumnIndex, identity2.RowCount, identity2.ColumnCount));
        }
Exemplo n.º 14
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);
                    }
                }
            }
        }
Exemplo n.º 15
0
        private static void LocalId2Index(CalcLocalIdentity item, out int startRow, out int startCol, out int endRow, out int endCol)
        {
            CalcCellIdentity  identity  = item as CalcCellIdentity;
            CalcRangeIdentity identity2 = item as CalcRangeIdentity;

            if (identity != null)
            {
                startRow = endRow = identity.RowIndex;
                startCol = endCol = identity.ColumnIndex;
            }
            else
            {
                startRow = identity2.RowIndex;
                startCol = identity2.ColumnIndex;
                endRow   = (identity2.RowIndex + identity2.RowCount) - 1;
                endCol   = (identity2.ColumnIndex + identity2.ColumnCount) - 1;
            }
            startRow = (startRow < 0) ? 0 : startRow;
            startCol = (startCol < 0) ? 0 : startCol;
            endRow   = (endRow < 0) ? 0xfffff : endRow;
            endCol   = (endCol < 0) ? 0x3fff : endCol;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>A <see cref="T:Dt.CalcEngine.Expressions.CalcExpression" /> indicates the expression.</returns>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="id" /> is <see langword="null" />.</exception>
        public CalcExpression GetExpression(CalcLocalIdentity id)
        {
            if (object.ReferenceEquals(id, null))
            {
                throw new ArgumentNullException("id");
            }
            CalcExpression expressionCore = this.GetExpressionCore(id);

            if (object.ReferenceEquals(expressionCore, null) && (id is CalcCellIdentity))
            {
                CalcRangeIdentity sharedFormulaRange = this.Graph.GetSharedFormulaRange(id as CalcCellIdentity);
                if (!object.ReferenceEquals(sharedFormulaRange, null))
                {
                    expressionCore = this.GetExpressionCore(sharedFormulaRange);
                    if (!object.ReferenceEquals(expressionCore, null) && !(expressionCore is CalcSharedExpression))
                    {
                        expressionCore = new CalcSharedExpression(expressionCore);
                    }
                }
            }
            return(expressionCore);
        }
Exemplo n.º 17
0
 internal void MarkAsDirty(CalcService service, bool recalculateAll = false, bool recursiveToIntersectant = true, bool recursiveToDependency = true, bool recursiveToSharedFormula = true)
 {
     if (!this.IsDirty && !this._isProcessingDirty)
     {
         int  num;
         int  num2;
         int  num3;
         int  num4;
         bool flag;
         this._isProcessingDirty = true;
         if ((this.DirtyItem == null) && !this._isTempNode)
         {
             CalcLocalIdentity objA = this.Id as CalcLocalIdentity;
             if (object.ReferenceEquals(objA, null))
             {
                 return;
             }
             this.DirtyItem = new DirtyItem(service, this.Source, objA, this);
         }
         CalcGraph graph = service.GetCalculationManager(this.Source, null, true).Graph;
         CalcReferenceHelper.Id2Range(this.Source, this.Id, out num, out num2, out num3, out num4, out flag);
         CalcRangeIdentity id = this.Id as CalcRangeIdentity;
         List <CalcNode>   searchingDepends = new List <CalcNode>();
         List <CalcNode>   list2            = new List <CalcNode>();
         if (recursiveToIntersectant && !object.ReferenceEquals(id, null))
         {
             List <CalcNode> list3 = new List <CalcNode>();
             for (int i = 0; i < num3; i++)
             {
                 for (int j = 0; j < num4; j++)
                 {
                     CalcNode node = graph.GetNode(new CalcCellIdentity(num + i, num2 + j));
                     if (!object.ReferenceEquals(node, null) && node.IsDirty)
                     {
                         list2.Add(node);
                     }
                     if ((!object.ReferenceEquals(node, null) && !node._isWattingForProcess) && (!node._isProcessingDirty && !node.IsDirty))
                     {
                         node._isWattingForProcess = true;
                         list3.Add(node);
                     }
                 }
             }
             foreach (CalcNode node2 in list3)
             {
                 node2.MarkAsDirty(service, recalculateAll, false, true, true);
                 node2._isWattingForProcess = false;
             }
         }
         DirtyItem       dependForehand         = null;
         List <CalcNode> pendingDependDirtyNode = new List <CalcNode>();
         if ((this.Dependents != null) && (this.Dependents.Count > 0))
         {
             searchingDepends.AddRange(this.Dependents.Values);
         }
         List <SharedFormulaDirtyItem> sharedDirtyItmes = new List <SharedFormulaDirtyItem>();
         if (flag || !recalculateAll)
         {
             foreach (CalcNode node3 in graph.GetAllDependentRangeNodes(num, num2, num3, num4))
             {
                 if ((node3 != this) && ((recalculateAll || !graph.IsSharedFormula(node3.Id as CalcRangeIdentity)) || ((node3.Dependents != null) && (node3.Dependents.Count != 0))))
                 {
                     if (!recalculateAll && recursiveToDependency)
                     {
                         ExpandSharedFormulaDependency(service, graph, list2, sharedDirtyItmes, node3, this.Id as CalcLocalIdentity);
                     }
                     else if (recalculateAll)
                     {
                         list2.Add(node3);
                     }
                 }
             }
             if (recursiveToSharedFormula && this._isTempNode)
             {
                 foreach (CalcNode node4 in graph.GetAllDependentSharedNodes(num, num2, num3, num4))
                 {
                     list2.Add(node4);
                 }
             }
         }
         if (recursiveToIntersectant)
         {
             searchingDepends.AddRange(list2);
             list2.Clear();
         }
         dependForehand = SerchDependForehand(dependForehand, searchingDepends, list2, pendingDependDirtyNode, sharedDirtyItmes);
         if (recursiveToSharedFormula && !this._isTempNode)
         {
             if (dependForehand != null)
             {
                 service.InsertToDirtyBefore(this.DirtyItem, dependForehand);
             }
             else
             {
                 service.AddDirtyItem(this.DirtyItem);
             }
         }
         if (recursiveToDependency)
         {
             foreach (CalcNode node5 in pendingDependDirtyNode)
             {
                 node5._isWattingForProcess = true;
             }
             foreach (CalcNode node6 in pendingDependDirtyNode)
             {
                 node6.MarkAsDirty(service, recalculateAll, true, true, true);
                 node6._isWattingForProcess = false;
             }
             foreach (SharedFormulaDirtyItem item2 in sharedDirtyItmes)
             {
                 if (!item2.Node.IsDirty)
                 {
                     service.AddDirtyItem(item2);
                 }
                 List <CalcNode> list6 = new List <CalcNode>();
                 foreach (CalcLocalIdentity identity3 in item2.DirtySubIds2)
                 {
                     if (!item2.DirtySubIds.Contains(identity3))
                     {
                         item2.DirtySubIds.Add(identity3);
                         CalcNode item = graph.GetNode(identity3);
                         if (item == null)
                         {
                             item = CreateTempNode(this.Source, identity3);
                         }
                         item._isWattingForProcess = true;
                         list6.Add(item);
                     }
                 }
                 foreach (CalcNode node8 in list6)
                 {
                     node8.MarkAsDirty(service, recalculateAll, true, true, false);
                     node8._isWattingForProcess = false;
                 }
             }
         }
         else if (recalculateAll)
         {
             foreach (CalcNode node9 in searchingDepends)
             {
                 this.SetPredencyItem(service, node9);
             }
             foreach (CalcNode node10 in list2)
             {
                 if (IsContains(node10.Id as CalcLocalIdentity, this.Id as CalcLocalIdentity))
                 {
                     this.SetPredencyItem(service, node10);
                 }
             }
         }
         this._isProcessingDirty = false;
     }
 }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
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>();
 }
Exemplo n.º 20
0
 /// <summary>
 /// Clears the formula.
 /// </summary>
 /// <param name="id">The id.</param>
 public void ClearFormula(CalcLocalIdentity id)
 {
     this.ClearExpression(id);
 }
Exemplo n.º 21
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++;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// Determines whether the specified <see cref="T:Dt.CalcEngine.CalcIdentity" /> is intersected with an range that has array formula.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns>
 /// <see langword="true" /> if the specified <see cref="T:Dt.CalcEngine.CalcIdentity" /> is intersected
 /// with an range that has array formula;  otherwise, <see langword="false" />.
 /// </returns>
 public bool IsIsIntersectantWithArrayFormula(CalcLocalIdentity id)
 {
     return(this.Graph.IsIsIntersectantWithArrayFormula(id));
 }
Exemplo n.º 23
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);
         }
     }
 }
Exemplo n.º 24
0
        private static void ExpandSharedFormulaDependency(CalcService service, CalcGraph graph, List <CalcNode> searchingDepends, List <SharedFormulaDirtyItem> sharedDirtyItmes, CalcNode rangeIntersected, CalcLocalIdentity currentId)
        {
            CalcRangeIdentity identity = currentId as CalcRangeIdentity;
            CalcRangeIdentity id       = rangeIntersected.Id as CalcRangeIdentity;

            if ((!object.ReferenceEquals(id, null) && (rangeIntersected.Dependents != null)) && ((rangeIntersected.Dependents.Count > 0) && ShouldExpand(graph, id)))
            {
                foreach (KeyValuePair <CalcNode, CalcNode> pair in rangeIntersected.Dependents)
                {
                    List <CalcLocalIdentity> list;
                    CalcRangeIdentity        rangeId = pair.Key.Id as CalcRangeIdentity;
                    if ((rangeId == null) || !graph.IsSharedFormula(rangeId))
                    {
                        goto Label_019E;
                    }
                    if ((currentId == rangeId) || ((identity != null) && (identity.IsFullRow || identity.IsFullColumn)))
                    {
                        searchingDepends.Add(pair.Key);
                        continue;
                    }
                    SharedFormulaDirtyItem dirtyItem = null;
                    if (pair.Key.DirtyItem != null)
                    {
                        if (pair.Key.DirtyItem is SharedFormulaDirtyItem)
                        {
                            dirtyItem = pair.Key.DirtyItem as SharedFormulaDirtyItem;
                            if (!dirtyItem.IsFullRangeDirty)
                            {
                                goto Label_0136;
                            }
                        }
                        continue;
                    }
                    dirtyItem = new SharedFormulaDirtyItem(service, graph.Manager.Source, rangeId, graph.GetNode(rangeId));
                    graph.GetNode(rangeId).DirtyItem = dirtyItem;
Label_0136:
                    list = GetDepIdsInSharedFormulaRange(graph.Manager, rangeId, currentId);
                    if ((list.Count == 1) && (list[0] == rangeId))
                    {
                        dirtyItem.IsFullRangeDirty = true;
                        searchingDepends.Add(graph.GetNode(rangeId));
                    }
                    else
                    {
                        dirtyItem.DirtySubIds2.AddRange(list);
                        if (dirtyItem.DirtySubIds2.Count > 0)
                        {
                            sharedDirtyItmes.Add(dirtyItem);
                        }
                    }
                    continue;
Label_019E:
                    searchingDepends.Add(pair.Key);
                }
            }
            else
            {
                searchingDepends.Add(rangeIntersected);
            }
        }
Exemplo n.º 25
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);
        }