/// <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; } }
public StoreOrchestratorTests() { _dicomDataset = new DicomDataset() { { DicomTag.StudyInstanceUID, DefaultStudyInstanceUid }, { DicomTag.SeriesInstanceUID, DefaultSeriesInstanceUid }, { DicomTag.SOPInstanceUID, DefaultSopInstanceUid }, }; _dicomInstanceEntry.GetDicomDatasetAsync(DefaultCancellationToken).Returns(_dicomDataset); _dicomInstanceEntry.GetStreamAsync(DefaultCancellationToken).Returns(_stream); _indexDataStore .BeginCreateInstanceIndexAsync(Arg.Any <int>(), _dicomDataset, Arg.Any <IEnumerable <QueryTag> >(), DefaultCancellationToken) .Returns(DefaultVersion); _queryTagService .GetQueryTagsAsync(Arg.Any <CancellationToken>()) .Returns(_queryTags); _contextAccessor.RequestContext.DataPartitionEntry = new PartitionEntry(1, "Microsoft.Default"); _storeOrchestrator = new StoreOrchestrator( _contextAccessor, _fileStore, _metadataStore, _indexDataStore, _deleteService, _queryTagService); }
public StoreOrchestratorTests() { _dicomDataset = new DicomDataset() { { DicomTag.StudyInstanceUID, DefaultStudyInstanceUid }, { DicomTag.SeriesInstanceUID, DefaultSeriesInstanceUid }, { DicomTag.SOPInstanceUID, DefaultSopInstanceUid }, }; _dicomInstanceEntry.GetDicomDatasetAsync(DefaultCancellationToken).Returns(_dicomDataset); _dicomInstanceEntry.GetStreamAsync(DefaultCancellationToken).Returns(_stream); _indexDataStore.CreateInstanceIndexAsync(_dicomDataset, DefaultCancellationToken).Returns(DefaultVersion); _storeOrchestrator = new StoreOrchestrator(_fileStore, _metadataStore, _indexDataStore, _deleteService); }
public StoreOrchestratorTests() { _dicomDataset = new DicomDataset() { { DicomTag.StudyInstanceUID, DefaultStudyInstanceUid }, { DicomTag.SeriesInstanceUID, DefaultSeriesInstanceUid }, { DicomTag.SOPInstanceUID, DefaultSopInstanceUid }, }; _dicomInstanceEntry.GetDicomDatasetAsync(DefaultCancellationToken).Returns(_dicomDataset); _dicomInstanceEntry.GetStreamAsync(DefaultCancellationToken).Returns(_stream); _indexDataStoreFactory.GetInstance().Returns(_indexDataStore); _indexDataStore.CreateInstanceIndexAsync(_dicomDataset, DefaultCancellationToken).Returns(DefaultVersion); _queryTagService.GetQueryTagsAsync(Arg.Any <CancellationToken>()) .Returns(Array.Empty <QueryTag>()); _storeOrchestrator = new StoreOrchestrator(_fileStore, _metadataStore, _indexDataStoreFactory, _deleteService, _queryTagService); }
/// <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); } }