Пример #1
0
        public List <EmailNotificationAction> GetNotificationActions(IEnumerable <SqlWorkflowEvent> sqlArtifactTriggers)
        {
            var notifications = new List <EmailNotificationAction>();

            foreach (var workflowEvent in sqlArtifactTriggers)
            {
                var triggersXml = workflowEvent.Triggers;
                var xmlWorkflowEventTriggers = new XmlWorkflowEventTriggers();
                if (!string.IsNullOrWhiteSpace(triggersXml))
                {
                    try
                    {
                        Log.Debug($"Deserializing triggers: {triggersXml}");
                        var triggersFromXml = SerializationHelper.FromXml <XmlWorkflowEventTriggers>(triggersXml);
                        if (triggersFromXml != null)
                        {
                            xmlWorkflowEventTriggers = triggersFromXml;
                        }
                        else
                        {
                            Log.Debug($"Invalid triggers XML: {triggersXml}");
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"Deserialization failed for triggers: {triggersXml}", ex);
                    }
                }
                var triggersWithEmailActions = xmlWorkflowEventTriggers.Triggers.Where(trigger => trigger.Action.ActionType == ActionTypes.EmailNotification);
                foreach (var trigger in triggersWithEmailActions)
                {
                    var action = (XmlEmailNotificationAction)trigger.Action;
                    XmlStateCondition condition = null;
                    if (trigger.Condition?.ConditionType == ConditionTypes.State)
                    {
                        condition = (XmlStateCondition)trigger.Condition;
                    }
                    var emailNotification = new EmailNotificationAction
                    {
                        ConditionalStateId  = condition?.StateId,
                        EventPropertyTypeId = workflowEvent.EventPropertyTypeId ?? 0,
                        PropertyTypeId      = action.PropertyTypeId,
                        Message             = action.Message
                    };
                    emailNotification.Emails.AddRange(action.Emails);
                    notifications.Add(emailNotification);
                }
            }
            return(notifications);
        }
Пример #2
0
        private static XmlStateCondition ToXmlModel(IeStateCondition ieCondition, IDictionary <string, int> stateMap)
        {
            if (ieCondition == null)
            {
                return(null);
            }

            int stateId;

            if (!stateMap.TryGetValue(ieCondition.State, out stateId))
            {
                throw new ExceptionWithErrorCode(I18NHelper.FormatInvariant("Id of State '{0}' is not found.", ieCondition.State),
                                                 ErrorCodes.UnexpectedError);
            }

            var xmlCondition = new XmlStateCondition {
                StateId = stateId
            };

            return(xmlCondition);
        }