コード例 #1
0
        public async Task <int> DeleteAsync(string id, CancellationToken cancellationToken = default)
        {
            var definitionRecords =
                await _workflowDefinitionVersionRepository.GetListByDefinitionIdAndVersionAsync(id, VersionOptions.All,
                                                                                                true, cancellationToken);

            var instanceRecords = await _workflowInstanceRepository.GetListByDefinitionIdAsync(id, false, cancellationToken);

            var activityDefinitionRecords = await _activityDefinitionRepository
                                            .GetListByWorkFlowInstanceDefinitionIdAsync(id, cancellationToken : cancellationToken);

            var connectionRecords = await _workflowDefinitionVersionRepository
                                    .GetConnectionDefinitionListByWorkFlowInstanceDefinitionIdAsync(id, cancellationToken : cancellationToken);

            var activityInstanceRecords = await _activityInstanceRepository
                                          .GetListByWorkFlowInstanceDefinitionIdAsync(id, cancellationToken : cancellationToken);

            var blockingActivityRecords = await _workflowInstanceRepository
                                          .GetBlockingActivityListByWorkFlowInstanceDefinitionIdAsync(id, cancellationToken : cancellationToken);

            _workflowInstanceRepository.BatchDeleteWorkflowInstances(instanceRecords);
            _workflowDefinitionVersionRepository.BatchDeleteWorkflowDefinitionVersions(definitionRecords);
            _activityDefinitionRepository.BatchDeleteActivityDefinitions(activityDefinitionRecords);
            _workflowDefinitionVersionRepository.BatchDeleteConnectionDefinitions(connectionRecords);
            _activityInstanceRepository.BatchDeleteActivityInstances(activityInstanceRecords);
            _workflowInstanceRepository.BatchDeleteBlockingActivitys(blockingActivityRecords);
            await _unitOfWorkManager.Current.SaveChangesAsync(cancellationToken);

            return(definitionRecords.Count);
        }
コード例 #2
0
        public async Task <global::Elsa.Models.WorkflowInstance> SaveAsync(global::Elsa.Models.WorkflowInstance instance, CancellationToken cancellationToken = default)
        {
            var existingEntity = await _workflowInstanceRepository
                                 .GetByInstanceIdAsync(instance.Id, true, cancellationToken);

            if (existingEntity == null)
            {
                var workflowInstance = new WorkflowInstance(_guidGenerator.Create().ToString());
                _objectMapper.Map(instance, workflowInstance);
                workflowInstance.Activities = instance.Activities
                                              .Select(t =>
                                                      new ActivityInstance(_guidGenerator.Create().ToString())
                {
                    Type       = t.Value.Type,
                    ActivityId = t.Key,
                    State      = t.Value.State,
                    Output     = t.Value.Output,
                }
                                                      ).ToList();
                workflowInstance.BlockingActivities = instance.BlockingActivities.Select(t =>
                                                                                         new BlockingActivity(_guidGenerator.Create().ToString())
                {
                    ActivityId   = t.ActivityId,
                    ActivityType = t.ActivityType
                }).ToList();

                await _workflowInstanceRepository.InsertAsync(workflowInstance, cancellationToken : cancellationToken);

                await _unitOfWorkManager.Current.SaveChangesAsync(cancellationToken);

                return(Map(workflowInstance));
            }
            else
            {
                _activityInstanceRepository.BatchDeleteActivityInstances(existingEntity.Activities.ToList());
                _workflowInstanceRepository.BatchDeleteBlockingActivitys(existingEntity.BlockingActivities.ToList());
                existingEntity.Activities.Clear();
                existingEntity.BlockingActivities.Clear();
                var entity = _objectMapper.Map(instance, existingEntity);
                await _workflowInstanceRepository.UpdateAsync(entity, cancellationToken : cancellationToken);

                await _unitOfWorkManager.Current.SaveChangesAsync(cancellationToken);

                return(Map(entity));
            }
        }