private static async Task ActivityChanged(ProcessActivityChangedEventArgs args, WorkflowRuntime runtime) { if (!args.TransitionalProcessWasCompleted) { return; } //TODO change Document transition history and WorkflowInbox }
private static async Task ActivityChanged(ProcessActivityChangedEventArgs args, WorkflowRuntime runtime) { if (!args.TransitionalProcessWasCompleted) { return; } var historyModel = await MetadataToModelConverter.GetEntityModelByModelAsync("DocumentTransitionHistory"); var emptyHistory = (await historyModel.GetAsync(Filter.And.Equal(Null.Value, "EmployeeId").Equal(args.ProcessId, "DocumentId"))).Select(h => h.GetId()).ToList(); await historyModel.DeleteAsync(emptyHistory); await runtime.PreExecuteFromCurrentActivityAsync(args.ProcessId); var nextState = WorkflowInit.Runtime.GetLocalizedStateName(args.ProcessId, args.ProcessInstance.CurrentState); var documentModel = await MetadataToModelConverter.GetEntityModelByModelAsync("Document"); var document = (await documentModel.GetAsync(Filter.And.Equal(args.ProcessId, "Id"))).FirstOrDefault() as dynamic; if (document == null) { return; } document.StateName = nextState; document.State = args.ProcessInstance.CurrentState; await documentModel.UpdateSingleAsync(document as DynamicEntity); var newActors = await Runtime.GetAllActorsForDirectCommandTransitionsAsync(args.ProcessId); var newInboxes = new List <dynamic>(); foreach (var newActor in newActors) { var newInboxItem = new DynamicEntity() as dynamic; newInboxItem.Id = Guid.NewGuid(); newInboxItem.IdentityId = new Guid(newActor); newInboxItem.ProcessId = args.ProcessId; newInboxes.Add(newInboxItem); } using (var shared = new SharedTransaction()) { var inboxModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowInbox"); var existingInboxes = (await inboxModel.GetAsync(Filter.And.Equal(args.ProcessId, "ProcessId"))).Select(i => i.GetId()).ToList(); await inboxModel.DeleteAsync(existingInboxes); await inboxModel.InsertAsync(newInboxes); shared.Commit(); } }
private void ActivityChanged(ProcessActivityChangedEventArgs args, WorkflowRuntime runtime) { if (!args.TransitionalProcessWasCompleted) { return; } Log.Information($":::::::::: ActivityChanged: pid={args.ProcessId.ToString()}, scheme={args.SchemeCode}, activity={args.CurrentActivityName}, state={args.CurrentState}, last={args.PreviousState}"); WorkflowProductService.TransitionType transitionType = GetTransitionType(args); var serviceArgs = new WorkflowProductService.ProductActivityChangedArgs { ProcessId = args.ProcessId, CurrentActivityName = args.CurrentActivityName, PreviousActivityName = args.PreviousActivityName, CurrentState = args.CurrentState, PreviousState = args.PreviousState, ExecutingCommand = args.ProcessInstance.CurrentCommand, TransitionType = transitionType }; BackgroundJob.Enqueue <WorkflowProductService>(service => service.ProductActivityChanged(serviceArgs)); }
private void ActivityChanged(ProcessActivityChangedEventArgs args, WorkflowRuntime runtime) { if (!args.TransitionalProcessWasCompleted) { return; } Log.Information($":::::::::: ActivityChanged: pid={args.ProcessId.ToString()}, scheme={args.SchemeCode}, activity={args.CurrentActivityName}, state={args.CurrentState}, last={args.PreviousState}"); var serviceArgs = new WorkflowProductService.ProductProcessChangedArgs { ProcessId = args.ProcessId, CurrentActivityName = args.CurrentActivityName, PreviousActivityName = args.PreviousActivityName, CurrentState = args.CurrentState, PreviousState = args.PreviousState, ExecutingCommand = args.ProcessInstance.CurrentCommand }; // There is a bit of a timing window before the ProcessId is assigned to the Product. So delay this a little bit (15 seconds in the default minimum time. BackgroundJob.Enqueue <WorkflowProductService>(service => service.ProductProcessChanged(serviceArgs)); //TODO change Document transition history and WorkflowInbox }
private WorkflowProductService.TransitionType GetTransitionType(ProcessActivityChangedEventArgs args) { WorkflowProductService.TransitionType transitionType = WorkflowProductService.TransitionType.Other; // In DWKit 2.4.1, when executing a timeout transition back to the same state, // args.ExecutedTransition isn't the transition that is actually being executed // (seems to be the first transition of all defined). In this case, ignore the // transition type. if (args.ExecutedTransition != null) { if ((args.CurrentState == args.ExecutedTransition.To.State) && (args.PreviousState == args.ExecutedTransition.From.State)) { switch (args.ExecutedTransition.Classifier) { case TransitionClassifier.Direct: transitionType = WorkflowProductService.TransitionType.Continuation; break; case TransitionClassifier.Reverse: transitionType = (args.ExecutedTransition.Trigger.Type == TriggerType.Command) ? WorkflowProductService.TransitionType.Rejection : WorkflowProductService.TransitionType.Reverse; break; default: transitionType = WorkflowProductService.TransitionType.Other; break; } } else { Log.Warning($":::: Executing Transition Mismatch: PreviousState={args.PreviousState}=>CurrentState={args.CurrentState}; TransitionName={args.ExecutedTransition.Name}, From={args.ExecutedTransition.From.State} => To={args.ExecutedTransition.To.State}"); } } return(transitionType); }
private static async Task ActivityChanged(ProcessActivityChangedEventArgs args, WorkflowRuntime runtime) { if (!args.TransitionalProcessWasCompleted) { return; } var historyModel = await MetadataToModelConverter.GetEntityModelByModelAsync("DocumentTransitionHistory"); var emptyHistory = (await historyModel.GetAsync(Filter.And.Equal(Null.Value, "EmployeeId").Equal(args.ProcessId, "DocumentId") .Equal(Null.Value, "TransitionTime"))).Select(h => h.GetId()).ToList(); await historyModel.DeleteAsync(emptyHistory); await runtime.PreExecuteFromCurrentActivityAsync(args.ProcessId); var nextState = WorkflowInit.Runtime.GetLocalizedStateName(args.ProcessId, args.ProcessInstance.CurrentState); var documentModel = await MetadataToModelConverter.GetEntityModelByModelAsync("Document"); var document = (await documentModel.GetAsync(Filter.And.Equal(args.ProcessId, "Id"))).FirstOrDefault() as dynamic; if (document == null) { return; } document.StateName = nextState; document.State = args.ProcessInstance.CurrentState; await documentModel.UpdateSingleAsync(document as DynamicEntity); var newActors = await Runtime.GetAllActorsForDirectCommandTransitionsAsync(args.ProcessId); var newInboxes = new List <dynamic>(); foreach (var newActor in newActors) { var newInboxItem = new DynamicEntity() as dynamic; newInboxItem.Id = Guid.NewGuid(); newInboxItem.IdentityId = newActor; newInboxItem.ProcessId = args.ProcessId; newInboxes.Add(newInboxItem); } var userIdsForNotification = new List <string>(); userIdsForNotification.AddRange(newInboxes.Select(a => (string)(a as dynamic).IdentityId)); var inboxModel = await MetadataToModelConverter.GetEntityModelByModelAsync("WorkflowInbox"); using (var shared = new SharedTransaction()) { await shared.BeginTransactionAsync(); var existingInbox = (await inboxModel.GetAsync(Filter.And.Equal(args.ProcessId, "ProcessId"))); userIdsForNotification.AddRange(existingInbox.Select(a => (string)(a as dynamic).IdentityId)); var existingInboxIds = existingInbox.Select(i => i.GetId()).ToList(); await inboxModel.DeleteAsync(existingInboxIds); await inboxModel.InsertAsync(newInboxes); await shared.CommitAsync(); } userIdsForNotification = userIdsForNotification.Distinct().ToList(); Func <Task> task = async() => { await ClientNotifiers.NotifyClientsAboutInboxStatus(userIdsForNotification); }; task.FireAndForgetWithDefaultExceptionLogger(); }