/// <summary> /// Add actions to each node type /// </summary> /// <param name="nodeToken">The token to add the action to</param> /// <param name="actions">The list of actions associated with this token</param> private void ParseActions(NodeToken nodeToken, List <Action> actions) { foreach (var action in actions) { try { var actionType = Enum.Parse(typeof(ActionTypes), action.Type); switch (actionType) { case ActionTypes.Method: { var actionFunc = actionsLoader.GetInvocationExpressionAction(action.Name, action.Value); if (actionFunc != null) { nodeToken.InvocationExpressionActions.Add(new InvocationExpressionAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, InvocationExpressionActionFunc = actionFunc }); } break; } case ActionTypes.Expression: { var actionFunc = actionsLoader.GetExpressionAction(action.Name, action.Value); if (actionFunc != null) { nodeToken.ExpressionActions.Add(new ExpressionAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, ExpressionActionFunc = actionFunc }); } break; } case ActionTypes.Class: { var actionFunc = actionsLoader.GetClassAction(action.Name, action.Value); if (actionFunc != null) { nodeToken.ClassDeclarationActions.Add(new ClassDeclarationAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, ClassDeclarationActionFunc = actionFunc }); } break; } case ActionTypes.Interface: { var actionFunc = actionsLoader.GetInterfaceAction(action.Name, action.Value); if (actionFunc != null) { nodeToken.InterfaceDeclarationActions.Add(new InterfaceDeclarationAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, InterfaceDeclarationActionFunc = actionFunc }); } break; } case ActionTypes.Using: { var actionFunc = actionsLoader.GetCompilationUnitAction(action.Name, action.Value); if (actionFunc != null) { nodeToken.UsingActions.Add(new UsingAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, UsingActionFunc = actionFunc }); } break; } case ActionTypes.Namespace: { var actionFunc = actionsLoader.GetNamespaceActions(action.Name, action.Value); if (actionFunc != null) { nodeToken.NamespaceActions.Add(new NamespaceAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, NamespaceActionFunc = actionFunc }); } break; } case ActionTypes.Identifier: { var actionFunc = actionsLoader.GetIdentifierNameAction(action.Name, action.Value); if (actionFunc != null) { nodeToken.IdentifierNameActions.Add(new IdentifierNameAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, IdentifierNameActionFunc = actionFunc }); } break; } case ActionTypes.Attribute: { var actionFunc = actionsLoader.GetAttributeAction(action.Name, action.Value); if (actionFunc != null) { nodeToken.AttributeActions.Add(new AttributeAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, AttributeActionFunc = actionFunc }); } break; } case ActionTypes.AttributeList: { var actionFunc = actionsLoader.GetAttributeListAction(action.Name, action.Value); if (actionFunc != null) { nodeToken.AttributeListActions.Add(new AttributeAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, AttributeListActionFunc = actionFunc }); } break; } case ActionTypes.ObjectCreation: { var actionFunc = actionsLoader.GetObjectCreationExpressionActions(action.Name, action.Value); if (actionFunc != null) { nodeToken.ObjectCreationExpressionActions.Add(new ObjectCreationExpressionAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, ObjectCreationExpressionGenericActionFunc = actionFunc }); } break; } case ActionTypes.MethodDeclaration: { var actionFunc = actionsLoader.GetMethodDeclarationAction(action.Name, action.Value); if (actionFunc != null) { nodeToken.MethodDeclarationActions.Add(new MethodDeclarationAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, MethodDeclarationActionFunc = actionFunc }); } break; } case ActionTypes.ElementAccess: { var actionFunc = actionsLoader.GetElementAccessExpressionActions(action.Name, action.Value); if (actionFunc != null) { nodeToken.ElementAccessActions.Add(new ElementAccessAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, ElementAccessExpressionActionFunc = actionFunc }); } break; } case ActionTypes.MemberAccess: { var actionFunc = actionsLoader.GetMemberAccessExpressionActions(action.Name, action.Value); if (actionFunc != null) { nodeToken.MemberAccessActions.Add(new MemberAccessAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, MemberAccessActionFunc = actionFunc }); } break; } case ActionTypes.Project: { var actionFunc = actionsLoader.GetProjectLevelActions(action.Name, action.Value); if (actionFunc != null) { nodeToken.ProjectLevelActions.Add(new ProjectLevelAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, ProjectLevelActionFunc = actionFunc }); } break; } case ActionTypes.ProjectFile: { var actionFunc = actionsLoader.GetProjectFileActions(action.Name, action.Value); if (actionFunc != null) { nodeToken.ProjectFileActions.Add(new ProjectLevelAction() { Key = nodeToken.Key, Value = GetActionValue(action.Value), Description = action.Description, ActionValidation = action.ActionValidation, Name = action.Name, Type = action.Type, ProjectFileActionFunc = actionFunc }); } break; } case ActionTypes.Package: { PackageAction packageAction = new PackageAction(); if (action.Value is string) { packageAction.Name = action.Value; } else { Dictionary <string, string> jsonParameters = JsonConvert.DeserializeObject <Dictionary <string, string> >(action.Value.ToString()); if (jsonParameters.ContainsKey(CTA.Rules.Config.Constants.PackageName)) { packageAction.Name = jsonParameters[CTA.Rules.Config.Constants.PackageName]; } else { LogHelper.LogDebug(string.Format("Parameter {0} is not available for action {1}" , Config.Constants.PackageName, action.Name)); continue; } //TODO: If version is not available/valid, we use latest version. Should we reconsider? if (jsonParameters.ContainsKey(CTA.Rules.Config.Constants.PackageVersion)) { packageAction.Version = jsonParameters[CTA.Rules.Config.Constants.PackageVersion]; } } nodeToken.PackageActions.Add(packageAction); break; } } } catch (Exception ex) { LogHelper.LogError(ex, string.Format("Error parsing action type {0}", action.Type)); } } }
public void AttributeListActionsTest() { var addComment = _actionLoader.GetAttributeListAction("AddComment", "comment"); Assert.IsNotNull(addComment); }