Ejemplo n.º 1
0
        public PlainValueCellCacheEntry GetPlainValueEntry(int bookIndex, int sheetIndex,
                                                           int rowIndex, int columnIndex, ValueEval value)
        {
            Loc loc = new Loc(bookIndex, sheetIndex, rowIndex, columnIndex);
            PlainValueCellCacheEntry result = _plainCellCache.Get(loc);

            if (result == null)
            {
                result = new PlainValueCellCacheEntry(value);
                _plainCellCache.Put(loc, result);
                if (_evaluationListener != null)
                {
                    _evaluationListener.OnReadPlainValue(sheetIndex, rowIndex, columnIndex, result);
                }
            }
            else
            {
                // TODO - if we are confident that this sanity check is not required, we can Remove 'value' from plain value cache entry
                if (!AreValuesEqual(result.GetValue(), value))
                {
                    throw new InvalidOperationException("value changed");
                }
                if (_evaluationListener != null)
                {
                    _evaluationListener.OnCacheHit(sheetIndex, rowIndex, columnIndex, value);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public void NotifyDeleteCell(int bookIndex, int sheetIndex, IEvaluationCell cell)
        {
            if (cell.CellType == NPOI.SS.UserModel.CellType.Formula)
            {
                FormulaCellCacheEntry fcce = _formulaCellCache.Remove(cell);
                if (fcce == null)
                {
                    // formula cell Has not been evaluated yet
                }
                else
                {
                    fcce.SetSensitiveInputCells(null);
                    fcce.RecurseClearCachedFormulaResults(_evaluationListener);
                }
            }
            else
            {
                Loc loc = new Loc(bookIndex, sheetIndex, cell.RowIndex, cell.ColumnIndex);
                PlainValueCellCacheEntry pcce = _plainCellCache.Get(loc);

                if (pcce == null)
                {
                    // cache entry doesn't exist. nothing To do
                }
                else
                {
                    pcce.RecurseClearCachedFormulaResults(_evaluationListener);
                }
            }
        }
Ejemplo n.º 3
0
        public void AcceptPlainValueDependency(int bookIndex, int sheetIndex,
                                               int rowIndex, int columnIndex, ValueEval value)
        {
            // Tell the currently evaluating cell frame that it Has a dependency on the specified
            int prevFrameIndex = _evaluationFrames.Count - 1;

            if (prevFrameIndex < 0)
            {
                // Top level frame, there is no 'cell' above this frame that is using the current cell
            }
            else
            {
                CellEvaluationFrame consumingFrame = (CellEvaluationFrame)_evaluationFrames[prevFrameIndex];
                if (value == BlankEval.instance)
                {
                    consumingFrame.AddUsedBlankCell(bookIndex, sheetIndex, rowIndex, columnIndex);
                }
                else
                {
                    PlainValueCellCacheEntry cce = _cache.GetPlainValueEntry(bookIndex, sheetIndex,
                                                                             rowIndex, columnIndex, value);
                    consumingFrame.AddSensitiveInputCell(cce);
                }
            }
        }
Ejemplo n.º 4
0
        public void TestBasicCellCacheEntry()
        {
            CellCacheEntry pcce = new PlainValueCellCacheEntry(new NumberEval(42.0));
            ValueEval ve = pcce.GetValue();
            Assert.AreEqual(42, ((NumberEval)ve).NumberValue, 0.0);

            FormulaCellCacheEntry fcce = new FormulaCellCacheEntry();
            fcce.UpdateFormulaResult(new NumberEval(10.0), CellCacheEntry.EMPTY_ARRAY, null);

            ve = fcce.GetValue();
            Assert.AreEqual(10, ((NumberEval)ve).NumberValue, 0.0);
        }
Ejemplo n.º 5
0
        public void TestLoc()
        {
            PlainCellCache cache = new PlainCellCache();
            for (int bookIndex = 0; bookIndex < 0x1000; bookIndex += 0x100)
            {
                for (int sheetIndex = 0; sheetIndex < 0x1000; sheetIndex += 0x100)
                {
                    for (int rowIndex = 0; rowIndex < 0x100000; rowIndex += 0x1000)
                    {
                        for (int columnIndex = 0; columnIndex < 0x4000; columnIndex += 0x100)
                        {
                            Loc loc = new Loc(bookIndex, sheetIndex, rowIndex, columnIndex);
                            Assert.AreEqual(bookIndex, loc.BookIndex);
                            Assert.AreEqual(sheetIndex, loc.SheetIndex);
                            Assert.AreEqual(rowIndex, loc.RowIndex);
                            Assert.AreEqual(columnIndex, loc.ColumnIndex);

                            Loc sameLoc = new Loc(bookIndex, sheetIndex, rowIndex, columnIndex);
                            Assert.AreEqual(loc.GetHashCode(), sameLoc.GetHashCode());
                            Assert.IsTrue(loc.Equals(sameLoc));

                            Assert.IsNull(cache.Get(loc));
                            PlainValueCellCacheEntry entry = new PlainValueCellCacheEntry(new NumberEval(0));
                            cache.Put(loc, entry);

                            Assert.AreSame(entry, cache.Get(loc));
                            cache.Remove(loc);
                            Assert.IsNull(cache.Get(loc));

                            cache.Put(loc, entry);
                        }
                        cache.Clear();
                    }
                }

            }
        }
Ejemplo n.º 6
0
        public void NotifyUpdateCell(int bookIndex, int sheetIndex, IEvaluationCell cell)
        {
            FormulaCellCacheEntry fcce = _formulaCellCache.Get(cell);

            int rowIndex = cell.RowIndex;
            int columnIndex = cell.ColumnIndex;
            Loc loc = new Loc(bookIndex, sheetIndex, cell.RowIndex, cell.ColumnIndex);
            PlainValueCellCacheEntry pcce = _plainCellCache.Get(loc);

            if (cell.CellType == NPOI.SS.UserModel.CellType.FORMULA)
            {
                if (fcce == null)
                {
                    fcce = new FormulaCellCacheEntry();

                    if (pcce == null)
                    {
                        if (_evaluationListener != null)
                        {
                            _evaluationListener.OnChangeFromBlankValue(sheetIndex, rowIndex,
                                    columnIndex, cell, fcce);
                        }
                        UpdateAnyBlankReferencingFormulas(bookIndex, sheetIndex, rowIndex, columnIndex);
                    }
                    _formulaCellCache.Put(cell, fcce);
                }
                else
                {
                    fcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    fcce.ClearFormulaEntry();
                }
                if (pcce == null)
                {
                    // was formula cell before - no Change of type
                }
                else
                {
                    // changing from plain cell To formula cell
                    pcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    _plainCellCache.Remove(loc);
                }
            }
            else
            {
                ValueEval value = WorkbookEvaluator.GetValueFromNonFormulaCell(cell);
                if (pcce == null)
                {
                    if (value != BlankEval.instance)
                    {
                        pcce = new PlainValueCellCacheEntry(value);
                        if (fcce == null)
                        {
                            if (_evaluationListener != null)
                            {
                                _evaluationListener.OnChangeFromBlankValue(sheetIndex, rowIndex,
                                        columnIndex, cell, pcce);
                            }
                            UpdateAnyBlankReferencingFormulas(bookIndex, sheetIndex, rowIndex, columnIndex);
                        }
                        _plainCellCache.Put(loc, pcce);
                    }
                }
                else
                {
                    if (pcce.UpdateValue(value))
                    {
                        pcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    }
                    if (value == BlankEval.instance)
                    {
                        _plainCellCache.Remove(loc);
                    }
                }
                if (fcce == null)
                {
                    // was plain cell before - no Change of type
                }
                else
                {
                    // was formula cell before - now a plain value
                    _formulaCellCache.Remove(cell);
                    fcce.SetSensitiveInputCells(null);
                    fcce.RecurseClearCachedFormulaResults(_evaluationListener);
                }
            }
        }
Ejemplo n.º 7
0
        public PlainValueCellCacheEntry GetPlainValueEntry(int bookIndex, int sheetIndex,
                int rowIndex, int columnIndex, ValueEval value)
        {

            Loc loc = new Loc(bookIndex, sheetIndex, rowIndex, columnIndex);
            PlainValueCellCacheEntry result = _plainCellCache.Get(loc);
            if (result == null)
            {
                result = new PlainValueCellCacheEntry(value);
                _plainCellCache.Put(loc, result);
                if (_evaluationListener != null)
                {
                    _evaluationListener.OnReadPlainValue(sheetIndex, rowIndex, columnIndex, result);
                }
            }
            else
            {
                // TODO - if we are confident that this sanity check is not required, we can Remove 'value' from plain value cache entry  
                if (!AreValuesEqual(result.GetValue(), value))
                {
                    throw new InvalidOperationException("value changed");
                }
                if (_evaluationListener != null)
                {
                    _evaluationListener.OnCacheHit(sheetIndex, rowIndex, columnIndex, value);
                }
            }
            return result;
        }
Ejemplo n.º 8
0
        public void NotifyUpdateCell(int bookIndex, int sheetIndex, IEvaluationCell cell)
        {
            FormulaCellCacheEntry fcce = _formulaCellCache.Get(cell);

            int rowIndex    = cell.RowIndex;
            int columnIndex = cell.ColumnIndex;
            Loc loc         = new Loc(bookIndex, sheetIndex, cell.RowIndex, cell.ColumnIndex);
            PlainValueCellCacheEntry pcce = _plainCellCache.Get(loc);

            if (cell.CellType == NPOI.SS.UserModel.CellType.Formula)
            {
                if (fcce == null)
                {
                    fcce = new FormulaCellCacheEntry();

                    if (pcce == null)
                    {
                        if (_evaluationListener != null)
                        {
                            _evaluationListener.OnChangeFromBlankValue(sheetIndex, rowIndex,
                                                                       columnIndex, cell, fcce);
                        }
                        UpdateAnyBlankReferencingFormulas(bookIndex, sheetIndex, rowIndex, columnIndex);
                    }
                    _formulaCellCache.Put(cell, fcce);
                }
                else
                {
                    fcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    fcce.ClearFormulaEntry();
                }
                if (pcce == null)
                {
                    // was formula cell before - no Change of type
                }
                else
                {
                    // changing from plain cell To formula cell
                    pcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    _plainCellCache.Remove(loc);
                }
            }
            else
            {
                ValueEval value = WorkbookEvaluator.GetValueFromNonFormulaCell(cell);
                if (pcce == null)
                {
                    if (value != BlankEval.instance)
                    {
                        pcce = new PlainValueCellCacheEntry(value);
                        if (fcce == null)
                        {
                            if (_evaluationListener != null)
                            {
                                _evaluationListener.OnChangeFromBlankValue(sheetIndex, rowIndex,
                                                                           columnIndex, cell, pcce);
                            }
                            UpdateAnyBlankReferencingFormulas(bookIndex, sheetIndex, rowIndex, columnIndex);
                        }
                        _plainCellCache.Put(loc, pcce);
                    }
                }
                else
                {
                    if (pcce.UpdateValue(value))
                    {
                        pcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    }
                    if (value == BlankEval.instance)
                    {
                        _plainCellCache.Remove(loc);
                    }
                }
                if (fcce == null)
                {
                    // was plain cell before - no Change of type
                }
                else
                {
                    // was formula cell before - now a plain value
                    _formulaCellCache.Remove(cell);
                    fcce.SetSensitiveInputCells(null);
                    fcce.RecurseClearCachedFormulaResults(_evaluationListener);
                }
            }
        }
Ejemplo n.º 9
0
 public void Put(Loc key, PlainValueCellCacheEntry cce)
 {
     _plainValueEntriesByLoc[key] = cce;
 }
Ejemplo n.º 10
0
 public void Put(Loc key, PlainValueCellCacheEntry cce)
 {
     _plainValueEntriesByLoc[key] = cce;
 }