コード例 #1
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;
                }
            }
        }
コード例 #2
0
ファイル: CalcNode.cs プロジェクト: Daoting/dt
        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);
            }
        }
コード例 #3
0
ファイル: CalcNode.cs プロジェクト: Daoting/dt
 private static bool IsContains(CalcRangeIdentity rangeId, int row, int col, int rowCount, int colCount)
 {
     if (!rangeId.IsFullColumn && ((row < rangeId.RowIndex) || ((row + rowCount) > (rangeId.RowIndex + rangeId.RowCount))))
     {
         return(false);
     }
     return(rangeId.IsFullRow || ((col >= rangeId.ColumnIndex) && ((col + colCount) <= (rangeId.ColumnIndex + rangeId.ColumnCount))));
 }
コード例 #4
0
 /// <summary>
 /// hdt 唐忠宝增加
 /// </summary>
 /// <param name="id"></param>
 /// <param name="containsRanges"></param>
 /// <param name="intersectedRanges"></param>
 public void GetArrayFormulaByRange(CalcRangeIdentity id, out List <CalcRangeIdentity> containsRanges, out List <CalcRangeIdentity> intersectedRanges)
 {
     if (object.ReferenceEquals(id, null))
     {
         throw new ArgumentNullException("id");
     }
     this.Graph.GetArrayFormulaByRange(id, out containsRanges, out intersectedRanges);
 }
コード例 #5
0
ファイル: CalcReferenceHelper.cs プロジェクト: Daoting/dt
        internal static void Id2Range(ICalcSource source, CalcIdentity Id, out int row, out int col, out int rowCount, out int colCount, out bool searchRange)
        {
            int num;
            int num2;

            colCount    = num = 1;
            rowCount    = num2 = num;
            row         = col = num2;
            searchRange = false;
            CalcCellIdentity  objA      = Id as CalcCellIdentity;
            CalcRangeIdentity identity2 = Id as CalcRangeIdentity;

            if (!object.ReferenceEquals(objA, null))
            {
                row         = objA.RowIndex;
                col         = objA.ColumnIndex;
                rowCount    = colCount = 1;
                searchRange = true;
            }
            else if (!object.ReferenceEquals(identity2, null))
            {
                if (identity2.IsFullColumn || identity2.IsFullRow)
                {
                    CalcReference reference = source.GetReference(identity2) as CalcReference;
                    row      = reference.GetRow(0);
                    col      = reference.GetColumn(0);
                    rowCount = reference.GetRowCount(0);
                    colCount = reference.GetColumnCount(0);
                }
                if (identity2.IsFullRow)
                {
                    row      = identity2.RowIndex;
                    rowCount = identity2.RowCount;
                }
                else if (identity2.IsFullColumn)
                {
                    col      = identity2.ColumnIndex;
                    colCount = identity2.ColumnCount;
                }
                else
                {
                    row      = identity2.RowIndex;
                    rowCount = identity2.RowCount;
                    col      = identity2.ColumnIndex;
                    colCount = identity2.ColumnCount;
                }
                searchRange = true;
            }
            else
            {
                int num5;
                int num6;
                colCount = num5 = 0;
                rowCount = num6 = num5;
                row      = col = num6;
            }
        }
コード例 #6
0
ファイル: CalcNode.cs プロジェクト: Daoting/dt
        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);
        }
コード例 #7
0
ファイル: CalcEvaluatorContext.cs プロジェクト: Daoting/dt
 /// <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);
 }
コード例 #8
0
        /// <summary>
        /// Sets the formula.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="formula">The formula.</param>
        /// <param name="isArrayFormula">Indicates the formula is array formula or not.</param>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="id" /> is <see langword="null" />.</exception>
        public void SetFormula(CalcRangeIdentity id, string formula, bool isArrayFormula = true)
        {
            if (object.ReferenceEquals(id, null))
            {
                throw new ArgumentNullException("id");
            }
            CalcExpression expr = this.Parser.Parse(formula, this.Source.GetParserContext(id));

            this.SetExpression(id, expr, isArrayFormula);
        }
コード例 #9
0
ファイル: CalcRangeIdentity.cs プロジェクト: Daoting/dt
        /// <summary>
        /// Determines whether the specified <see cref="T:Dt.CalcEngine.CalcCellIdentity" />
        /// is equal to the current <see cref="T:Dt.CalcEngine.CalcCellIdentity" />.
        /// </summary>
        /// <param name="other">
        /// The <see cref="T:Dt.CalcEngine.CalcCellIdentity" /> to compare with the
        /// current <see cref="T:Dt.CalcEngine.CalcCellIdentity" />.
        /// </param>
        /// <returns>
        /// <see langword="true" /> if the specified <see cref="T:Dt.CalcEngine.CalcCellIdentity" />
        /// is equal to the current <see cref="T:Dt.CalcEngine.CalcCellIdentity" />;
        /// otherwise, <see langword="false" />.
        /// </returns>
        protected override bool CompareTo(CalcIdentity other)
        {
            CalcRangeIdentity objA = other as CalcRangeIdentity;

            if (object.ReferenceEquals(objA, null))
            {
                return(false);
            }
            return(((((this._isFullRow == objA._isFullRow) && (this._isFullColumn == objA._isFullColumn)) && ((this._rowIndex == objA._rowIndex) && (this._columnIndex == objA._columnIndex))) && (this._rowCount == objA._rowCount)) && (this._columnCount == objA._columnCount));
        }
