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 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); }
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 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); }
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); }
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); }
public async Task Delete(CaseFileAggregate caseFile, CancellationToken token) { using (var lck = await _caseManagementDbContext.Lock()) { var record = await _caseManagementDbContext.CaseFiles.FirstOrDefaultAsync(_ => _.Id == caseFile.AggregateId, token); if (record == null) { return; } _caseManagementDbContext.CaseFiles.Remove(record); } }
public static CaseFileResult ToDto(CaseFileAggregate caseFile) { return(new CaseFileResult { CreateDateTime = caseFile.CreateDateTime, Description = caseFile.Description, Id = caseFile.AggregateId, Name = caseFile.Name, FileId = caseFile.FileId, Payload = caseFile.Payload, Status = Enum.GetName(typeof(CaseFileStatus), caseFile.Status), UpdateDateTime = caseFile.UpdateDateTime, Version = caseFile.Version }); }
public static CaseFileModel ToModel(this CaseFileAggregate caseFile) { return(new CaseFileModel { Id = caseFile.AggregateId, Version = caseFile.Version, FileId = caseFile.FileId, Name = caseFile.Name, Description = caseFile.Description, CreateDateTime = caseFile.CreateDateTime, UpdateDateTime = caseFile.UpdateDateTime, SerializedContent = caseFile.Payload, Status = (int)caseFile.Status }); }
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); }
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 }); }
public async Task Update(CaseFileAggregate caseFile, CancellationToken token) { using (var lck = await _caseManagementDbContext.Lock()) { var record = await _caseManagementDbContext.CaseFiles.FirstOrDefaultAsync(_ => _.Id == caseFile.AggregateId, token); if (record == null) { return; } record.Name = caseFile.Name; record.Description = caseFile.Description; record.UpdateDateTime = caseFile.UpdateDateTime; record.SerializedContent = caseFile.Payload; record.Status = (int)caseFile.Status; record.Version = caseFile.Version; } }
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, payload); await _caseFileCommandRepository.Add(caseFile, token); await _caseFileCommandRepository.SaveChanges(token); return(new CreateCaseFileResult { Id = caseFile.AggregateId }); }
public static ICollection <CasePlanAggregate> ExtractCasePlans(tDefinitions definitions, CaseFileAggregate caseFile) { var result = new List <CasePlanAggregate>(); foreach (var cmmnCase in definitions.@case) { result.Add(BuildCasePlan(cmmnCase, definitions, caseFile)); } return(result); }
private static CasePlanAggregate BuildCasePlan(tCase tCase, tDefinitions definitions, CaseFileAggregate caseFile) { var planModel = tCase.casePlanModel; var roles = new List <CasePlanRole>(); var files = new List <CasePlanFileItem>(); if (tCase.caseRoles != null && tCase.caseRoles.role != null) { foreach (var role in tCase.caseRoles.role) { roles.Add(new CasePlanRole { Id = role.id, Name = role.name }); } } if (tCase.caseFileModel != null && tCase.caseFileModel.caseFileItem != null) { foreach (var caseFileItem in tCase.caseFileModel.caseFileItem) { var caseFileItemDef = definitions.caseFileItemDefinition.First(c => c.id == caseFileItem.definitionRef.ToString()); files.Add(new CasePlanFileItem { DefinitionType = caseFileItemDef.definitionType, Id = caseFileItem.id, Name = caseFileItem.name }); } } return(CasePlanAggregate.New(planModel.id, planModel.name, planModel.name, caseFile.AggregateId, caseFile.Version, Serialize(planModel), roles, files)); }
public Task Update(CaseFileAggregate caseFile, CancellationToken token) { _caseFiles.Remove(_caseFiles.First(a => a.AggregateId == caseFile.AggregateId)); _caseFiles.Add((CaseFileAggregate)caseFile.Clone()); return Task.CompletedTask; }
public Task Add(CaseFileAggregate caseFile, CancellationToken token) { _caseFiles.Add((CaseFileAggregate)caseFile.Clone()); return Task.CompletedTask; }
public Task Update(CaseFileAggregate caseFile, CancellationToken token) { _caseManagementDbContext.CaseFiles.Update(caseFile); return(Task.CompletedTask); }
public Task Delete(CaseFileAggregate caseFile, CancellationToken token) { _caseFiles.Remove(_caseFiles.First(a => a.AggregateId == caseFile.AggregateId)); return(Task.CompletedTask); }
public Task Add(CaseFileAggregate caseFile, CancellationToken token) { _caseManagementDbContext.CaseFiles.Add(caseFile.ToModel()); return(Task.CompletedTask); }