Пример #1
0
        public ServerBuilder AddDefinitions(List <string> pathLst)
        {
            var builder = _services.BuildServiceProvider();
            var commitAggregateHelper = (ICommitAggregateHelper)builder.GetService(typeof(ICommitAggregateHelper));
            var caseFiles             = new ConcurrentBag <CaseFileAggregate>();
            var caseDefinitions       = new ConcurrentBag <CasePlanAggregate>();

            foreach (var path in pathLst)
            {
                var cmmnTxt        = File.ReadAllText(path);
                var name           = Path.GetFileName(path);
                var caseFile       = CaseFileAggregate.New(name, name, 0, cmmnTxt);
                var tDefinitions   = CMMNParser.ParseWSDL(cmmnTxt);
                var caseDefinition = CMMNParser.ExtractCasePlans(tDefinitions, caseFile);
                foreach (var cd in caseDefinition)
                {
                    caseDefinitions.Add(cd);
                }

                caseFiles.Add(caseFile);
                var newCaseFile = caseFile.Publish();
                caseFiles.Add(newCaseFile);
                commitAggregateHelper.Commit(caseFile, CaseFileAggregate.GetStreamName(caseFile.AggregateId), CancellationToken.None).Wait();
                commitAggregateHelper.Commit(newCaseFile, CaseFileAggregate.GetStreamName(newCaseFile.AggregateId), CancellationToken.None).Wait();
            }

            _services.TryUpdateSingleton <ICaseFileQueryRepository>(new InMemoryCaseFileQueryRepository(caseFiles));
            _services.TryUpdateSingleton <ICaseFileCommandRepository>(new InMemoryCaseFileCommandRepository(caseFiles));
            _services.TryUpdateSingleton <ICasePlanCommandRepository>(new InMemoryCasePlanCommandRepository(caseDefinitions));
            _services.TryUpdateSingleton <ICasePlanQueryRepository>(new InMemoryCasePlanQueryRepository(caseDefinitions));
            return(this);
        }
Пример #2
0
        private void InitializeDatabase(IApplicationBuilder app)
        {
            var pathLst = Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "Cmmns"), "*.cmmn").ToList();

            using (var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                using (var context = scope.ServiceProvider.GetService <CaseManagementDbContext>())
                {
                    context.Database.Migrate();
                    if (context.CasePlans.Any())
                    {
                        return;
                    }

                    var commitAggregateHelper = (ICommitAggregateHelper)scope.ServiceProvider.GetService(typeof(ICommitAggregateHelper));
                    foreach (var path in pathLst)
                    {
                        var cmmnTxt      = File.ReadAllText(path);
                        var name         = Path.GetFileName(path);
                        var caseFile     = CaseFileAggregate.New(name, name, 0, cmmnTxt);
                        var tDefinitions = CMMNParser.ParseWSDL(cmmnTxt);
                        var newCaseFile  = caseFile.Publish();
                        commitAggregateHelper.Commit(caseFile, CaseFileAggregate.GetStreamName(caseFile.AggregateId), CancellationToken.None).Wait();
                        commitAggregateHelper.Commit(newCaseFile, CaseFileAggregate.GetStreamName(newCaseFile.AggregateId), CancellationToken.None).Wait();
                    }

                    context.SaveChanges();
                }
            }
        }
        public async Task <bool> Handle(UpdateCaseFileCommand command, CancellationToken token)
        {
            var caseFile = await _eventStoreRepository.GetLastAggregate <CaseFileAggregate>(command.Id, CaseFileAggregate.GetStreamName(command.Id));

            if (caseFile == null || string.IsNullOrWhiteSpace(caseFile.AggregateId))
            {
                throw new UnknownCaseFileException(command.Id);
            }

            caseFile.Update(command.Name, command.Description);
            await _commitAggregateHelper.Commit(caseFile, CaseFileAggregate.GetStreamName(caseFile.AggregateId), token);

            return(true);
        }
Пример #4
0
        public async Task <bool> Handle(UpdateCaseFilePayloadCommand request, CancellationToken cancellationToken)
        {
            var caseFile = await _eventStoreRepository.GetLastAggregate <CaseFileAggregate>(request.Id, CaseFileAggregate.GetStreamName(request.Id));

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

            caseFile.UpdatePayload(request.Payload);
            await _commitAggregateHelper.Commit(caseFile, CaseFileAggregate.GetStreamName(caseFile.AggregateId), cancellationToken);

            return(true);
        }
Пример #5
0
        public async Task <string> Handle(PublishCaseFileCommand publishCaseFileCommand, CancellationToken token)
        {
            var caseFile = await _eventStoreRepository.GetLastAggregate <CaseFileAggregate>(publishCaseFileCommand.Id, CaseFileAggregate.GetStreamName(publishCaseFileCommand.Id));

            if (caseFile == null || string.IsNullOrWhiteSpace(caseFile.AggregateId))
            {
                throw new UnknownCaseFileException(publishCaseFileCommand.Id);
            }

            var newCaseFile = caseFile.Publish();
            await _commitAggregateHelper.Commit(caseFile, CaseFileAggregate.GetStreamName(caseFile.AggregateId), token);

            await _commitAggregateHelper.Commit(newCaseFile, CaseFileAggregate.GetStreamName(newCaseFile.AggregateId), token);

            return(newCaseFile.AggregateId);
        }
Пример #6
0
        public async Task <CreateCaseFileResult> Handle(AddCaseFileCommand addCaseFileCommand, CancellationToken token)
        {
            var payload = addCaseFileCommand.Payload;

            if (string.IsNullOrWhiteSpace(addCaseFileCommand.Payload))
            {
                payload = _options.DefaultCMMNSchema;
                payload = payload.Replace("{id}", $"CasePlanModel_{Guid.NewGuid()}");
            }

            var caseFile   = CaseFileAggregate.New(addCaseFileCommand.Name, addCaseFileCommand.Description, 0, addCaseFileCommand.Owner, payload);
            var streamName = CaseFileAggregate.GetStreamName(caseFile.AggregateId);
            await _commitAggregateHelper.Commit(caseFile, streamName, token);

            return(new CreateCaseFileResult
            {
                Id = caseFile.AggregateId
            });
        }