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: 0x060004C4 RID: 1220 RVA: 0x0001E0A4 File Offset: 0x0001C2A4 public string PreProcessFormula(string formula, ThresholdLevel level, ThresholdOperatorEnum thresholdOperator) { if (string.IsNullOrEmpty(formula)) { return(formula); } if (!this.IsUseBaselineMacro(formula)) { return(formula); } if (this.IsMacro(BusinessLayerSettings.Instance.ThresholdsUseBaselineCriticalCalculationMacro, formula)) { level = ThresholdLevel.Critical; } if (this.IsMacro(BusinessLayerSettings.Instance.ThresholdsUseBaselineWarningCalculationMacro, formula)) { level = ThresholdLevel.Warning; } if (CoreThresholdPreProcessor.IsGreaterOperator(thresholdOperator)) { if (level != ThresholdLevel.Critical) { return(BusinessLayerSettings.Instance.ThresholdsDefaultWarningFormulaForGreater); } return(BusinessLayerSettings.Instance.ThresholdsDefaultCriticalFormulaForGreater); } else { if (level != ThresholdLevel.Critical) { return(BusinessLayerSettings.Instance.ThresholdsDefaultWarningFormulaForLess); } return(BusinessLayerSettings.Instance.ThresholdsDefaultCriticalFormulaForLess); } }
public string PreProcessFormula( string formula, ThresholdLevel level, ThresholdOperatorEnum thresholdOperator) { if (string.IsNullOrEmpty(formula) || !this.IsUseBaselineMacro(formula)) return formula; if (this.IsMacro(BusinessLayerSettings.Instance.ThresholdsUseBaselineCriticalCalculationMacro, formula)) level = (ThresholdLevel) 2; if (this.IsMacro(BusinessLayerSettings.Instance.ThresholdsUseBaselineWarningCalculationMacro, formula)) level = (ThresholdLevel) 1; return CoreThresholdPreProcessor.IsGreaterOperator(thresholdOperator) ? (level != 2 ? BusinessLayerSettings.Instance.ThresholdsDefaultWarningFormulaForGreater : BusinessLayerSettings.Instance.ThresholdsDefaultCriticalFormulaForGreater) : (level != 2 ? BusinessLayerSettings.Instance.ThresholdsDefaultWarningFormulaForLess : BusinessLayerSettings.Instance.ThresholdsDefaultCriticalFormulaForLess); }
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); }
public ValidationResult PreValidateFormula( string formula, ThresholdLevel level, ThresholdOperatorEnum thresholdOperator) { if (string.IsNullOrEmpty(formula)) return new ValidationResult(false, string.Format(Resources.get_LIBCODE_PC0_01())); if (this.IsUseBaselineMacro(formula)) { if (thresholdOperator == 2 || thresholdOperator == 5) return new ValidationResult(false, string.Format(Resources.get_LIBCODE_ZT0_11(), (object) formula)); } else { if (this.ContainsMacro(BusinessLayerSettings.Instance.ThresholdsUseBaselineCalculationMacro, formula)) return new ValidationResult(false, string.Format(Resources.get_LIBCODE_ZT0_17(), (object) BusinessLayerSettings.Instance.ThresholdsUseBaselineCalculationMacro)); if (this.ContainsMacro(BusinessLayerSettings.Instance.ThresholdsUseBaselineWarningCalculationMacro, formula)) return new ValidationResult(false, string.Format(Resources.get_LIBCODE_ZT0_17(), (object) BusinessLayerSettings.Instance.ThresholdsUseBaselineWarningCalculationMacro)); if (this.ContainsMacro(BusinessLayerSettings.Instance.ThresholdsUseBaselineCriticalCalculationMacro, formula)) return new ValidationResult(false, string.Format(Resources.get_LIBCODE_ZT0_17(), (object) BusinessLayerSettings.Instance.ThresholdsUseBaselineCriticalCalculationMacro)); } return ValidationResult.CreateValid(); }
private static bool IsGreaterOperator(ThresholdOperatorEnum thresholdOperator) { return thresholdOperator == null || thresholdOperator == 1; }
// Token: 0x060004C6 RID: 1222 RVA: 0x0001E210 File Offset: 0x0001C410 private static bool IsGreaterOperator(ThresholdOperatorEnum thresholdOperator) { return(thresholdOperator == ThresholdOperatorEnum.Greater || thresholdOperator == ThresholdOperatorEnum.GreaterOrEqual); }
// Token: 0x060004C5 RID: 1221 RVA: 0x0001E130 File Offset: 0x0001C330 public ValidationResult PreValidateFormula(string formula, ThresholdLevel level, ThresholdOperatorEnum thresholdOperator) { if (string.IsNullOrEmpty(formula)) { return(new ValidationResult(false, string.Format(Resources.LIBCODE_PC0_01, Array.Empty <object>()))); } if (this.IsUseBaselineMacro(formula)) { if (thresholdOperator == ThresholdOperatorEnum.Equal || thresholdOperator == ThresholdOperatorEnum.NotEqual) { return(new ValidationResult(false, string.Format(Resources.LIBCODE_ZT0_11, formula))); } } else { if (this.ContainsMacro(BusinessLayerSettings.Instance.ThresholdsUseBaselineCalculationMacro, formula)) { return(new ValidationResult(false, string.Format(Resources.LIBCODE_ZT0_17, BusinessLayerSettings.Instance.ThresholdsUseBaselineCalculationMacro))); } if (this.ContainsMacro(BusinessLayerSettings.Instance.ThresholdsUseBaselineWarningCalculationMacro, formula)) { return(new ValidationResult(false, string.Format(Resources.LIBCODE_ZT0_17, BusinessLayerSettings.Instance.ThresholdsUseBaselineWarningCalculationMacro))); } if (this.ContainsMacro(BusinessLayerSettings.Instance.ThresholdsUseBaselineCriticalCalculationMacro, formula)) { return(new ValidationResult(false, string.Format(Resources.LIBCODE_ZT0_17, BusinessLayerSettings.Instance.ThresholdsUseBaselineCriticalCalculationMacro))); } } return(ValidationResult.CreateValid()); }
// 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); }