Exemplo n.º 1
0
        /// <summary>
        /// Evaluate the expression according to the operation specified and pass this to the CalculationManager
        //  If something goes wrong during the execution, the error field will be populated and the method will
        //  return false.
        /// </summary>
        /// <param name="expressionTO">The expression automatic.</param>
        /// <param name="evaluation">The evaluation.</param>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        public bool TryEvaluateFunction(IEvaluationFunction expressionTO, out string evaluation, out string error)
        {
            bool isSuccessfulEvaluation;

            error      = string.Empty;
            evaluation = string.Empty;

            if (!(string.IsNullOrEmpty(expressionTO.Function)))
            {
                try
                {
                    CalculationValue calcVal = _manager.CalculateFormula(expressionTO.Function);
                    evaluation             = calcVal.GetResolvedValue().ToString();
                    isSuccessfulEvaluation = true;
                }
                catch (Exception ex)
                {
                    Dev2Logger.Log.Error("Function evaluation Error", ex);
                    error = ex.Message;
                    isSuccessfulEvaluation = false;
                }
            }
            else
            {
                error = "Unable to evaluate empty function";
                isSuccessfulEvaluation = false;
            }

            return(isSuccessfulEvaluation);
        }
Exemplo n.º 2
0
        public bool TryEvaluateFunction(string expression, out string evaluation, out string error)
        {
            var evaluationState = false;

            error      = string.Empty;
            evaluation = string.Empty;
            if (!string.IsNullOrEmpty(expression))
            {
                try
                {
                    var value = _manager.CalculateFormula(expression);
                    if (value.IsError)
                    {
                        error = value.ToErrorValue().Message;
                    }
                    else
                    {
                        evaluation      = value.IsDateTime ? PerformEvaluation(value) : value.GetResolvedValue().ToString();
                        evaluationState = true;
                    }
                }
                catch (Exception ex)
                {
                    Dev2Logger.Error(ErrorResource.FunctionEvaluationError, ex, GlobalConstants.WarewolfError);
                    error           = ex.Message;
                    evaluationState = false;
                }
            }
            else
            {
                error = ErrorResource.NothingToEvaluate;
            }

            return(evaluationState);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Evaluate the expression according to the operation specified and pass this to the CalculationManager
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="evaluation">The evaluation.</param>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        public bool TryEvaluateFunction(string expression, out string evaluation, out string error)
        {
            bool evaluationState = false;

            error      = String.Empty;
            evaluation = String.Empty;
            if (!String.IsNullOrEmpty(expression))
            {
                try
                {
                    CalculationValue value = _manager.CalculateFormula(expression);
                    if (value.IsError)
                    {
                        error = value.ToErrorValue().Message;
                    }
                    else
                    {
                        if (value.IsDateTime)
                        {
                            DateTime dateTime     = value.ToDateTime();
                            string   shortPattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
                            string   longPattern  = CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern;
                            string   finalPattern = shortPattern + " " + longPattern;
                            if (finalPattern.Contains("ss"))
                            {
                                finalPattern = finalPattern.Insert(finalPattern.IndexOf("ss", StringComparison.Ordinal) + 2, ".fff");
                            }
                            evaluation = dateTime.ToString(finalPattern);
                        }
                        else
                        {
                            evaluation = value.GetResolvedValue().ToString();
                        }
                        evaluationState = true;
                    }
                }
                catch (Exception ex)
                {
                    Dev2Logger.Error(ErrorResource.FunctionEvaluationError, ex);
                    error           = ex.Message;
                    evaluationState = false;
                }
            }
            else
            {
                error = ErrorResource.NothingToEvaluate;
            }

            return(evaluationState);
        }