public async Task <Guid> ProcessFile(string bucket, string fileName, IDictionary <string, object> metadata = null) { Log.Information($"Processing started [{fileName}]"); var blobId = await AddBlob(bucket, fileName, metadata); var blobInfo = await BlobStorage.GetFileInfo(blobId, bucket); await Bus.Publish <BlobLoaded>(new { BlobInfo = new LoadedBlobInfo(blobId, fileName, blobInfo.Length, JohnId, blobInfo.UploadDateTime, blobInfo.MD5, bucket, blobInfo.Metadata), TimeStamp = DateTimeOffset.UtcNow }); if (!Harness.Published.Select <Generic.Sagas.Events.FileProcessed>(m => m.Context.Message.BlobId == blobId).Any()) { throw new TimeoutException(); } var fileProcessed = Harness.Published.Select <Generic.Sagas.Events.FileProcessed>(m => m.Context.Message.BlobId == blobId).First(); var fileId = fileProcessed.Context.Message.Id; if (!Harness.Published.Select <Generic.Domain.Events.Files.NodeStatusPersisted>(m => (m.Context.Message.Status == Generic.Domain.FileStatus.Processed || m.Context.Message.Status == Generic.Domain.FileStatus.Failed) && m.Context.Message.Id == fileId).Any()) { throw new TimeoutException(); } if (!Harness.Published.Select <Generic.Domain.Events.Files.StatusPersisted>(m => (m.Context.Message.Status == Generic.Domain.FileStatus.Processed || m.Context.Message.Status == Generic.Domain.FileStatus.Failed) && m.Context.Message.Id == fileId).Any()) { throw new TimeoutException(); } var events = await CqrsEventStore.Get(fileId, 0); Log.Information($"Aggregate-{fileId}: {string.Join(", ", events.Select(e => $"{e.GetType().Name} ({e.Version})"))}"); Log.Information($"Processing finished [{fileName}]"); return(fileId); }
protected async Task <Guid> ProcessRecordsFile(string bucket, string fileName, IDictionary <string, object> metadata = null) { Log.Information($"Processing started [{fileName}]"); var blobId = await AddBlob(bucket, fileName, metadata.ToDictionary(c => c.Key, c => c.Value, StringComparer.OrdinalIgnoreCase)); var blobInfo = await BlobStorage.GetFileInfo(blobId, bucket); await Bus.Publish <BlobLoaded>(new { BlobInfo = new LoadedBlobInfo(blobId, fileName, blobInfo.Length, Guid.Parse(bucket), blobInfo.UploadDateTime, blobInfo.MD5, bucket, blobInfo.Metadata), TimeStamp = DateTimeOffset.UtcNow }); Harness.Published.Select(); if (!Harness.Published.Select <RecordsFile.Sagas.Events.RecordsFileProcessed>(m => m.Context.Message.BlobId == blobId).Any()) { throw new TimeoutException(); } var fileProcessed = Harness.Published.Select <RecordsFile.Sagas.Events.RecordsFileProcessed>(m => m.Context.Message.BlobId == blobId).First(); var fileId = fileProcessed.Context.Message.Id; if (fileProcessed.Context.Message.ProcessedRecords != Fixture.GetProcessedRecords(fileId).Count()) { throw new Exception($"fileProcessed.Context.Message.ProcessedRecords ({fileProcessed.Context.Message.ProcessedRecords}) != Fixture.GetProcessedRecords(fileId).Count() ({Fixture.GetProcessedRecords(fileId).Count()})"); } foreach (var recordId in Fixture.GetProcessedRecords(fileId)) { if (!Harness.Published.Select <RecordsFile.Domain.Events.Records.NodeStatusPersisted>(m => m.Context.Message.Status == RecordsFile.Domain.RecordStatus.Processed && m.Context.Message.Id == recordId).Any()) { throw new TimeoutException(); } if (!Harness.Published.Select <RecordsFile.Domain.Events.Records.StatusPersisted>(m => m.Context.Message.Status == RecordsFile.Domain.RecordStatus.Processed && m.Context.Message.Id == recordId).Any()) { throw new TimeoutException(); } } if (fileProcessed.Context.Message.FailedRecords != Fixture.GetInvalidRecords(fileId).Count()) { throw new Exception("fileProcessed.Context.Message.FailedRecords != Fixture.GetInvalidRecords(fileId).Count()"); } foreach (var recordId in Fixture.GetInvalidRecords(fileId)) { if (!Harness.Published.Select <RecordsFile.Domain.Events.Records.RecordPersisted>(m => m.Context.Message.Id == recordId).Any()) { throw new TimeoutException(); } if (!Harness.Published.Select <RecordsFile.Domain.Events.Records.NodeRecordPersisted>(m => m.Context.Message.Id == recordId).Any()) { throw new TimeoutException(); } } if (!Harness.Published.Select <Generic.Domain.Events.Files.NodeStatusPersisted>(m => (m.Context.Message.Status == Generic.Domain.FileStatus.Processed || m.Context.Message.Status == Generic.Domain.FileStatus.Failed) && m.Context.Message.Id == fileId).Any()) { throw new TimeoutException(); } if (!Harness.Published.Select <Generic.Domain.Events.Files.StatusPersisted>(m => (m.Context.Message.Status == Generic.Domain.FileStatus.Processed || m.Context.Message.Status == Generic.Domain.FileStatus.Failed) && m.Context.Message.Id == fileId).Any()) { throw new TimeoutException(); } var events = await CqrsEventStore.Get(fileId, 0); Log.Information($"Aggregate-{fileId}: {string.Join(", ", events.Select(e => $"{e.GetType().Name} ({e.Version})"))}"); Log.Information($"Processing finished [{fileName}]"); return(fileId); }