コード例 #10
0
ファイル: CalcNode.cs プロジェクト: Daoting/dt
        private static bool ShouldExpand(CalcGraph graph, CalcRangeIdentity rangeIntersectedDepId)
        {
            if (graph.Manager.GetExpression(rangeIntersectedDepId) == null)
            {
                return(true);
            }
            CalcNode node = graph.GetNode(rangeIntersectedDepId);

            return(((node != null) && (node.DirtyItem is SharedFormulaDirtyItem)) && !(node.DirtyItem as SharedFormulaDirtyItem).IsFullRangeDirty);
        }
コード例 #11
0
 private void ExpandSharedFormula(CalcExpression expr, CalcRangeIdentity rangeId)
 {
     for (int i = rangeId.RowIndex; i < (rangeId.RowIndex + rangeId.RowCount); i++)
     {
         for (int j = rangeId.ColumnIndex; j < (rangeId.ColumnIndex + rangeId.ColumnCount); j++)
         {
             CalcCellIdentity id = new CalcCellIdentity(i, j);
             this.SetExpression(id, expr, false);
         }
     }
 }
コード例 #12
0
 /// <summary>
 /// hdt 唐忠宝增加
 /// </summary>
 /// <param name="cellId"></param>
 /// <returns></returns>
 private IEnumerable <CalcNode> EnumerateIntersectedNodesExcludeSelf(CalcCellIdentity cellId)
 {
     foreach (CalcNode iteratorVariable0 in this.Graph.GetAllRangeNodes())
     {
         CalcRangeIdentity id = iteratorVariable0.Id as CalcRangeIdentity;
         if ((!object.ReferenceEquals(id, null) && (((cellId.RowIndex >= id.RowIndex) && (cellId.RowIndex < (id.RowIndex + id.RowCount))) || id._isFullColumn)) && (((cellId.ColumnIndex >= id.ColumnIndex) && (cellId.ColumnIndex < (id.ColumnIndex + id.ColumnCount))) || id._isFullRow))
         {
             yield return(iteratorVariable0);
         }
     }
 }
コード例 #13
0
ファイル: CalcEvaluatorContext.cs プロジェクト: Daoting/dt
 /// <summary>
 /// Determines whether the specified <see cref="T:Dt.CalcEngine.CalcIdentity" /> is intersected with another one.
 /// </summary>
 /// <param name="srcId">The source identity, intersected this with another one.</param>
 /// <param name="destId">The destination identity,</param>
 /// <returns>
 /// <see langword="true" /> if the specified calc identity is intersected; otherwise, <see langword="false" />.
 /// By default, compare two by <see cref="M:System.Object.ReferenceEquals(System.Object,System.Object)" />.
 /// </returns>
 public virtual bool IsIntersected(CalcIdentity srcId, CalcIdentity destId)
 {
     if (srcId == destId)
     {
         return(true);
     }
     if (srcId is CalcCellIdentity)
     {
         if (destId is CalcRangeIdentity)
         {
             return(IsIntersected(srcId as CalcCellIdentity, destId as CalcRangeIdentity));
         }
     }
     else if (srcId is CalcRangeIdentity)
     {
         if (destId is CalcCellIdentity)
         {
             return(IsIntersected(destId as CalcCellIdentity, srcId as CalcRangeIdentity));
         }
         if (destId is CalcRangeIdentity)
         {
             CalcRangeIdentity identity  = srcId as CalcRangeIdentity;
             CalcRangeIdentity identity2 = destId as CalcRangeIdentity;
             if ((identity._isFullColumn && identity._isFullRow) || (identity2._isFullColumn && identity2._isFullRow))
             {
                 return(true);
             }
             if (identity._isFullColumn || identity2._isFullColumn)
             {
                 if (!InRange(identity._columnIndex, identity2._columnIndex, identity2._columnIndex + identity2._columnCount))
                 {
                     return(InRange(identity2._columnIndex, identity._columnIndex, identity._columnIndex + identity._columnCount));
                 }
                 return(true);
             }
             if (identity._isFullRow || identity2._isFullRow)
             {
                 if (!InRange(identity._rowIndex, identity2._rowIndex, identity2._rowIndex + identity2._rowCount))
                 {
                     return(InRange(identity2._rowIndex, identity._rowIndex, identity._rowIndex + identity._rowCount));
                 }
                 return(true);
             }
             return((InRange(identity._rowIndex, identity2._rowIndex, identity2._rowIndex + identity2._rowCount) && InRange(identity._columnIndex, identity2._columnIndex, identity2._columnIndex + identity2._columnCount)) || (InRange(identity2._rowIndex, identity._rowIndex, identity._rowIndex + identity._rowCount) && InRange(identity2._columnIndex, identity._columnIndex, identity._columnIndex + identity._columnCount)));
         }
     }
     else if ((srcId is CalcExternalIdentity) && (destId is CalcExternalIdentity))
     {
         return(this.IsIntersected((srcId as CalcExternalIdentity).ConvertToLocal(), (destId as CalcExternalIdentity).ConvertToLocal()));
     }
     return(false);
 }
