private static InspectionResult Execute(IActivityModel activityModel, Rule ruleInstance) { return(new InspectionResult() { HasErrors = false, RecommendationMessage = "Everything is perfect!" }); }
private static InspectionResult Inspect(IActivityModel activity, Rule ruleInstance) { var result = new InspectionResult(); List <ActivityPropertySetting> settings = GetSettingsEntries(ruleInstance); if (settings == null) { return(result); } var activityType = activity.Type.SubstringBefore(','); if (ActivityBreaksRule(activityType, activity.Properties, settings, out string message)) { result.Messages.Add(message); } if (result.Messages.Count > 0) { result.HasErrors = true; result.ErrorLevel = TraceLevel.Error; result.RecommendationMessage = ruleInstance.RecommendationMessage; } return(result); }
// This is the function that executes for each activity in all the files. Might impact performance. // The rule instance is the rule provided above which also contains the user-configured data. private static InspectionResult Inspect(IActivityModel activityModel, Rule ruleInstance) { var messageList = new List <string>(); foreach (var activityModelVariable in activityModel.Variables) { if (activityModelVariable.DisplayName.Length > 40) { messageList.Add($"The variable {activityModelVariable.DisplayName} has a length longer than 40"); } } if (messageList.Count > 0) { return(new InspectionResult() { ErrorLevel = ruleInstance.ErrorLevel, HasErrors = true, RecommendationMessage = ruleInstance.RecommendationMessage, // When inspecting a model, a rule can generate more than one message. Messages = messageList }); } else { return(new InspectionResult() { HasErrors = false }); } }
private static InspectionResult Inspect(IActivityModel activityModel, Rule ruleInstance) { var messageList = new List <string>(); var str = activityModel.Type; string defaultDisplayName = (str.Split(',')[0]).Split('.')[(str.Split(',')[0]).Split('.').Length - 1]; //the current DisplayName shouldn't be equal to the default display name but it should atleast contain it if (activityModel.DisplayName.ToLower().Equals(defaultDisplayName.ToLower()) || !activityModel.DisplayName.ToLower().Contains(defaultDisplayName.ToLower())) { messageList.Add(string.Format(Strings.ST_ACC_004_ErrorFormat, activityModel.DisplayName, defaultDisplayName)); } if (messageList.Count > 0) { return(new InspectionResult() { ErrorLevel = ruleInstance.ErrorLevel, HasErrors = true, RecommendationMessage = ruleInstance.RecommendationMessage, Messages = messageList, DocumentationLink = ruleInstance.DocumentationLink }); } else { return(new InspectionResult() { HasErrors = false }); } }
private static InspectionResult Inspect(IActivityModel activityModel, Rule ruleInstance) { var messageList = new List <string>(); //stuff that deals with just the activity messageList.Add(string.Format("activityModel.DisplayName: {0}", activityModel.DisplayName)); messageList.Add(string.Format("activityModel.Type: {0}", activityModel.Type)); messageList.Add(string.Format("activityModel.Type: {0}", activityModel.Parent.DisplayName)); messageList.Add(string.Format("activityModel.Parent.DisplayName: {0}", activityModel.Parent.DisplayName)); messageList.Add(string.Format("activityModel.Context.Project.DisplayName: {0}", activityModel.Context.Project.DisplayName)); foreach (var arg in activityModel.Arguments) { messageList.Add(string.Format("arg.DisplayName: {0}", arg.DisplayName)); } foreach (var child in activityModel.Children) { messageList.Add(string.Format("child.DisplayName: {0}", child.DisplayName)); } foreach (var property in activityModel.Properties) { messageList.Add(string.Format("property.DisplayName: {0}", property.DisplayName)); } foreach (var variables in activityModel.Variables) { messageList.Add(string.Format("variables.DisplayName: {0}", variables.DisplayName)); } foreach (var variables in activityModel.Context.Variables) { messageList.Add(string.Format("activityModel.Context.Variables var: {0}", variables.DisplayName)); } if (messageList.Count > 0) { return(new InspectionResult() { ErrorLevel = ruleInstance.ErrorLevel, HasErrors = true, RecommendationMessage = ruleInstance.RecommendationMessage, Messages = messageList, DocumentationLink = ruleInstance.DocumentationLink }); } else { return(new InspectionResult() { HasErrors = false }); } }
private InspectionResult InspectVariableForString(IActivityModel activityToInspect, Rule configuredRule) { var configuredString = configuredRule.Parameters["string_in_variable"]?.Value; if (string.IsNullOrEmpty(configuredString)) { return(new InspectionResult() { HasErrors = false }); } if (activityToInspect.Variables.Count == 0) { return(new InspectionResult() { HasErrors = false }); } var messageList = new List <InspectionMessage>(); foreach (var variable in activityToInspect.Variables) { if (variable.DisplayName.Contains(configuredString)) { messageList.Add(new InspectionMessage() { Message = $"Variable {variable.DisplayName} contains an illegal string: {configuredString}" }); } } if (messageList.Count > 0) { return(new InspectionResult() { HasErrors = true, InspectionMessages = messageList, RecommendationMessage = "Fix your naming", ErrorLevel = configuredRule.ErrorLevel }); } return(new InspectionResult() { HasErrors = false }); }
private InspectionResult InspectVariableForString(IActivityModel activityToInspect, Rule configuredRule) { if (activityToInspect.Variables.Count == 0) { return(new InspectionResult() { HasErrors = false }); } var messageList = new List <InspectionMessage>(); foreach (var variable in activityToInspect.Variables) { //BOOLEAN EXPRESSION CHECK RULE, HAS TO BE DONE FOR ARGUMENTS AS WELL(ADD RECOMMENDATION MESSAGE AS WELL) if (variable.Type.ToString().Contains("System.Boolean")) { if ((variable.DisplayName.ToString().Trim().ToLower().StartsWith("has_")) || (variable.DisplayName.ToString().Trim().ToLower().StartsWith("is_")) || (variable.DisplayName.ToString().ToLower().EndsWith("_exists"))) { continue; } else { messageList.Add(new InspectionMessage() { Message = $"Variable { variable.DisplayName } does not follow the required naming convention of the boolean variables" }); } } } if (messageList.Count > 0) { return(new InspectionResult() { HasErrors = true, InspectionMessages = messageList, RecommendationMessage = "Boolean variable does not follow the required naming convention", ErrorLevel = configuredRule.ErrorLevel }); } return(new InspectionResult() { HasErrors = false }); }
private InspectionResult InspectVariableForString(IActivityModel activityToInspect, Rule configuredRule) { if (activityToInspect.Variables.Count == 0) { return(new InspectionResult() { HasErrors = false }); } var messageList = new List <InspectionMessage>(); foreach (var activity in activityToInspect.Children) { // BCC Rule(ADD RECOMMENDATION MESSAGE AS WELL) if (activity.Type.ToString().Contains("UiPath.Mail.Activities")) { foreach (var temp in activity.Arguments) { if (temp.DisplayName == "Bcc" && !(string.IsNullOrEmpty(temp.DefinedExpression))) { messageList.Add(new InspectionMessage() { Message = $"BCC was found in {activity.DisplayName.ToString()} with email address as { temp.DefinedExpression.ToString() }" }); } } } } if (messageList.Count > 0) { return(new InspectionResult() { HasErrors = true, InspectionMessages = messageList, RecommendationMessage = "Please check Bcc property in Send Mail activity and validate the email addresses before deploying", ErrorLevel = configuredRule.ErrorLevel }); } return(new InspectionResult() { HasErrors = false }); }
private static InspectionResult Inspect(IActivityModel activityModel, Rule ruleInstance) { var messageList = new List <string>(); // This retrieves the parameter value from the rule instance as configured by the user, if not, the default value. var lowerBound = ruleInstance.Parameters[lowerRange].Value; var upperBound = ruleInstance.Parameters[upperRange].Value; /* * to get the default value just check if the parameters are null and then set it to whatever */ if (lowerBound == null) { messageList.Add(defaultValue); } if (upperBound == null) { messageList.Add(defaultValue); } messageList.Add("ruleInstance.Parameters[lowerRange].Value: " + ruleInstance.Parameters[lowerRange].Value); messageList.Add("ruleInstance.Parameters[upperRange].Value: " + ruleInstance.Parameters[upperRange].Value); messageList.Add("ruleInstance.Parameters[lowerRange].Key: " + ruleInstance.Parameters[lowerRange].Key); messageList.Add("ruleInstance.Parameters[upperRange].Key: " + ruleInstance.Parameters[upperRange].Key); messageList.Add("LOWER BOUND: " + lowerBound); messageList.Add("UPPER BOUND: " + upperBound); if (messageList.Count > 0) { return(new InspectionResult() { ErrorLevel = ruleInstance.ErrorLevel, HasErrors = true, RecommendationMessage = ruleInstance.RecommendationMessage, Messages = messageList, DocumentationLink = "google.com" }); } else { return(new InspectionResult() { HasErrors = false }); } }
private static InspectionResult Inspect(IActivityModel activityModel, Rule ruleInstance) { /* * possible improvement would be making a better lowerCamelCase regex pattern * maybe introduce logic to break my word and then check beginning of each word after first * to see if it is uppercase etc */ var regex = new Regex(lowerCamelCaseRegex); var messageList = new List <string>(); foreach (var activityModelVariable in activityModel.Variables) { if (!regex.IsMatch(activityModelVariable.DisplayName)) { messageList.Add(string.Format(Strings.ST_ACC_002_ErrorFormat, activityModelVariable.DisplayName)); //messageList.Add(string.Format("activityModelVariable default value: {0} activityModelVariable defined expression: {1} activityModelVariable display name: {2} activityModelVariable type: {3}", activityModelVariable.DefaultValue, activityModelVariable.DefinedExpression, activityModelVariable.DisplayName, activityModelVariable.Type)); } } if (messageList.Count > 0) { return(new InspectionResult() { ErrorLevel = ruleInstance.ErrorLevel, HasErrors = true, RecommendationMessage = ruleInstance.RecommendationMessage, Messages = messageList, DocumentationLink = ruleInstance.DocumentationLink }); } else { return(new InspectionResult() { HasErrors = false }); } }
public static InspectionResult Execute(IActivityModel activity, Rule instance) { if (string.IsNullOrWhiteSpace(activity.Type) || !activity.Type.Contains("ClickImage")) { return new InspectionResult() { HasErrors = false } } ; var imageClickAccuracy = activity.Properties.Where(i => i.Type.Contains("ImageTarget")) .SelectMany(i => i.Arguments) .FirstOrDefault(i => i.DisplayName == "Accuracy"); return(new InspectionResult() { ErrorLevel = TraceLevel.Error, HasErrors = Convert.ToDouble(imageClickAccuracy.DefinedExpression) < 0.9, RecommendationMessage = "Accuracy needs to be greater to 0.9" }); } }
private static bool ContainLogMessage(IActivityModel activityModel) { bool isLogmessagePresent = false; if (activityModel.Children.Count == 0) { var ActivityType = activityModel.Type; var activityTypeData = ActivityType.Split(','); if (activityTypeData.Length > 0 && activityTypeData[0].Contains(".")) { var activityNameOnly = activityTypeData[0].Substring(activityTypeData[0].LastIndexOf('.') + 1); if (activityNameOnly.ToLower() == "logmessage") { isLogmessagePresent = true; } } } else { var ActivityTypeTop = activityModel.Type; var activityTypeDataTop = ActivityTypeTop.Split(','); if (activityTypeDataTop.Length > 0 && activityTypeDataTop[0].Contains(".")) { var activityNameOnly = activityTypeDataTop[0].Substring(activityTypeDataTop[0].LastIndexOf('.') + 1); if (activityNameOnly.ToLower() == "commentout") { isLogmessagePresent = false; } else { foreach (var activity in activityModel.Children) { isLogmessagePresent = ContainLogMessage(activity); if (isLogmessagePresent) { break; } } } } //foreach (var activity in activityModel.Children) //{ // var ActivityType = activity.Type; // var activityTypeData = ActivityType.Split(','); // if (activityTypeData.Length > 0 && activityTypeData[0].Contains(".")) // { // var activityNameOnly = activityTypeData[0].Substring(activityTypeData[0].LastIndexOf('.') + 1); // if (activityNameOnly.ToLower() == "logmessage") // { // isLogmessagePresent = true; // } // } //} } return(isLogmessagePresent); }
public static string GetActivityId(this IActivityModel activityModel) { return(activityModel.Properties.FirstOrDefault(p => p.DisplayName == "Id")?.DefinedExpression); }
private static InspectionResult Inspect(IActivityModel activityModel, Rule ruleInstance) { var regex = new Regex(alphabeticRegex); var messageList = new List <string>(); // This retrieves the parameter value from the rule instance as configured by the user, if not, the default value. var min = ruleInstance.Parameters[minimumKey].Value; var max = ruleInstance.Parameters[maximumKey].Value; int lowerBound, upperBound; if (min == null) { lowerBound = Int32.Parse(minimumLength); } else { lowerBound = Int32.Parse(min); } if (max == null) { upperBound = Int32.Parse(maximumLength); } else { upperBound = Int32.Parse(max); } foreach (var activityModelVariable in activityModel.Variables) { //The name should contain ONLY alphabetic characters. if (!regex.IsMatch(activityModelVariable.DisplayName)) { messageList.Add(string.Format(Strings.ST_ACC_009_ErrorFormatActivityVariableName, activityModelVariable.DisplayName)); } //checking if variables they fall within length restraints if (activityModelVariable.DisplayName.Length < lowerBound || activityModelVariable.DisplayName.Length > upperBound) { messageList.Add(string.Format(Strings.ST_ACC_009_ErrorFormatActivityVariableLength, activityModelVariable.DisplayName, lowerBound, upperBound)); } } if (messageList.Count > 0) { return(new InspectionResult() { ErrorLevel = ruleInstance.ErrorLevel, HasErrors = true, RecommendationMessage = ruleInstance.RecommendationMessage, Messages = messageList, DocumentationLink = ruleInstance.DocumentationLink }); } else { return(new InspectionResult() { HasErrors = false }); } }