public ValidationResult IsFormulaValid( string formula, ThresholdLevel level, ThresholdOperatorEnum thresholdOperator) { if (this.get_Log().get_IsDebugEnabled()) { this.get_Log().DebugFormat("Validating formula: {0} ...", (object)formula); } ValidationResult validationResult; try { validationResult = this._preProcessor.PreValidateFormula(formula, level, thresholdOperator); if (validationResult.get_IsValid()) { formula = this._preProcessor.PreProcessFormula(formula, level, thresholdOperator); this._variables = CoreThresholdProcessor.CreateVariables(CoreThresholdProcessor.CreateDefaultBaselineValues()); this.TryParse(formula, true); validationResult = ValidationResult.CreateValid(); } } catch (InvalidInputException ex) { validationResult = !ex.get_HasError() ? new ValidationResult(false, ((Exception)ex).Message) : new ValidationResult(false, (IEnumerable <string>)((IEnumerable <ExprEvalErrorDescription>)ex.get_Errors()).Select <ExprEvalErrorDescription, string>((Func <ExprEvalErrorDescription, string>)(er => CoreThresholdProcessor.GetErrorMessage(er))).ToArray <string>()); } catch (Exception ex) { this.get_Log().Error((object)string.Format("Unexpected error when validating formula: {0} ", (object)formula), ex); validationResult = new ValidationResult(false, ex.Message); } return(validationResult); }
// Token: 0x060004CF RID: 1231 RVA: 0x0001E3F8 File Offset: 0x0001C5F8 public double ComputeThreshold(string formula, BaselineValues baselineValues, ThresholdLevel level, ThresholdOperatorEnum thresholdOperator) { if (base.Log.IsVerboseEnabled) { base.Log.VerboseFormat("Computing formula: {0}, values: [{1}]", new object[] { formula, baselineValues }); } if (string.IsNullOrEmpty(formula)) { return(0.0); } double result; try { formula = this._preProcessor.PreProcessFormula(formula, level, thresholdOperator); this._variables = CoreThresholdProcessor.CreateVariables(baselineValues); result = base.EvaluateDynamic(formula, this._variables, null); } catch (InvalidInputException ex) { string text; if (ex.HasError) { text = string.Join(" ", ex.Errors.Select(new Func <ExprEvalErrorDescription, string>(CoreThresholdProcessor.GetErrorMessage)).ToArray <string>()); } else { text = ex.Message; } if (base.Log.IsInfoEnabled) { base.Log.Info(string.Format("Parsing error: {0} when evaluating formula: {1}, values: {2}", text, formula, baselineValues), ex); } throw new Exception(text, ex); } catch (Exception ex2) { base.Log.Error(string.Format("Unexpected error when evaluating formula: {0}, values: {1}", formula, baselineValues), ex2); throw; } return(result); }
public double ComputeThreshold( string formula, BaselineValues baselineValues, ThresholdLevel level, ThresholdOperatorEnum thresholdOperator) { if (this.get_Log().get_IsVerboseEnabled()) { this.get_Log().VerboseFormat("Computing formula: {0}, values: [{1}]", new object[2] { (object)formula, (object)baselineValues }); } if (string.IsNullOrEmpty(formula)) { return(0.0); } try { formula = this._preProcessor.PreProcessFormula(formula, level, thresholdOperator); this._variables = CoreThresholdProcessor.CreateVariables(baselineValues); return(this.EvaluateDynamic(formula, (IDictionary <string, Variable>) this._variables, (object)null)); } catch (InvalidInputException ex) { string message = !ex.get_HasError() ? ((Exception)ex).Message : string.Join(" ", ((IEnumerable <ExprEvalErrorDescription>)ex.get_Errors()).Select <ExprEvalErrorDescription, string>(new Func <ExprEvalErrorDescription, string>(CoreThresholdProcessor.GetErrorMessage)).ToArray <string>()); if (this.get_Log().get_IsInfoEnabled()) { this.get_Log().Info((object)string.Format("Parsing error: {0} when evaluating formula: {1}, values: {2}", (object)message, (object)formula, (object)baselineValues), (Exception)ex); } throw new Exception(message, (Exception)ex); } catch (Exception ex) { this.get_Log().Error((object)string.Format("Unexpected error when evaluating formula: {0}, values: {1}", (object)formula, (object)baselineValues), ex); throw; } }
// Token: 0x060004CE RID: 1230 RVA: 0x0001E2F0 File Offset: 0x0001C4F0 public ValidationResult IsFormulaValid(string formula, ThresholdLevel level, ThresholdOperatorEnum thresholdOperator) { if (base.Log.IsDebugEnabled) { base.Log.DebugFormat("Validating formula: {0} ...", formula); } ValidationResult validationResult; try { validationResult = this._preProcessor.PreValidateFormula(formula, level, thresholdOperator); if (validationResult.IsValid) { formula = this._preProcessor.PreProcessFormula(formula, level, thresholdOperator); this._variables = CoreThresholdProcessor.CreateVariables(CoreThresholdProcessor.CreateDefaultBaselineValues()); base.TryParse(formula, true); validationResult = ValidationResult.CreateValid(); } } catch (InvalidInputException ex) { if (ex.HasError) { validationResult = new ValidationResult(false, (from er in ex.Errors select CoreThresholdProcessor.GetErrorMessage(er)).ToArray <string>()); } else { validationResult = new ValidationResult(false, ex.Message); } } catch (Exception ex2) { base.Log.Error(string.Format("Unexpected error when validating formula: {0} ", formula), ex2); validationResult = new ValidationResult(false, ex2.Message); } return(validationResult); }
private static string GetErrorMessage(ExprEvalErrorDescription err) { switch ((int)err.get_Type()) { case 0: return(err.get_Message()); case 1: case 2: return(string.IsNullOrEmpty(err.get_InvalidText()) ? string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.get_LIBCODE_ZT0_12(), (object)err.get_CharPosition()) : string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.get_LIBCODE_ZT0_13(), (object)err.get_InvalidText(), (object)err.get_CharPosition())); case 3: return(string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.get_LIBCODE_ZT0_14(), (object)CoreThresholdProcessor.FormatVariable(err.get_InvalidText()))); case 4: return(string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.get_LIBCODE_ZT0_15(), (object)err.get_InvalidText())); case 5: return(string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.get_LIBCODE_ZT0_16(), (object)err.get_InvalidText())); default: return(string.Empty); } }
private Variable ConvertVariable(string name) { if (string.IsNullOrEmpty(name)) { throw new Exception("Variable name can't be null or empty."); } string lowerInvariant = name.ToLowerInvariant(); if (this._variables.ContainsKey(lowerInvariant)) { return(this._variables[lowerInvariant]); } throw new Exception(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Can't convert variable {0}.", (object)CoreThresholdProcessor.FormatVariable(name))); }
// Token: 0x060004D4 RID: 1236 RVA: 0x0001E750 File Offset: 0x0001C950 private static string GetErrorMessage(ExprEvalErrorDescription err) { switch (err.Type) { case ExprEvalErrorType.GeneralError: return(err.Message); case ExprEvalErrorType.LexerError: case ExprEvalErrorType.ParsingError: if (string.IsNullOrEmpty(err.InvalidText)) { return(string.Format(CultureInfo.InvariantCulture, Resources.LIBCODE_ZT0_12, err.CharPosition)); } return(string.Format(CultureInfo.InvariantCulture, Resources.LIBCODE_ZT0_13, err.InvalidText, err.CharPosition)); case ExprEvalErrorType.UnknownVariable: return(string.Format(CultureInfo.InvariantCulture, Resources.LIBCODE_ZT0_14, CoreThresholdProcessor.FormatVariable(err.InvalidText))); case ExprEvalErrorType.UnknownFunction: return(string.Format(CultureInfo.InvariantCulture, Resources.LIBCODE_ZT0_15, err.InvalidText)); case ExprEvalErrorType.InvalidParametersCount: return(string.Format(CultureInfo.InvariantCulture, Resources.LIBCODE_ZT0_16, err.InvalidText)); default: return(string.Empty); } }