in src/CTA.Rules.Update/CodeReplacer.cs [236:284]
public List<GenericActionExecution> ValidateActions(List<GenericActionExecution> actions, SyntaxNode root)
{
// Matches all types of comments and strings
//string regComments = @"\/\*(?:(?!\*\/)(?:.|[\r\n]+))*\*\/|\/\/(.*?)\r?\n|""((\\[^\n]|[^""\n])*)""|@(""[^""""]*"")+";
//We should only validate actions that did not throw an exception during execution.
var validActions = actions.Where(a => a.InvalidExecutions == 0).ToList();
foreach (var action in validActions)
{
var actionValidation = action.ActionValidation;
string trimmedResult;
var actionValid = true;
if (actionValidation == null) { continue; }
if (string.IsNullOrEmpty(actionValidation.CheckComments) || !bool.Parse(actionValidation.CheckComments))
{
trimmedResult = Utils.EscapeAllWhitespace(root.NoComments().NormalizeWhitespace().ToFullString());
}
else
{
trimmedResult = Utils.EscapeAllWhitespace(root.NormalizeWhitespace().ToFullString());
}
var contains = !string.IsNullOrEmpty(actionValidation.Contains) ? Utils.EscapeAllWhitespace(actionValidation.Contains) : string.Empty;
var notContains = !string.IsNullOrEmpty(actionValidation.NotContains) ? Utils.EscapeAllWhitespace(actionValidation.NotContains) : string.Empty;
if (!string.IsNullOrEmpty(contains) && !trimmedResult.Contains(contains))
{
//Validation token is not in the result source file:
actionValid = false;
}
if (!string.IsNullOrEmpty(notContains) && trimmedResult.Contains(notContains))
{
//Validation Negative token is in the result source file:
actionValid = false;
}
//Action is not valid, but didn't throw an exception (we don't want to log an invalid execution twice)
if (!actionValid && action.InvalidExecutions == 0)
{
var actionValidationException = new ActionValidationException(action.Key, action.Name);
action.InvalidExecutions = 1;
LogHelper.LogError(actionValidationException);
}
}
return actions;
}