示例#1
0
        public DicomInstanceEntryReaderForSinglePartRequest(ISeekableStreamConverter seekableStreamConverter, IOptions <StoreConfiguration> storeConfiguration)
        {
            EnsureArg.IsNotNull(seekableStreamConverter, nameof(seekableStreamConverter));
            EnsureArg.IsNotNull(storeConfiguration, nameof(storeConfiguration));
            EnsureArg.IsNotNull(storeConfiguration?.Value, nameof(storeConfiguration));


            _seekableStreamConverter = seekableStreamConverter;
            _storeConfiguration      = storeConfiguration.Value;
        }
        public LoggingSeekableStreamConverter(
            ISeekableStreamConverter seekableStreamConverter,
            ILogger <LoggingSeekableStreamConverter> logger)
        {
            EnsureArg.IsNotNull(seekableStreamConverter, nameof(seekableStreamConverter));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _seekableStreamConverter = seekableStreamConverter;
            _logger = logger;
        }
        public AspNetCoreMultipartReaderFactory(
            ISeekableStreamConverter seekableStreamConverter,
            IOptions <StoreConfiguration> storeConfiguration)
        {
            EnsureArg.IsNotNull(seekableStreamConverter, nameof(seekableStreamConverter));
            EnsureArg.IsNotNull(storeConfiguration?.Value, nameof(storeConfiguration));

            _seekableStreamConverter = seekableStreamConverter;
            _storeConfiguration      = storeConfiguration;
        }
        public DicomInstanceEntryReaderForSinglePartRequest(
            ILogger <DicomInstanceEntryReaderForSinglePartRequest> logger,
            ISeekableStreamConverter seekableStreamConverter)
        {
            EnsureArg.IsNotNull(logger, nameof(logger));
            EnsureArg.IsNotNull(seekableStreamConverter, nameof(seekableStreamConverter));

            _logger = logger;
            _seekableStreamConverter = seekableStreamConverter;
        }
        internal AspNetCoreMultipartReader(
            string contentType,
            Stream body,
            ISeekableStreamConverter seekableStreamConverter,
            IOptions <StoreConfiguration> storeConfiguration)
        {
            EnsureArg.IsNotNull(contentType, nameof(contentType));
            EnsureArg.IsNotNull(body, nameof(body));
            EnsureArg.IsNotNull(seekableStreamConverter, nameof(seekableStreamConverter));
            EnsureArg.IsNotNull(storeConfiguration?.Value, nameof(storeConfiguration));

            _seekableStreamConverter = seekableStreamConverter;
            _storeConfiguration      = storeConfiguration;

            if (!MediaTypeHeaderValue.TryParse(contentType, out MediaTypeHeaderValue media) ||
                !media.MediaType.Equals(KnownContentTypes.MultipartRelated, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new UnsupportedMediaTypeException(
                          string.Format(CultureInfo.InvariantCulture, DicomApiResource.UnsupportedContentType, contentType));
            }

            string boundary = HeaderUtilities.RemoveQuotes(media.Boundary).ToString();

            if (string.IsNullOrWhiteSpace(boundary))
            {
                throw new UnsupportedMediaTypeException(
                          string.Format(CultureInfo.InvariantCulture, DicomApiResource.InvalidMultipartContentType, contentType));
            }

            // Check to see if the root content type was specified or not.
            if (media.Parameters != null)
            {
                foreach (NameValueHeaderValue parameter in media.Parameters)
                {
                    if (TypeParameterName.Equals(parameter.Name.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        _rootContentType = HeaderUtilities.RemoveQuotes(parameter.Value).ToString();
                    }
                    else if (StartParameterName.Equals(parameter.Name.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        // TODO: According to RFC2387 3.2, the root section can be specified by using the
                        // start parameter. For now, we will assume that the first section is the "root" section
                        // and will add support later. Throw exception in case start is specified.
                        throw new NotSupportedException(DicomApiResource.StartParameterIsNotSupported);
                    }
                }
            }

            _multipartReader = new MultipartReader(boundary, body)
            {
                // set the max length of each section in bytes
                BodyLengthLimit = _storeConfiguration.Value.MaxAllowedDicomFileSize,
            };
        }
示例#6
0
        public async Task GivenMissingMultipartBodyPartException_WhenReading_NoMoreSectionShouldBeReturned()
        {
            string body = GenerateBody(
                DefaultBodyPartSeparator,
                "Content-Type: application/dicom",
                string.Empty,
                "content",
                DefaultBodyPartSeparator,
                "Content-Type: application/dicom+json",
                string.Empty,
                "content2",
                DefaultBodyPartFinalSeparator);

            ISeekableStreamConverter seekableStreamConverter = Substitute.For <ISeekableStreamConverter>();

            seekableStreamConverter.ConvertAsync(default, default).ThrowsForAnyArgs(new InvalidMultipartBodyPartException(new IOException()));
示例#7
0
 public AspNetCoreMultipartReaderTests()
 {
     _seekableStreamConverter = new SeekableStreamConverter(Substitute.For <IHttpContextAccessor>(), CreateStoreConfiguration());
 }