/// <summary> /// method /// US:902 /// validates the syntax and placeholders for the expression passed in /// </summary> /// <param name="exp"></param> /// <returns></returns> public CStatus Validate(CExpression exp) { CStatus status = ValidateSyntax(exp); if (!status.Status) { return(status); } status = ValidatePlaceHolders(exp.GetIf()); if (!status.Status) { return(status); } status = ValidateActions(exp.GetThen()); if (!status.Status) { return(status); } string strElse = exp.GetElse(); if (!string.IsNullOrEmpty(strElse)) { status = ValidateActions(exp.GetElse()); if (!status.Status) { return(status); } } return(status); }
/// <summary> /// method /// US:902 /// validates the syntax for the expression passed in /// </summary> /// <param name="strExp"></param> /// <returns></returns> private CStatus ValidateSyntax(CExpression Exp) { string strExp = Exp.Expression; if (string.IsNullOrEmpty(strExp)) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_NULL)); } // if the if token is not at the beginning int nIfIndex = strExp.IndexOf(CExpression.IfTkn); if (nIfIndex != 0) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_IF)); } // if there are two if tokens int nIfCount = strExp.Split(new string[] { CExpression.IfTkn }, StringSplitOptions.None).Count() - 1; if (nIfCount > 1) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_IF_DOUBLE)); } // if the then token does not exist int nThenIndex = strExp.IndexOf(CExpression.ThenTkn); if (nThenIndex < 0) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_THEN)); } // if there are two then tokens int nThenCount = strExp.Split(new string[] { CExpression.ThenTkn }, StringSplitOptions.None).Count() - 1; if (nThenCount > 1) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_THEN_DOUBLE)); } if (string.IsNullOrEmpty(Exp.GetIf())) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_IF_EMPTY)); } // if the expression end token is not at the end int nExpEndIndex = strExp.IndexOf(CExpression.EndTkn); if (nExpEndIndex != strExp.Length - 1) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_SEMI)); } // if there are two end tokens int nEndCount = strExp.Split(new char[] { CExpression.EndTkn }, StringSplitOptions.None).Count() - 1; if (nEndCount > 1) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_SEMI_DOUBLE)); } if (string.IsNullOrEmpty(Exp.GetThen())) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_THEN_EMPTY)); } // the else token is not required // if the else token exists int nElseIndex = strExp.IndexOf(CExpression.ElseTkn); if (nElseIndex >= 0) { // if there are two else tokens int nElseCount = strExp.Split(new string[] { CExpression.ElseTkn }, StringSplitOptions.None).Count() - 1; if (nElseCount > 1) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_ELSE_DOUBLE)); } // if the else token is before the then token if (nElseIndex < nThenIndex) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_IF_ELSE_THEN)); } if (string.IsNullOrEmpty(Exp.GetElse())) { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_VALIDATE_ELSE_EMPTY)); } } return(new CStatus(true, k_STATUS_CODE.Success, LogicModuleMessages.SUCCESS_VALIDATE)); }