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); }
public ServerBuilder AddDefinitions(List <string> pathLst, string caseOwner = null) { 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, caseOwner, cmmnTxt); var tDefinitions = CMMNParser.ParseWSDL(cmmnTxt); var caseDefinition = CMMNParser.ExtractCasePlans(tDefinitions, caseFile); foreach (var cd in caseDefinition) { caseDefinitions.Add(cd); } caseFiles.Add(caseFile); } _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); }
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; } 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(); context.CaseFiles.Add(caseFile); context.CaseFiles.Add(newCaseFile); foreach (var casePlan in CMMNParser.ExtractCasePlans(tDefinitions, caseFile)) { context.CasePlans.Add(casePlan); } } context.SaveChanges(); } } }
public async Task Handle(CaseFilePublishedEvent @event, CancellationToken cancellationToken) { var caseFile = await _caseFileQueryRepository.Get(@event.AggregateId, cancellationToken); var tDefinitions = CMMNParser.ParseWSDL(caseFile.Payload); foreach (var casePlan in CMMNParser.ExtractCasePlans(tDefinitions, caseFile)) { await _casePlanCommandRepository.Add(casePlan, cancellationToken); } await _casePlanCommandRepository.SaveChanges(cancellationToken); }
public async Task Consume(ConsumeContext <CaseFilePublishedEvent> context) { var caseFile = await _caseFileCommandRepository.Get(context.Message.AggregateId, CancellationToken.None); var tDefinitions = CMMNParser.ParseWSDL(caseFile.Payload); foreach (var casePlan in CMMNParser.ExtractCasePlans(tDefinitions, caseFile)) { await _casePlanCommandRepository.Add(casePlan, CancellationToken.None); } await _casePlanCommandRepository.SaveChanges(CancellationToken.None); }