private void LaunchWorkflow(RockContext rockContext, ConnectionWorkflow connectionWorkflow, string name, Message message) { var workflowType = WorkflowTypeCache.Get(connectionWorkflow.WorkflowTypeId.Value); if (workflowType != null && (workflowType.IsActive ?? true)) { ConnectionRequest connectionRequest = null; if (message.ConnectionRequestGuid.HasValue) { connectionRequest = new ConnectionRequestService(rockContext).Get(message.ConnectionRequestGuid.Value); var workflow = Rock.Model.Workflow.Activate(workflowType, name); workflow.InitiatorPersonAliasId = message.InitiatorPersonAliasId; List <string> workflowErrors; new WorkflowService(rockContext).Process(workflow, connectionRequest, out workflowErrors); if (workflow.Id != 0) { ConnectionRequestWorkflow connectionRequestWorkflow = new ConnectionRequestWorkflow(); connectionRequestWorkflow.ConnectionRequestId = connectionRequest.Id; connectionRequestWorkflow.WorkflowId = workflow.Id; connectionRequestWorkflow.ConnectionWorkflowId = connectionWorkflow.Id; connectionRequestWorkflow.TriggerType = connectionWorkflow.TriggerType; connectionRequestWorkflow.TriggerQualifier = connectionWorkflow.QualifierValue; new ConnectionRequestWorkflowService(rockContext).Add(connectionRequestWorkflow); rockContext.SaveChanges(); } } } }
private void LaunchWorkflow(RockContext rockContext, ConnectionWorkflow connectionWorkflow, string name) { var workflowType = Web.Cache.WorkflowTypeCache.Read(connectionWorkflow.WorkflowTypeId.Value); if (workflowType != null && (workflowType.IsActive ?? true)) { ConnectionRequestActivity connectionRequestActivity = null; if (ConnectionRequestActivityGuid.HasValue) { connectionRequestActivity = new ConnectionRequestActivityService(rockContext).Get(ConnectionRequestActivityGuid.Value); var workflow = Rock.Model.Workflow.Activate(workflowType, name); List <string> workflowErrors; new WorkflowService(rockContext).Process(workflow, connectionRequestActivity, out workflowErrors); if (workflow.Id != 0) { ConnectionRequestWorkflow connectionRequestWorkflow = new ConnectionRequestWorkflow(); connectionRequestWorkflow.ConnectionRequestId = connectionRequestActivity.ConnectionRequestId; connectionRequestWorkflow.WorkflowId = workflow.Id; connectionRequestWorkflow.ConnectionWorkflowId = connectionWorkflow.Id; connectionRequestWorkflow.TriggerType = connectionWorkflow.TriggerType; connectionRequestWorkflow.TriggerQualifier = connectionWorkflow.QualifierValue; new ConnectionRequestWorkflowService(rockContext).Add(connectionRequestWorkflow); rockContext.SaveChanges(); } } } }
private void LaunchWorkflow(RockContext rockContext, ConnectionWorkflow connectionWorkflow, string name) { var workflowTypeService = new WorkflowTypeService(rockContext); var workflowType = workflowTypeService.Get(connectionWorkflow.WorkflowTypeId.Value); if (workflowType != null) { ConnectionRequest connectionRequest = null; if (ConnectionRequestGuid.HasValue) { connectionRequest = new ConnectionRequestService(rockContext).Get(ConnectionRequestGuid.Value); var workflow = Rock.Model.Workflow.Activate(workflowType, name); List <string> workflowErrors; new WorkflowService(rockContext).Process(workflow, connectionRequest, out workflowErrors); if (workflow.Id != 0) { ConnectionRequestWorkflow connectionRequestWorkflow = new ConnectionRequestWorkflow(); connectionRequestWorkflow.ConnectionRequestId = connectionRequest.Id; connectionRequestWorkflow.WorkflowId = workflow.Id; connectionRequestWorkflow.ConnectionWorkflowId = connectionWorkflow.Id; connectionRequestWorkflow.TriggerType = connectionWorkflow.TriggerType; connectionRequestWorkflow.TriggerQualifier = connectionWorkflow.QualifierValue; new ConnectionRequestWorkflowService(rockContext).Add(connectionRequestWorkflow); rockContext.SaveChanges(); } } } }
/// <summary> /// Launches the workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="connectionWorkflow">The connection workflow.</param> /// <param name="name">The name.</param> private void LaunchWorkflow( RockContext rockContext, ConnectionRequest connectionRequest, ConnectionWorkflow connectionWorkflow ) { if ( connectionRequest != null && connectionWorkflow != null && connectionWorkflow.WorkflowType != null ) { var workflow = Rock.Model.Workflow.Activate( connectionWorkflow.WorkflowType, connectionWorkflow.WorkflowType.WorkTerm, rockContext ); if ( workflow != null ) { var workflowService = new Rock.Model.WorkflowService( rockContext ); List<string> workflowErrors; if ( workflowService.Process( workflow, connectionRequest, out workflowErrors ) ) { if ( workflow.Id != 0 ) { ConnectionRequestWorkflow connectionRequestWorkflow = new ConnectionRequestWorkflow(); connectionRequestWorkflow.ConnectionRequestId = connectionRequest.Id; connectionRequestWorkflow.WorkflowId = workflow.Id; connectionRequestWorkflow.ConnectionWorkflowId = connectionWorkflow.Id; connectionRequestWorkflow.TriggerType = connectionWorkflow.TriggerType; connectionRequestWorkflow.TriggerQualifier = connectionWorkflow.QualifierValue; new ConnectionRequestWorkflowService( rockContext ).Add( connectionRequestWorkflow ); rockContext.SaveChanges(); if ( workflow.HasActiveEntryForm( CurrentPerson ) ) { var qryParam = new Dictionary<string, string>(); qryParam.Add( "WorkflowTypeId", connectionWorkflow.WorkflowType.Id.ToString() ); qryParam.Add( "WorkflowId", workflow.Id.ToString() ); NavigateToLinkedPage( "WorkflowEntryPage", qryParam ); } else { mdWorkflowLaunched.Show( string.Format( "A '{0}' workflow has been started.", connectionWorkflow.WorkflowType.Name ), ModalAlertType.Information ); } ShowDetail( PageParameter( "ConnectionRequestId" ).AsInteger(), PageParameter( "ConnectionOpportunityId" ).AsIntegerOrNull() ); } else { mdWorkflowLaunched.Show( string.Format( "A '{0}' workflow was processed (but not persisted).", connectionWorkflow.WorkflowType.Name ), ModalAlertType.Information ); } } else { mdWorkflowLaunched.Show( "Workflow Processing Error(s):<ul><li>" + workflowErrors.AsDelimited( "</li><li>" ) + "</li></ul>", ModalAlertType.Information ); } } } }
private void LaunchWorkflow( RockContext rockContext, ConnectionWorkflow connectionWorkflow, string name ) { var workflowTypeService = new WorkflowTypeService( rockContext ); var workflowType = workflowTypeService.Get( connectionWorkflow.WorkflowTypeId.Value ); if ( workflowType != null ) { ConnectionRequestActivity connectionRequestActivity = null; if ( ConnectionRequestActivityGuid.HasValue ) { connectionRequestActivity = new ConnectionRequestActivityService( rockContext ).Get( ConnectionRequestActivityGuid.Value ); var workflow = Rock.Model.Workflow.Activate( workflowType, name ); List<string> workflowErrors; new WorkflowService( rockContext ).Process( workflow, connectionRequestActivity, out workflowErrors ); if ( workflow.Id != 0 ) { ConnectionRequestWorkflow connectionRequestWorkflow = new ConnectionRequestWorkflow(); connectionRequestWorkflow.ConnectionRequestId = connectionRequestActivity.ConnectionRequestId; connectionRequestWorkflow.WorkflowId = workflow.Id; connectionRequestWorkflow.ConnectionWorkflowId = connectionWorkflow.Id; connectionRequestWorkflow.TriggerType = connectionWorkflow.TriggerType; connectionRequestWorkflow.TriggerQualifier = connectionWorkflow.QualifierValue; new ConnectionRequestWorkflowService( rockContext ).Add( connectionRequestWorkflow ); rockContext.SaveChanges(); } } } }
private void LaunchWorkflow( RockContext rockContext, ConnectionWorkflow connectionWorkflow, string name ) { ConnectionRequest connectionRequest = null; if ( ConnectionRequestGuid.HasValue ) { connectionRequest = new ConnectionRequestService( rockContext ).Get( ConnectionRequestGuid.Value ); } var workflowTypeService = new WorkflowTypeService( rockContext ); var workflowType = workflowTypeService.Get( connectionWorkflow.WorkflowTypeId.Value ); if ( workflowType != null ) { var workflow = Rock.Model.Workflow.Activate( workflowType, name ); if ( workflow.AttributeValues != null ) { if ( workflow.AttributeValues.ContainsKey( "ConnectionOpportunity" ) ) { var connectionOpportunity = new ConnectionOpportunityService( rockContext ).Get( ConnectionOpportunityId.Value ); if ( connectionOpportunity != null ) { workflow.AttributeValues["ConnectionOpportunity"].Value = connectionOpportunity.Guid.ToString(); } } if ( workflow.AttributeValues.ContainsKey( "ConnectionType" ) ) { var connectionType = new ConnectionTypeService( rockContext ).Get( ConnectionTypeId.Value ); if ( connectionType != null ) { workflow.AttributeValues["ConnectionType"].Value = connectionType.Guid.ToString(); } } if ( workflow.AttributeValues.ContainsKey( "ConnectionRequest" ) ) { if ( connectionRequest != null ) { workflow.AttributeValues["ConnectionRequest"].Value = connectionRequest.Guid.ToString(); } } if ( workflow.AttributeValues.ContainsKey( "Person" ) ) { var person = new PersonService( rockContext ).Get( PersonId.Value ); if ( person != null ) { workflow.AttributeValues["Person"].Value = person.PrimaryAlias.Guid.ToString(); } } } List<string> workflowErrors; new WorkflowService( rockContext ).Process( workflow, connectionRequest, out workflowErrors ); if ( workflow.Id != 0 ) { ConnectionRequestWorkflow connectionRequestWorkflow = new ConnectionRequestWorkflow(); connectionRequestWorkflow.ConnectionRequestId = connectionRequest.Id; connectionRequestWorkflow.WorkflowId = workflow.Id; connectionRequestWorkflow.ConnectionWorkflowId = connectionWorkflow.Id; connectionRequestWorkflow.TriggerType = connectionWorkflow.TriggerType; connectionRequestWorkflow.TriggerQualifier = connectionWorkflow.QualifierValue; new ConnectionRequestWorkflowService( rockContext ).Add( connectionRequestWorkflow ); rockContext.SaveChanges(); } } }