/// <summary>
        /// Run formula and apply to passed cell.
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        public Boolean Run(SheetCell cell)
        {
            Boolean returnValue             = default(Boolean);
            FormulaExecutionContext context = default(FormulaExecutionContext);

            try
            {
                //validate settings determined at runtime
                if (!this.Complete())
                {
                    throw new ApplicationException(String.Format("{0}", this.ErrorMessage));
                }

                //run operation
                context = new FormulaExecutionContext(this, cell);
                cell.ValueChangingProgrammatically = true;
                //TODO:invoke with parameter list
                cell.Value = this.Delegate.DynamicInvoke(new ParameterExpression[] { /*Expression.Parameter(typeof(float), "p")*/ }).ToString(); //AssignerOperand.Evaluate(context).ToString();
                //TODO:mvoe this or something like it to wwhere formula is changed.
                //cell.Value = AssignerOperand.Evaluate(context).ToString();
                cell.ValueChangingProgrammatically = false;

                returnValue = true;
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
                cell.ValueChangingProgrammatically = false;
                throw;
            }
            return(returnValue);
        }
 public FormulaExecutionContext(Formula formula, SheetCell cell)
 {
     try
     {
         ExecutingFormula = formula;
         AssigneeCell     = cell;
     }
     catch (Exception ex)
     {
         Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
         throw;
     }
 }
        /// <summary>
        /// Determine if passed cell is among cells to which the formula criteria are applicable.
        /// </summary>
        /// <param name="cell">Specific sheet cell seeking value.</param>
        /// <returns></returns>
        public Boolean IsApplicableFormula(SheetCell cell)
        {
            Boolean          returnValue          = default(Boolean);
            List <SheetCell> formulaSearchResults = default(List <SheetCell>);
            List <SheetCell> cellSearchResults    = default(List <SheetCell>);
            Sheet            sheet = default(Sheet);

            try
            {
                if (this.Complete())
                {
                    //locate parent sheet, containing cells
                    sheet = this.Parent;
                    if (sheet == null)
                    {
                        throw new ApplicationException(String.Format("Unable to find parent sheet for formula: '{0}'", this.Value));
                    }

                    //run formula assigner criteria
                    formulaSearchResults = Sheet.GetCellsWhereAllSearchCategoryItemsMatchAnyInGivenCell(sheet.Cells.ToList <SheetCell>(), AssigneeCriteria);
                    if ((formulaSearchResults == null) || (formulaSearchResults.Count == 0))
                    {
                        throw new ApplicationException(String.Format("Unable to find cells for parent sheet of formula '{0}'", this.Value));
                    }

                    //find single cell in results
                    cellSearchResults = Sheet.GetCellsWhereAllSearchCategoryItemsMatchAnyInGivenCell(formulaSearchResults, cell.CategoryItems.ToList <CategoryItem>());
                    if ((cellSearchResults == null) || (cellSearchResults.Count == 0))
                    {
                        //cell not found; not an error
                    }
                    else
                    {
                        returnValue = true;
                    }
                }
                else
                {
                    //skip over any invalid formulae
                    Log.Write(this.ErrorMessage, EventLogEntryType.Error);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
                //throw;
            }
            return(returnValue);
        }