示例#1
0
        public async Task <SearchResult <ProcessInstanceResult> > Handle(CreateProcessInstanceCommand request, CancellationToken cancellationToken)
        {
            var processFile = await _processFileCommandRepository.Get(request.ProcessFileId, cancellationToken);

            if (processFile == null || string.IsNullOrWhiteSpace(processFile.AggregateId))
            {
                _logger.LogError($"the process file '{request.ProcessFileId}' doesn't exist");
                throw new UnknownProcessFileException(string.Format(Global.UnknownProcessFile, request.ProcessFileId));
            }

            var processInstances = BPMNParser.BuildInstances(processFile.Payload, request.ProcessFileId);
            var result           = new List <ProcessInstanceResult>();

            foreach (var processInstance in processInstances)
            {
                var pi = ProcessInstanceAggregate.New(request.ProcessFileId,
                                                      processFile.Name,
                                                      processInstance.ElementDefs.ToList(),
                                                      processInstance.Interfaces.ToList(),
                                                      processInstance.Messages.ToList(),
                                                      processInstance.ItemDefs.ToList(),
                                                      processInstance.SequenceFlows.ToList());
                await _processInstanceCommandRepository.Add(pi, cancellationToken);

                result.Add(ProcessInstanceResult.ToDto(pi));
            }

            await _processInstanceCommandRepository.SaveChanges(cancellationToken);

            return(new SearchResult <ProcessInstanceResult>
            {
                Content = result
            });
        }
示例#2
0
        public async Task <bool> Handle(UpdateProcessFileCommand request, CancellationToken cancellationToken)
        {
            var processFile = await _processFileCommandRepository.Get(request.Id, cancellationToken);

            if (processFile == null || string.IsNullOrWhiteSpace(processFile.AggregateId))
            {
                _logger.LogError($"Cannot update process file because it doesn't exist : '{request.Id}'");
                throw new UnknownProcessFileException(request.Id);
            }

            processFile.Update(request.Name, request.Description);
            await _processFileCommandRepository.Update(processFile, cancellationToken);

            await _processFileCommandRepository.SaveChanges(cancellationToken);

            return(true);
        }
        public async Task <PublishProcessFileResult> Handle(PublishProcessFileCommand request, CancellationToken cancellationToken)
        {
            var processFile = await _processFileCommandRepository.Get(request.Id, cancellationToken);

            if (request == null || string.IsNullOrWhiteSpace(processFile.AggregateId))
            {
                throw new UnknownProcessFileException(request.Id);
            }

            var newProcessFile = processFile.Publish();
            await _processFileCommandRepository.Update(processFile, cancellationToken);

            await _processFileCommandRepository.Add(newProcessFile, cancellationToken);

            await _processFileCommandRepository.SaveChanges(cancellationToken);

            return(new PublishProcessFileResult
            {
                Id = newProcessFile.AggregateId
            });
        }