Exemple #1
0
        public async Task GivenAnExistingDicomInstance_WhenAdded_ThenDicomInstanceAlreadyExistsExceptionShouldBeThrown()
        {
            string studyInstanceUid  = TestUidGenerator.Generate();
            string seriesInstanceUid = TestUidGenerator.Generate();
            string sopInstanceUid    = TestUidGenerator.Generate();

            DicomDataset dataset = Samples.CreateRandomDicomFile(studyInstanceUid, seriesInstanceUid, sopInstanceUid).Dataset;

            long version = await _indexDataStore.CreateInstanceIndexAsync(dataset);

            await _indexDataStore.UpdateInstanceIndexStatusAsync(
                dataset.ToVersionedInstanceIdentifier(version),
                IndexStatus.Created);

            await Assert.ThrowsAsync <InstanceAlreadyExistsException>(() => _indexDataStore.CreateInstanceIndexAsync(dataset));
        }
        /// <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;
            }
        }
Exemple #3
0
        /// <inheritdoc />
        public async Task UpdateInstanceIndexStatusAsync(VersionedInstanceIdentifier versionedInstanceIdentifier, IndexStatus status, CancellationToken cancellationToken)
        {
            LogUpdateInstanceIndexStatusDelegate(_logger, versionedInstanceIdentifier, status, null);

            try
            {
                await _indexDataStore.UpdateInstanceIndexStatusAsync(versionedInstanceIdentifier, status, cancellationToken);

                LogOperationSucceededDelegate(_logger, null);
            }
            catch (Exception ex)
            {
                LogOperationFailedDelegate(_logger, ex);

                throw;
            }
        }
        private async Task StoreDatasetsAndInstances(DicomDataset dataset, bool flagToStoreInstance)
        {
            long version = await _indexDataStore.CreateInstanceIndexAsync(dataset);

            var versionedInstanceIdentifier = dataset.ToVersionedInstanceIdentifier(version);

            if (flagToStoreInstance)
            {
                var dicomFile = new DicomFile(dataset);

                Samples.AppendRandomPixelData(5, 5, 0, dicomFile);

                await using MemoryStream stream = _recyclableMemoryStreamManager.GetStream();

                dicomFile.Save(stream);
                stream.Position = 0;
                await _fileStore.StoreFileAsync(
                    versionedInstanceIdentifier,
                    stream);
            }

            await _indexDataStore.UpdateInstanceIndexStatusAsync(versionedInstanceIdentifier, IndexStatus.Created);
        }