Esempio n. 1
0
        /// <summary>
        /// Processes the specified <see cref="Rock.Model.Workflow" />
        /// </summary>
        /// <param name="workflow">The <see cref="Rock.Model.Workflow" /> instance to process.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">A <see cref="System.Collections.Generic.List{String}" /> that contains any error messages that were returned while processing the <see cref="Rock.Model.Workflow" />.</param>
        /// <returns></returns>
        public bool Process(Workflow workflow, object entity, out List <string> errorMessages)
        {
            var workflowType = WorkflowTypeCache.Get(workflow.WorkflowTypeId);

            if (workflowType != null && (workflowType.IsActive ?? true))
            {
                var rockContext = (RockContext)this.Context;

                if (workflow.IsPersisted)
                {
                    workflow.IsProcessing = true;
                    rockContext.SaveChanges();
                }

                bool result = workflow.ProcessActivities(rockContext, entity, out errorMessages);

                if (workflow.Status == "DeleteWorkflowNow")
                {
                    if (workflow.Id > 0)
                    {
                        rockContext.SaveChanges();
                        Delete(workflow);
                        rockContext.SaveChanges();
                    }
                    result = true;
                }
                else
                {
                    if (workflow.IsPersisted || workflowType.IsPersisted)
                    {
                        if (workflow.Id == 0)
                        {
                            Add(workflow);
                        }

                        rockContext.SaveChanges();

                        workflow.SaveAttributeValues(rockContext);
                        foreach (var activity in workflow.Activities)
                        {
                            activity.SaveAttributeValues(rockContext);
                        }

                        workflow.IsProcessing = false;
                        rockContext.SaveChanges();
                    }
                }

                return(result);
            }

            else
            {
                errorMessages = new List <string> {
                    "Workflow Type is invalid or not active!"
                };
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Processes the specified <see cref="Rock.Model.Workflow" />
        /// </summary>
        /// <param name="workflow">The <see cref="Rock.Model.Workflow" /> instance to process.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">A <see cref="System.Collections.Generic.List{String}" /> that contains any error messages that were returned while processing the <see cref="Rock.Model.Workflow" />.</param>
        /// <returns></returns>
        public bool Process(Workflow workflow, object entity, out List <string> errorMessages)
        {
            var rockContext = (RockContext)this.Context;

            if (workflow.IsPersisted)
            {
                workflow.IsProcessing = true;
                rockContext.SaveChanges();
            }

            bool result = workflow.ProcessActivities(rockContext, entity, out errorMessages);

            if (workflow.Status == "DeleteWorkflowNow")
            {
                if (workflow.Id > 0)
                {
                    rockContext.SaveChanges();
                    Delete(workflow);
                    rockContext.SaveChanges();
                }
                result = true;
            }
            else
            {
                if (workflow.IsPersisted || workflow.WorkflowType.IsPersisted)
                {
                    if (workflow.Id == 0)
                    {
                        Add(workflow);
                    }

                    rockContext.WrapTransaction(() =>
                    {
                        rockContext.SaveChanges();
                        workflow.SaveAttributeValues(rockContext);
                        foreach (var activity in workflow.Activities)
                        {
                            activity.SaveAttributeValues(rockContext);
                        }
                    });

                    workflow.IsProcessing = false;
                    rockContext.SaveChanges();
                }
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Processes the specified <see cref="Rock.Model.Workflow" />
        /// </summary>
        /// <param name="workflow">The <see cref="Rock.Model.Workflow" /> instance to process.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">A <see cref="System.Collections.Generic.List{String}" /> that contains any error messages that were returned while processing the <see cref="Rock.Model.Workflow" />.</param>
        /// <returns></returns>
        public bool Process(Workflow workflow, object entity, out List <string> errorMessages)
        {
            var workflowType = WorkflowTypeCache.Get(workflow.WorkflowTypeId);

            if (workflowType != null && (workflowType.IsActive ?? true))
            {
                var rockContext = (RockContext)this.Context;

                if (workflow.IsPersisted)
                {
                    workflow.IsProcessing = true;
                    rockContext.SaveChanges();
                }

                bool result = workflow.ProcessActivities(rockContext, entity, out errorMessages);

                if (workflow.Status == "DeleteWorkflowNow")
                {
                    if (workflow.Id > 0)
                    {
                        rockContext.SaveChanges();
                        Delete(workflow);
                        rockContext.SaveChanges();
                    }
                    result = true;
                }
                else
                {
                    if (workflow.IsPersisted || workflowType.IsPersisted)
                    {
                        if (workflow.Id == 0)
                        {
                            Add(workflow);
                        }

                        // Set EntityId and EntityTypeId if they are not already set and the included entity object is appropriate.
                        if ((workflow.EntityId == null) && (workflow.EntityTypeId == null) && (entity != null))
                        {
                            var typedEntity = entity as IEntity;
                            if (typedEntity != null)
                            {
                                workflow.EntityId     = typedEntity.Id;
                                workflow.EntityTypeId = typedEntity.TypeId;
                            }
                        }

                        rockContext.SaveChanges();

                        workflow.SaveAttributeValues(rockContext);
                        foreach (var activity in workflow.Activities)
                        {
                            activity.SaveAttributeValues(rockContext);
                        }

                        workflow.IsProcessing = false;
                        rockContext.SaveChanges();
                    }
                }

                return(result);
            }

            else
            {
                errorMessages = new List <string> {
                    "Workflow Type is invalid or not active!"
                };
                return(false);
            }
        }