コード例 #14
0
ファイル: CalcEvaluatorContext.cs プロジェクト: Daoting/dt
 private static bool IsIntersected(CalcCellIdentity cellId, CalcRangeIdentity rangeId)
 {
     if (rangeId._isFullColumn && rangeId._isFullRow)
     {
         return(true);
     }
     if (rangeId._isFullColumn)
     {
         return(InRange(cellId._columnIndex, rangeId._columnIndex, rangeId._columnIndex + rangeId._columnCount));
     }
     if (rangeId._isFullRow)
     {
         return(InRange(cellId._rowIndex, rangeId._rowIndex, rangeId._rowIndex + rangeId._rowCount));
     }
     return(InRange(cellId._rowIndex, rangeId._rowIndex, rangeId._rowIndex + rangeId._rowCount) && InRange(cellId._columnIndex, rangeId._columnIndex, rangeId._columnIndex + rangeId._columnCount));
 }
コード例 #15
0
ファイル: CalcNode.cs プロジェクト: Daoting/dt
        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));
        }
コード例 #16
0
 /// <summary>
 /// Gets the array formula.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="range">The range that the array formula was set.</param>
 /// <returns>A <see langword="string" /> indicates the array formula.</returns>
 public string GetArrayFormulaByCell(CalcCellIdentity id, out CalcRangeIdentity range)
 {
     if (object.ReferenceEquals(id, null))
     {
         throw new ArgumentNullException("id");
     }
     if (!this.IsIsIntersectantWithArrayFormula(id))
     {
         range = null;
         return(null);
     }
     range = this.Graph.GetArrayFormulaRange(id, false);
     if (range == null)
     {
         return(null);
     }
     return(this.GetFormula(range));
 }
コード例 #17
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);
        }
コード例 #18
0
ファイル: CalcNode.cs プロジェクト: Daoting/dt
        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;
        }
コード例 #19
0
ファイル: CalcRangeIdentity.cs プロジェクト: Daoting/dt
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Dt.CalcEngine.CalcRangeIdentity" /> class.
 /// </summary>
 /// <param name="range">The range.</param>
 /// <param name="rowOffset">The row offset.</param>
 /// <param name="columnOffset">The column offset.</param>
 public CalcRangeIdentity(CalcRangeIdentity range, int rowOffset, int columnOffset)
 {
     if (range.IsFullColumn)
     {
         this.RowIndex = -1;
         this.RowCount = -1;
     }
     else
     {
         this.RowIndex = range.RowIndex + rowOffset;
         this.RowCount = range.RowCount;
     }
     if (range.IsFullRow)
     {
         this.ColumnIndex = -1;
         this.ColumnCount = -1;
     }
     else
     {
         this.ColumnIndex = range.ColumnIndex + columnOffset;
         this.ColumnCount = range.ColumnCount;
     }
 }
コード例 #20
0
 /// <summary>
 /// Sets the expression.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="expr">The exception.</param>
 /// <param name="isArrayFormula">Indicates the expression is array formula or not.</param>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="id" /> is <see langword="null" />.</exception>
 public void SetExpression(CalcRangeIdentity id, CalcExpression expr, bool isArrayFormula = true)
 {
     if (object.ReferenceEquals(id, null))
     {
         throw new ArgumentNullException("id");
     }
     if (!isArrayFormula && !(expr is CalcSharedExpression))
     {
         expr = new CalcSharedExpression(expr);
     }
     if ((!isArrayFormula && !id.IsFullRow) && (!id.IsFullColumn && !CalcGraph.IsLargeArray(id)))
     {
         this.ExpandSharedFormula(expr, id);
     }
     else if (this.Service.IsGraphSuspended)
     {
         this._tmpFormulas[id] = new Tuple <CalcExpression, bool>(expr, isArrayFormula);
     }
     else
     {
         this.Graph.SetNode(id, expr, this.Source.GetEvaluatorContext(id), this.Source, isArrayFormula);
         this._formulas[id] = expr;
     }
 }
コード例 #21
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);
         }
     }
 }
コード例 #22
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);
        }
コード例 #23
0
ファイル: CalcNode.cs プロジェクト: Daoting/dt
 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;
     }
 }