private WorkflowEventAction GenerateAction(XmlAction action, int currentUserId)
        {
            if (action == null)
            {
                return(null);
            }
            var emailNotification = action as XmlEmailNotificationAction;

            if (emailNotification != null)
            {
                return(ToEmailNotificationAction(emailNotification));
            }

            var propertyChangeAction = action as XmlPropertyChangeAction;

            if (propertyChangeAction != null)
            {
                return(ToPropertyChangeAction(propertyChangeAction, currentUserId));
            }

            var generateAction = action as XmlGenerateAction;

            if (generateAction != null)
            {
                return(ToGenerateAction(generateAction));
            }

            var webhookAction = action as XmlWebhookAction;

            if (webhookAction != null)
            {
                return(ToWebhookAction(webhookAction));
            }

            // Throw an exception if we receive an action that has not already been handled by the above cases
            throw new ApplicationException("Cannot generate WorkflowEventAction of unknown type.");
        }
Exemple #2
0
        private static IeBaseAction FromXmlModel(XmlAction xmlAction, WorkflowDataNameMaps dataMaps,
                                                 ISet <int> userIdsToCollect, ISet <int> groupIdsToCollect)
        {
            if (xmlAction == null)
            {
                return(null);
            }

            string       name   = null;
            IeBaseAction action = null;

            switch (xmlAction.ActionType)
            {
            case ActionTypes.EmailNotification:
                var xeAction = xmlAction as XmlEmailNotificationAction;
                action = !xeAction.PropertyTypeId.HasValue ||
                         dataMaps.PropertyTypeMap.TryGetValue(xeAction.PropertyTypeId.Value, out name)
                        ? new IeEmailNotificationAction
                {
                    Name         = xeAction.Name,
                    Emails       = xeAction.Emails,
                    PropertyId   = xeAction.PropertyTypeId,
                    PropertyName = name,
                    Message      = xeAction.Message
                }
                        : null;
                break;

            case ActionTypes.PropertyChange:
                var xpAction        = xmlAction as XmlPropertyChangeAction;
                var isPropertyFound = dataMaps.PropertyTypeMap.TryGetValue(xpAction.PropertyTypeId, out name) ||
                                      WorkflowHelper.TryGetNameOrDescriptionPropertyTypeName(xpAction.PropertyTypeId, out name);

                action = isPropertyFound
                        ? new IePropertyChangeAction
                {
                    Name          = xpAction.Name,
                    PropertyId    = xpAction.PropertyTypeId,
                    PropertyName  = name,
                    PropertyValue = xpAction.PropertyValue,
                    ValidValues   = FromXmlModel(xpAction.ValidValues, dataMaps),
                    UsersGroups   = FromXmlModel(xpAction.UsersGroups, userIdsToCollect, groupIdsToCollect)
                }
                        : null;
                break;

            case ActionTypes.Generate:
                var xgAction = xmlAction as XmlGenerateAction;
                action = xgAction.GenerateActionType != GenerateActionTypes.Children ||
                         (xgAction.ArtifactTypeId.HasValue &&
                          dataMaps.ArtifactTypeMap.TryGetValue(xgAction.ArtifactTypeId.Value, out name))
                        ? new IeGenerateAction
                {
                    Name = xgAction.Name,
                    GenerateActionType = xgAction.GenerateActionType,
                    ChildCount         = xgAction.ChildCount,
                    ArtifactTypeId     = xgAction.ArtifactTypeId,
                    ArtifactType       = name
                }
                        : null;
                break;

            case ActionTypes.Webhook:
                var xwAction = xmlAction as XmlWebhookAction;
                action = new IeWebhookAction
                {
                    Name = xmlAction.Name,
                    Id   = xwAction.WebhookId
                };
                break;
            }

            return(action);
        }