Beispiel #1
0
        public async Task Handle(CasePlanInstanceCreatedEvent message, CancellationToken token)
        {
            var record = CasePlanInstanceAggregate.New(new List <DomainEvent> {
                message
            });
            await _casePlanInstanceCommandRepository.Add(record, token);

            await _casePlanInstanceCommandRepository.SaveChanges(token);
        }
        public async Task <bool> Handle(LaunchCaseInstanceCommand launchCaseInstanceCommand, CancellationToken token)
        {
            var caseInstance = await _casePlanInstanceCommandRepository.Get(launchCaseInstanceCommand.CasePlanInstanceId, token);

            if (caseInstance == null || string.IsNullOrWhiteSpace(caseInstance.AggregateId))
            {
                throw new UnknownCasePlanInstanceException(launchCaseInstanceCommand.CasePlanInstanceId);
            }

            await _casePlanInstanceProcessor.Execute(caseInstance, token);

            await _casePlanInstanceCommandRepository.Update(caseInstance, token);

            await _casePlanInstanceCommandRepository.SaveChanges(token);

            return(true);
        }
        public async Task <CasePlanInstanceResult> Handle(CreateCaseInstanceCommand request, CancellationToken cancellationToken)
        {
            var workflowDefinition = await _casePlanCommandRepository.Get(request.CasePlanId, cancellationToken);

            if (workflowDefinition == null)
            {
                throw new UnknownCasePlanException(request.CasePlanId);
            }

            var casePlanInstance = CasePlanInstanceAggregate.New(Guid.NewGuid().ToString(), workflowDefinition, request.NameIdentifier, request.Parameters);
            await _casePlanInstanceCommandRepository.Add(casePlanInstance, cancellationToken);

            await _casePlanInstanceCommandRepository.SaveChanges(cancellationToken);

            await _busControl.Publish(casePlanInstance.DomainEvents.First(s => s is CasePlanInstanceCreatedEvent) as CasePlanInstanceCreatedEvent, cancellationToken);

            return(CasePlanInstanceResult.ToDto(casePlanInstance));
        }
Beispiel #4
0
        public async Task <bool> Execute(string casePlanInstanceId, string casePlanElementInstanceId, Dictionary <string, string> parameters, CancellationToken token)
        {
            var casePlanInstance = await _casePlanInstanceCommandRepository.Get(casePlanInstanceId, token);

            if (casePlanInstance == null)
            {
                throw new UnknownCasePlanInstanceException(casePlanInstanceId);
            }

            if (!string.IsNullOrWhiteSpace(casePlanElementInstanceId))
            {
                var elt = casePlanInstance.GetChild(casePlanElementInstanceId);
                if (elt == null)
                {
                    throw new UnknownCasePlanElementInstanceException(casePlanInstanceId, casePlanElementInstanceId);
                }
            }

            var subscriber = await _subscriberRepository.Get(casePlanInstanceId, casePlanElementInstanceId, EvtName, token);

            if (subscriber == null)
            {
                throw new InvalidOperationException("subscriber doesn't exist");
            }

            subscriber.IsCaptured = true;
            subscriber.Parameters = parameters;
            await _subscriberRepository.Update(subscriber, token);

            await _casePlanInstanceProcessor.Execute(casePlanInstance, token);

            await _casePlanInstanceCommandRepository.Update(casePlanInstance, token);

            await _casePlanInstanceCommandRepository.SaveChanges(token);

            return(true);
        }