/// <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="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> public void Process(Workflow workflow, out List <string> errorMessages) { workflow.IsProcessing = true; this.Context.SaveChanges(); var rockContext = (RockContext)this.Context; workflow.LoadAttributes(rockContext); workflow.Process(rockContext, out errorMessages); if (workflow.IsPersisted) { this.Context.WrapTransaction(() => { this.Context.SaveChanges(); workflow.SaveAttributeValues(rockContext); foreach (var activity in workflow.Activities) { activity.SaveAttributeValues(rockContext); } }); workflow.IsProcessing = false; this.Context.SaveChanges(); } }
/// <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); } }
/// <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); }
private void PersistWorkflow(Rock.Model.Workflow workflow) { if (workflow.Id == 0) { var workflowService = new WorkflowService(_rockContext); workflowService.Add(workflow); } _rockContext.WrapTransaction(() => { _rockContext.SaveChanges(); workflow.SaveAttributeValues(_rockContext); foreach (var activity in workflow.Activities) { activity.SaveAttributeValues(_rockContext); } }); }
private void SaveForProcessingLater(Rock.Model.Workflow newWorkflow, RockContext rockContext) { newWorkflow.IsPersisted = true; var service = new WorkflowService(rockContext); if (newWorkflow.Id == 0) { service.Add(newWorkflow); } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); newWorkflow.SaveAttributeValues(rockContext); foreach (var activity in newWorkflow.Activities) { activity.SaveAttributeValues(rockContext); } }); }
/// <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); } }