Example #1
0
        /// <summary>
        /// Get a friendly description of the settings for a Status Change trigger.
        /// </summary>
        /// <param name="trigger"></param>
        /// <returns></returns>
        public string GetTriggerSettingsDescription(StepWorkflowTrigger trigger)
        {
            if (trigger == null)
            {
                return(string.Empty);
            }

            var settings = new StepWorkflowTrigger.StatusChangeTriggerSettings(trigger.TypeQualifier);

            return(this.GetTriggerSettingsDescription(trigger.TriggerType, settings));
        }
        /// <summary>
        /// Evaluate if a specific trigger should be processed for the target entity.
        /// </summary>
        /// <param name="dataContext"></param>
        /// <param name="trigger"></param>
        /// <param name="entityGuid"></param>
        /// <param name="entityState"></param>
        /// <returns></returns>
        protected override bool ShouldProcessTrigger(RockContext dataContext, StepWorkflowTrigger trigger, Guid entityGuid, EntityState entityState)
        {
            if (trigger.TriggerType == StepWorkflowTrigger.WorkflowTriggerCondition.StatusChanged)
            {
                // Determine if this Step has transitioned between statuses that match the "To" and "From" qualifiers for this trigger.
                // If the condition does not specify a status, any status will match.
                // A new Step can only match this condition if it has a matching "To" State and a "From" State is not specified.
                if (entityState == EntityState.Added || entityState == EntityState.Modified)
                {
                    var settings = new StepWorkflowTrigger.StatusChangeTriggerSettings(trigger.TypeQualifier);

                    if ((settings.FromStatusId == null || settings.FromStatusId.Value == PreviousStepStatusId.GetValueOrDefault(-1)) &&
                        (settings.ToStatusId == null || settings.ToStatusId.Value == CurrentStepStatusId.GetValueOrDefault(-1)))
                    {
                        return(true);
                    }
                }
            }
            else if (trigger.TriggerType == StepWorkflowTrigger.WorkflowTriggerCondition.IsComplete)
            {
                // Determine if this Step has transitioned from an incomplete status to a complete status.
                // Note that adding a new Step with a complete status will satisfy this trigger.
                if (entityState == EntityState.Added || entityState == EntityState.Modified)
                {
                    var statusService = new StepStatusService(dataContext);

                    var fromStatus = statusService.Queryable().AsNoTracking().FirstOrDefault(x => x.Id == this.PreviousStepStatusId);
                    var toStatus   = statusService.Queryable().AsNoTracking().FirstOrDefault(x => x.Id == this.CurrentStepStatusId);

                    if ((fromStatus == null || !fromStatus.IsCompleteStatus) &&
                        (toStatus != null && toStatus.IsCompleteStatus))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #3
0
        /// <summary>
        /// Get a friendly description of the settings for a Status Change trigger.
        /// </summary>
        /// <param name="triggerType">Type of the trigger.</param>
        /// <param name="settings">The settings.</param>
        /// <returns></returns>
        public string GetTriggerSettingsDescription(StepWorkflowTrigger.WorkflowTriggerCondition triggerType, StepWorkflowTrigger.StatusChangeTriggerSettings settings)
        {
            if (triggerType == StepWorkflowTrigger.WorkflowTriggerCondition.StatusChanged)
            {
                var statusService = new StepStatusService(( RockContext )this.Context);

                StepStatus status;

                status = statusService.Queryable().AsNoTracking().FirstOrDefault(x => x.Id == settings.FromStatusId);

                var fromStatus = (status == null) ? "[Any]" : status.Name;

                status = statusService.Queryable().AsNoTracking().FirstOrDefault(x => x.Id == settings.ToStatusId);

                var toStatus = (status == null) ? "[Any]" : status.Name;

                string description = string.Format($"Status Change: {fromStatus} to {toStatus}");

                return(description);
            }
            else if (triggerType == StepWorkflowTrigger.WorkflowTriggerCondition.IsComplete)
            {
                return("Step Completed");
            }
            else
            {
                return(triggerType.ToString());
            }
        }