Example #1
0
        /// <inheritdoc />
        public async Task <StoreResponse> Handle(
            StoreRequest message,
            CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(message, nameof(message));

            if (await AuthorizationService.CheckAccess(DataActions.Write, cancellationToken) != DataActions.Write)
            {
                throw new UnauthorizedDicomActionException(DataActions.Write);
            }

            StoreRequestValidator.ValidateRequest(message);

            // Find a reader that can parse the request body.
            IDicomInstanceEntryReader dicomInstanceEntryReader = _dicomInstanceEntryReaderManager.FindReader(message.RequestContentType);

            if (dicomInstanceEntryReader == null)
            {
                throw new UnsupportedMediaTypeException(
                          string.Format(CultureInfo.InvariantCulture, DicomCoreResource.UnsupportedContentType, message.RequestContentType));
            }

            // Read list of entries.
            IReadOnlyList <IDicomInstanceEntry> instanceEntries = await dicomInstanceEntryReader.ReadAsync(
                message.RequestContentType,
                message.RequestBody,
                cancellationToken);

            // Process list of entries.
            return(await _storeService.ProcessAsync(instanceEntries, message.StudyInstanceUid, cancellationToken));
        }
Example #2
0
        /// <inheritdoc />
        public async Task <IReadOnlyList <IDicomInstanceEntry> > ReadAsync(string contentType, Stream stream, CancellationToken cancellationToken)
        {
            LogReadingDelegate(_logger, _readerType, null);

            try
            {
                IReadOnlyList <IDicomInstanceEntry> dicomInstanceEntries = await _dicomInstanceEntryReader.ReadAsync(contentType, stream);

                LogSuccessfullyReadDelegate(_logger, dicomInstanceEntries?.Count ?? 0, null);

                return(dicomInstanceEntries);
            }
            catch (Exception ex)
            {
                LogFailedToReadDelegate(_logger, ex);

                throw;
            }
        }