/// <inheritdoc /> public async Task StoreDicomInstanceEntryAsync( IDicomInstanceEntry dicomInstanceEntry, CancellationToken cancellationToken) { EnsureArg.IsNotNull(dicomInstanceEntry, nameof(dicomInstanceEntry)); DicomDataset dicomDataset = await dicomInstanceEntry.GetDicomDatasetAsync(cancellationToken); long version = await _indexDataStore.CreateInstanceIndexAsync(dicomDataset, cancellationToken); var versionedInstanceIdentifier = dicomDataset.ToVersionedInstanceIdentifier(version); try { // We have successfully created the index, store the files. Task[] tasks = new[] { StoreFileAsync(versionedInstanceIdentifier, dicomInstanceEntry, cancellationToken), StoreInstanceMetadataAsync(dicomDataset, version, cancellationToken), }; await Task.WhenAll(tasks); // Successfully uploaded the files. Update the status to be available. await _indexDataStore.UpdateInstanceIndexStatusAsync(versionedInstanceIdentifier, IndexStatus.Created, cancellationToken); } catch (Exception) { // Exception occurred while storing the file. Try delete the index. await TryCleanupInstanceIndexAsync(versionedInstanceIdentifier); throw; } }
/// <inheritdoc /> public async Task StoreDicomInstanceEntryAsync( IDicomInstanceEntry dicomInstanceEntry, CancellationToken cancellationToken) { EnsureArg.IsNotNull(dicomInstanceEntry, nameof(dicomInstanceEntry)); var partitionKey = _contextAccessor.RequestContext.GetPartitionKey(); DicomDataset dicomDataset = await dicomInstanceEntry.GetDicomDatasetAsync(cancellationToken); IReadOnlyCollection <QueryTag> queryTags = await _queryTagService.GetQueryTagsAsync(cancellationToken : cancellationToken); long watermark = await _indexDataStore.BeginCreateInstanceIndexAsync(partitionKey, dicomDataset, queryTags, cancellationToken); var versionedInstanceIdentifier = dicomDataset.ToVersionedInstanceIdentifier(watermark); try { // We have successfully created the index, store the files. await Task.WhenAll( StoreFileAsync(versionedInstanceIdentifier, dicomInstanceEntry, cancellationToken), StoreInstanceMetadataAsync(dicomDataset, watermark, cancellationToken)); await _indexDataStore.EndCreateInstanceIndexAsync(partitionKey, dicomDataset, watermark, queryTags, cancellationToken : cancellationToken); } catch (Exception) { // Exception occurred while storing the file. Try delete the index. await TryCleanupInstanceIndexAsync(versionedInstanceIdentifier); throw; } }
private async Task DisposeResourceAsync(IDicomInstanceEntry resource) { try { await resource.DisposeAsync(); } catch (Exception ex) { _logger.LogWarning(ex, "Failed to dispose the resource."); } }
private async Task StoreFileAsync( VersionedInstanceIdentifier versionedInstanceIdentifier, IDicomInstanceEntry dicomInstanceEntry, CancellationToken cancellationToken) { Stream stream = await dicomInstanceEntry.GetStreamAsync(cancellationToken); await _fileStore.StoreFileAsync( versionedInstanceIdentifier, stream, cancellationToken); }
/// <inheritdoc /> public async Task StoreDicomInstanceEntryAsync(IDicomInstanceEntry dicomInstanceEntry, CancellationToken cancellationToken) { EnsureArg.IsNotNull(dicomInstanceEntry, nameof(dicomInstanceEntry)); string dicomInstanceIdentifier = (await dicomInstanceEntry.GetDicomDatasetAsync(cancellationToken)) .ToInstanceIdentifier() .ToString(); LogPersistingDicomInstanceEntryDelegate(_logger, dicomInstanceIdentifier, null); try { await _storeOrchestrator.StoreDicomInstanceEntryAsync(dicomInstanceEntry, cancellationToken); LogSuccessfullyPersistedDicomInstanceEntryDelegate(_logger, dicomInstanceIdentifier, null); } catch (Exception ex) { LogFailedToPersistDicomInstanceEntryDelegate(_logger, dicomInstanceIdentifier, ex); throw; } }
private async Task ProcessDicomInstanceEntryAsync(int index, CancellationToken cancellationToken) { IDicomInstanceEntry dicomInstanceEntry = _dicomInstanceEntries[index]; DicomDataset dicomDataset = null; try { // Open and validate the DICOM instance. dicomDataset = await dicomInstanceEntry.GetDicomDatasetAsync(cancellationToken); await _dicomDatasetValidator.ValidateAsync(dicomDataset, _requiredStudyInstanceUid, cancellationToken); } catch (Exception ex) { ushort failureCode = FailureReasonCodes.ProcessingFailure; switch (ex) { case DicomValidationException _: failureCode = FailureReasonCodes.ValidationFailure; break; case DatasetValidationException dicomDatasetValidationException: failureCode = dicomDatasetValidationException.FailureCode; break; case ValidationException _: failureCode = FailureReasonCodes.ValidationFailure; break; } LogValidationFailedDelegate(_logger, index, failureCode, ex); _storeResponseBuilder.AddFailure(dicomDataset, failureCode); return; } try { // Store the instance. await _storeOrchestrator.StoreDicomInstanceEntryAsync( dicomInstanceEntry, cancellationToken); LogSuccessfullyStoredDelegate(_logger, index, null); _storeResponseBuilder.AddSuccess(dicomDataset); } catch (Exception ex) { ushort failureCode = FailureReasonCodes.ProcessingFailure; switch (ex) { case PendingInstanceException _: failureCode = FailureReasonCodes.PendingSopInstance; break; case InstanceAlreadyExistsException _: failureCode = FailureReasonCodes.SopInstanceAlreadyExists; break; } LogFailedToStoreDelegate(_logger, index, failureCode, ex); _storeResponseBuilder.AddFailure(dicomDataset, failureCode); } }