public EntryOperation(BookSheetKey bsk, int rowIndex, int columnIndex, IEvaluationListener evaluationListener) { this.bsk = bsk; this.evaluationListener = evaluationListener; this.rowIndex = rowIndex; this.columnIndex = columnIndex; }
/* package */ public WorkbookEvaluator(EvaluationWorkbook workbook, IEvaluationListener evaluationListener) { _workbook = workbook; _evaluationListener = evaluationListener; _cache = new EvaluationCache(evaluationListener); _sheetIndexesBySheet = new Hashtable(); _collaboratingWorkbookEnvironment = CollaboratingWorkbooksEnvironment.EMPTY; _workbookIx = 0; }
public void NotifyUpdatedBlankCell(BookSheetKey bsk, int rowIndex, int columnIndex, IEvaluationListener evaluationListener) { if (_usedBlankCellGroup != null) { if (_usedBlankCellGroup.ContainsCell(bsk, rowIndex, columnIndex)) { ClearFormulaEntry(); RecurseClearCachedFormulaResults(evaluationListener); } } }
public void RecurseClearCachedFormulaResults(IEvaluationListener listener) { if (listener == null) { RecurseClearCachedFormulaResults(); } else { listener.OnClearCachedValue(this); RecurseClearCachedFormulaResults(listener, 1); } }
public WorkbookEvaluator(EvaluationWorkbook workbook, IEvaluationListener evaluationListener, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) { _workbook = workbook; _evaluationListener = evaluationListener; _cache = new EvaluationCache(evaluationListener); _sheetIndexesBySheet = new Hashtable(); _sheetIndexesByName = new Dictionary <string, int>(); _collaboratingWorkbookEnvironment = CollaboratingWorkbooksEnvironment.EMPTY; _workbookIx = 0; _stabilityClassifier = stabilityClassifier; _udfFinder = udfFinder == null ? UDFFinder.DEFAULT : udfFinder; }
public WorkbookEvaluator(EvaluationWorkbook workbook, IEvaluationListener evaluationListener, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) { _workbook = workbook; _evaluationListener = evaluationListener; _cache = new EvaluationCache(evaluationListener); _sheetIndexesBySheet = new Hashtable(); _sheetIndexesByName = new Dictionary<string,int>(); _collaboratingWorkbookEnvironment = CollaboratingWorkbooksEnvironment.EMPTY; _workbookIx = 0; _stabilityClassifier = stabilityClassifier; _udfFinder = udfFinder == null ? UDFFinder.DEFAULT : udfFinder; }
/** * Identical To {@link #RecurseClearCachedFormulaResults()} except for the listener call-backs */ protected void RecurseClearCachedFormulaResults(IEvaluationListener listener, int depth) { FormulaCellCacheEntry[] formulaCells = GetConsumingCells(); listener.SortDependentCachedValues(formulaCells); for (int i = 0; i < formulaCells.Length; i++) { FormulaCellCacheEntry fc = formulaCells[i]; listener.OnClearDependentCachedValue(fc, depth); fc.ClearFormulaEntry(); fc.RecurseClearCachedFormulaResults(listener, depth + 1); } }
public WorkbookEvaluator(IEvaluationWorkbook workbook, IEvaluationListener evaluationListener, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) { _workbook = workbook; _evaluationListener = evaluationListener; _cache = new EvaluationCache(evaluationListener); _sheetIndexesBySheet = new Hashtable(); _sheetIndexesByName = new Dictionary<string, int>(); _collaboratingWorkbookEnvironment = CollaboratingWorkbooksEnvironment.EMPTY; _workbookIx = 0; _stabilityClassifier = stabilityClassifier; AggregatingUDFFinder defaultToolkit = // workbook can be null in unit tests workbook == null ? null : (AggregatingUDFFinder)workbook.GetUDFFinder(); if (defaultToolkit != null && udfFinder != null) { defaultToolkit.Add(udfFinder); } _udfFinder = defaultToolkit; }
public WorkbookEvaluator(IEvaluationWorkbook workbook, IEvaluationListener evaluationListener, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) { _workbook = workbook; _evaluationListener = evaluationListener; _cache = new EvaluationCache(evaluationListener); _sheetIndexesBySheet = new Hashtable(); _sheetIndexesByName = new Dictionary <string, int>(); _collaboratingWorkbookEnvironment = CollaboratingWorkbooksEnvironment.EMPTY; _workbookIx = 0; _stabilityClassifier = stabilityClassifier; AggregatingUDFFinder defaultToolkit = // workbook can be null in unit tests workbook == null ? null : (AggregatingUDFFinder)workbook.GetUDFFinder(); if (defaultToolkit != null && udfFinder != null) { defaultToolkit.Add(udfFinder); } _udfFinder = defaultToolkit; }
private static void HookNewEnvironment(WorkbookEvaluator[] evaluators, CollaboratingWorkbooksEnvironment env) { // All evaluators will need To share the same cache. // but the cache takes an optional evaluation listener. int nItems = evaluators.Length; IEvaluationListener evalListener = evaluators[0].GetEvaluationListener(); // make sure that all evaluators have the same listener for (int i = 0; i < nItems; i++) { if (evalListener != evaluators[i].GetEvaluationListener()) { // This would be very complex To support throw new Exception("Workbook evaluators must all have the same evaluation listener"); } } EvaluationCache cache = new EvaluationCache(evalListener); for (int i = 0; i < nItems; i++) { evaluators[i].AttachToEnvironment(env, cache, i); } }
/** * @return never <c>null</c>, never {@link BlankEval} */ private ValueEval EvaluateAny(IEvaluationCell srcCell, int sheetIndex, int rowIndex, int columnIndex, EvaluationTracker tracker) { bool shouldCellDependencyBeRecorded = _stabilityClassifier == null ? true : !_stabilityClassifier.IsCellFinal(sheetIndex, rowIndex, columnIndex); ValueEval result; if (srcCell == null || srcCell.CellType != CellType.FORMULA) { result = GetValueFromNonFormulaCell(srcCell); if (shouldCellDependencyBeRecorded) { tracker.AcceptPlainValueDependency(_workbookIx, sheetIndex, rowIndex, columnIndex, result); } return(result); } FormulaCellCacheEntry cce = _cache.GetOrCreateFormulaCellEntry(srcCell); if (shouldCellDependencyBeRecorded || cce.IsInputSensitive) { tracker.AcceptFormulaDependency(cce); } IEvaluationListener evalListener = _evaluationListener; if (cce.GetValue() == null) { if (!tracker.StartEvaluate(cce)) { return(ErrorEval.CIRCULAR_REF_ERROR); } OperationEvaluationContext ec = new OperationEvaluationContext(this, _workbook, sheetIndex, rowIndex, columnIndex, tracker); try { Ptg[] ptgs = _workbook.GetFormulaTokens(srcCell); if (evalListener == null) { result = EvaluateFormula(ec, ptgs); } else { evalListener.OnStartEvaluate(srcCell, cce); result = EvaluateFormula(ec, ptgs); evalListener.OnEndEvaluate(cce, result); } tracker.UpdateCacheResult(result); } catch (NotImplementedException e) { throw AddExceptionInfo(e, sheetIndex, rowIndex, columnIndex); } finally { tracker.EndEvaluate(cce); } } else { if (evalListener != null) { evalListener.OnCacheHit(sheetIndex, rowIndex, columnIndex, cce.GetValue()); } return(cce.GetValue()); } if (IsDebugLogEnabled()) { String sheetName = GetSheetName(sheetIndex); CellReference cr = new CellReference(rowIndex, columnIndex); LogDebug("Evaluated " + sheetName + "!" + cr.FormatAsString() + " To " + cce.GetValue().ToString()); } // Usually (result === cce.getValue()) // But sometimes: (result==ErrorEval.CIRCULAR_REF_ERROR, cce.getValue()==null) // When circular references are detected, the cache entry is only updated for // the top evaluation frame //return cce.GetValue(); return(result); }
/** * @return never <c>null</c>, never {@link BlankEval} */ private ValueEval EvaluateAny(IEvaluationCell srcCell, int sheetIndex, int rowIndex, int columnIndex, EvaluationTracker tracker) { bool shouldCellDependencyBeRecorded = _stabilityClassifier == null ? true : !_stabilityClassifier.IsCellFinal(sheetIndex, rowIndex, columnIndex); ValueEval result; if (srcCell == null || srcCell.CellType != CellType.Formula) { result = GetValueFromNonFormulaCell(srcCell); if (shouldCellDependencyBeRecorded) { tracker.AcceptPlainValueDependency(_workbookIx, sheetIndex, rowIndex, columnIndex, result); } return(result); } FormulaCellCacheEntry cce = _cache.GetOrCreateFormulaCellEntry(srcCell); if (shouldCellDependencyBeRecorded || cce.IsInputSensitive) { tracker.AcceptFormulaDependency(cce); } IEvaluationListener evalListener = _evaluationListener; if (cce.GetValue() == null) { if (!tracker.StartEvaluate(cce)) { return(ErrorEval.CIRCULAR_REF_ERROR); } OperationEvaluationContext ec = new OperationEvaluationContext(this, _workbook, sheetIndex, rowIndex, columnIndex, tracker); try { Ptg[] ptgs = _workbook.GetFormulaTokens(srcCell); if (evalListener == null) { result = EvaluateFormula(ec, ptgs); } else { evalListener.OnStartEvaluate(srcCell, cce); result = EvaluateFormula(ec, ptgs); evalListener.OnEndEvaluate(cce, result); } tracker.UpdateCacheResult(result); } catch (NotImplementedException e) { throw AddExceptionInfo(e, sheetIndex, rowIndex, columnIndex); } catch (RuntimeException re) { if (re.InnerException is WorkbookNotFoundException && _ignoreMissingWorkbooks) { LogInfo(re.InnerException.Message + " - Continuing with cached value!"); switch (srcCell.CachedFormulaResultType) { case CellType.Numeric: result = new NumberEval(srcCell.NumericCellValue); break; case CellType.String: result = new StringEval(srcCell.StringCellValue); break; case CellType.Blank: result = BlankEval.instance; break; case CellType.Boolean: result = BoolEval.ValueOf(srcCell.BooleanCellValue); break; case CellType.Error: result = ErrorEval.ValueOf(srcCell.ErrorCellValue); break; case CellType.Formula: default: throw new RuntimeException("Unexpected cell type '" + srcCell.CellType + "' found!"); } } else { throw re; } } finally { tracker.EndEvaluate(cce); } } else { if (evalListener != null) { evalListener.OnCacheHit(sheetIndex, rowIndex, columnIndex, cce.GetValue()); } return(cce.GetValue()); } if (IsDebugLogEnabled()) { string sheetName = GetSheetName(sheetIndex); CellReference cr = new CellReference(rowIndex, columnIndex); LogDebug("Evaluated " + sheetName + "!" + cr.FormatAsString() + " To " + cce.GetValue()); } // Usually (result === cce.getValue()) // But sometimes: (result==ErrorEval.CIRCULAR_REF_ERROR, cce.getValue()==null) // When circular references are detected, the cache entry is only updated for // the top evaluation frame //return cce.GetValue(); return(result); }
/* package */ public EvaluationCache(IEvaluationListener evaluationListener) { _evaluationListener = evaluationListener; _plainCellCache = new PlainCellCache(); _formulaCellCache = new FormulaCellCache(); }
/** * @return never <c>null</c>, never {@link BlankEval} */ private ValueEval EvaluateAny(EvaluationCell srcCell, int sheetIndex, int rowIndex, int columnIndex, EvaluationTracker tracker) { if (srcCell == null || srcCell.CellType != CellType.FORMULA) { ValueEval result = GetValueFromNonFormulaCell(srcCell); tracker.AcceptPlainValueDependency(_workbookIx, sheetIndex, rowIndex, columnIndex, result); return(result); } FormulaCellCacheEntry cce = _cache.GetOrCreateFormulaCellEntry(srcCell); tracker.AcceptFormulaDependency(cce); IEvaluationListener evalListener = _evaluationListener; if (cce.GetValue() == null) { if (!tracker.StartEvaluate(cce)) { return(ErrorEval.CIRCULAR_REF_ERROR); } OperationEvaluationContext ec = new OperationEvaluationContext(this, _workbook, sheetIndex, rowIndex, columnIndex, tracker); try { ValueEval result; Ptg[] ptgs = _workbook.GetFormulaTokens(srcCell); if (evalListener == null) { result = EvaluateFormula(ec, ptgs); } else { evalListener.OnStartEvaluate(srcCell, cce); result = EvaluateFormula(ec, ptgs); evalListener.OnEndEvaluate(cce, result); } tracker.UpdateCacheResult(result); } finally { tracker.EndEvaluate(cce); } } else { if (evalListener != null) { evalListener.OnCacheHit(sheetIndex, rowIndex, columnIndex, cce.GetValue()); } return(cce.GetValue()); } if (IsDebugLogEnabled()) { String sheetName = GetSheetName(sheetIndex); CellReference cr = new CellReference(rowIndex, columnIndex); LogDebug("Evaluated " + sheetName + "!" + cr.FormatAsString() + " To " + cce.GetValue().ToString()); } return(cce.GetValue()); }