示例#1
0
        public HttpResponseMessage CreateWadoRsResponse
        (
            IWadoRequestHeader request,
            IEnumerable <IWadoRsResponse> wadoResponses,
            MimeMediaType mimeType
        )
        {
            HttpResponseMessage response = new HttpResponseMessage( );


            if (wadoResponses == null || wadoResponses.FirstOrDefault( ) == null)
            {
                response.StatusCode = System.Net.HttpStatusCode.NotAcceptable;

                return(response);
            }
            if (!IsValidResponse(wadoResponses, out response))
            {
                return(response);
            }


            if (mimeType == MimeMediaTypes.Json)
            {
                return(GetJsonResponse(wadoResponses));
            }
            else
            {
                return(GetMultipartResponse(wadoResponses, mimeType));
            }
        }
示例#2
0
        public virtual HttpResponseMessage RetrieveInstance(IWadoRequestHeader header, IObjectID request)
        {
            //IWadoRsMimeResponseCreator mimeResponseHandler = new WadoRsMimeResponseCreator ( ) ;
            IWadoResponseService responseService = new WadoResponseService( );
            HttpResponseMessage  response        = new HttpResponseMessage( );
            string mimeType      = null;
            var    wadoResponses = CreateRetrieveInstanceResponse(header, request, out mimeType);

            //System.Net.Http.Headers.MediaTypeWithQualityHeaderValue mediaType ;
            //if ( ((MimeMediaType)MimeMediaTypes.MultipartRelated).IsIn ( request.AcceptHeader, out mediaType ))

            MultipartContent multiContent = new MultipartContent("related", "DICOM DATA BOUNDARY");

            multiContent.Headers.ContentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("type", "\"" + mimeType + "\""));

            response.Content = multiContent;


            foreach (var wadoResponse in wadoResponses)
            {
                StreamContent sContent = new StreamContent(wadoResponse.Content);
                sContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(wadoResponse.MimeType);

                multiContent.Add(sContent);
            }

            if (wadoResponses.Count( ) == 0)
            {
                response.StatusCode = System.Net.HttpStatusCode.NotFound;
            }


            return(response);
        }
示例#3
0
        protected virtual IEnumerable <IWadoRsResponse> CreateRetrieveInstanceResponse
        (
            IWadoRequestHeader header,
            IObjectID objectID,
            out string mimeType
        )
        {
            List <IWadoRsResponse>          responses = new List <IWadoRsResponse> ( );
            MediaTypeWithQualityHeaderValue mediaType = null;


            mimeType = null;

            MimeMediaType jsMime = MimeMediaTypes.MultipartRelated;

            if (jsMime.IsIn(header.AcceptHeader, out mediaType))
            {
                mimeType = ProcessMultipartRequest(objectID, responses, mediaType);
            }
            //TODO: all requests for retrieve is multipart except for "metadata in json format"
            //e.g:
            //Instances:
            //Accept - A comma-separated list of representation schemes, in preference order, which will be accepted by the service in theresponse to this request. The types allowed for this request header are as follows:
            //multipart/related; type=application/dicom; [transfer-syntax={TransferSyntaxUID}]
            //Specifies that the response can be DICOM Instances encoded in PS3.10 format. If transfer-syntax is not specified the servercan freely choose which Transfer Syntax to use for each Instance.
            //multipart/related; type=application/octet-stream
            //Specifies that the response can be Little Endian uncompressed bulk data.
            //multipart/related; type={MediaType}
            //Specifies that the response can be pixel data encoded using a {MediaType} listed in Table 6.5-1 (including parameters).

            //Bulk Data:
            //multipart/related; type=application/octet-stream
            //multipart/related; type={MediaType}

            //metadata:
            //multipart/related; type=application/dicom+xml
            //application/json

            //else
            //if ( ((MimeMediaType)MimeMediaTypes.Json).IsIn (header.AcceptHeader, out mediaType))
            //{
            //    mimeType = ProcessJsonRequest ( objectID, responses ) ;
            //}
            //else
            //if ( ((MimeMediaType)MimeMediaTypes.Jpeg).IsIn (header.AcceptHeader, out mediaType))
            //{
            //    //.... and so on
            //}

            //return json metadata by default
            if (null == mimeType)
            {
                mimeType = ProcessJsonRequest(objectID, responses);
            }

            return(responses);
        }
示例#4
0
        public HttpResponseMessage CreateRetrieveInstancesResponse
        (
            IWadoRequestHeader request,
            IEnumerable <IWadoRsResponse> wadoResponses,
            MimeMediaType mimeType
        )
        {
            HttpResponseMessage response = null;

            if (!IsValidResponse(wadoResponses, out response))
            {
                return(response);
            }

            //if ( request.IsMultipart ( ) )
            {
                return(GetMultipartResponse(wadoResponses, mimeType));
            }
        }
示例#5
0
        public virtual HttpResponseMessage RetrieveMultipartInstance(IWadoRequestHeader header, IObjectId request)
        {
            HttpResponseMessage             response;
            MultipartContent                multiContent;
            MediaTypeWithQualityHeaderValue selectedMediaTypeHeader;


            if (!IsMultiPartRequest(header))
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.NotAcceptable));     //TODO: check error code in standard
            }

            response                = new HttpResponseMessage( );
            multiContent            = new MultipartContent("related", MultipartResponseHelper.DicomDataBoundary);
            selectedMediaTypeHeader = null;

            response.Content = multiContent;

            foreach (var mediaTypeHeader in header.AcceptHeader)
            {
                if (request is IWadoRsFramesRequest)
                {
                    var frames = ((IWadoRsFramesRequest)request).Frames;
                    foreach (int frame in frames)
                    {
                        request.Frame = frame;

                        foreach (var wadoResponse in ProcessMultipartRequest(request, mediaTypeHeader))
                        {
                            MultipartResponseHelper.AddMultipartContent(multiContent, wadoResponse);

                            selectedMediaTypeHeader = mediaTypeHeader;
                        }
                    }
                }
                else
                {
                    foreach (var wadoResponse in ProcessMultipartRequest(request, mediaTypeHeader))
                    {
                        MultipartResponseHelper.AddMultipartContent(multiContent, wadoResponse);

                        selectedMediaTypeHeader = mediaTypeHeader;
                    }
                }

                if (selectedMediaTypeHeader != null)
                {
                    break;
                }
            }



            if (selectedMediaTypeHeader != null)
            {
                multiContent.Headers.ContentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("type", "\"" + MultipartResponseHelper.GetSubMediaType(selectedMediaTypeHeader) + "\""));
            }
            else
            {
                response.StatusCode = System.Net.HttpStatusCode.NotFound; //check error code
            }


            return(response);
        }
示例#6
0
 protected virtual bool IsMultiPartRequest(IWadoRequestHeader header)
 {
     return(MultipartResponseHelper.IsMultiPartRequest(header));
 }
示例#7
0
        protected virtual HttpResponseMessage ProcessJsonRequest
        (
            IWadoRequestHeader header,
            IObjectId objectID
        )
        {
            List <IWadoRsResponse> responses        = new List <IWadoRsResponse> ( );
            HttpResponseMessage    response         = new HttpResponseMessage( );
            StringBuilder          fullJsonResponse = new StringBuilder("[");
            StringBuilder          jsonArray        = new StringBuilder( );
            string selectedTransfer = "";
            bool   exists           = false;
            var    mediaTypeHeader  = header.AcceptHeader.FirstOrDefault( );

            IEnumerable <NameValueHeaderValue> transferSyntaxHeader = null;
            List <string> transferSyntaxes = new List <string> ( );
            var           defaultTransfer  = "";


            if (null != mediaTypeHeader)
            {
                transferSyntaxHeader = mediaTypeHeader.Parameters.Where(n => n.Name == "transfer-syntax");
            }

            if (null == transferSyntaxHeader || 0 == transferSyntaxHeader.Count( ))
            {
                transferSyntaxes.Add(defaultTransfer);
            }
            else
            {
                transferSyntaxes.AddRange(transferSyntaxHeader.Select(n => n.Value));
            }

            foreach (var transfer in transferSyntaxes)
            {
                selectedTransfer = transfer == "*" ? defaultTransfer : transfer;

                foreach (IStorageLocation storage in GetLocations(objectID, new DicomMediaProperties(MimeMediaTypes.Json, selectedTransfer)))
                {
                    exists = true;

                    using (var memoryStream = new MemoryStream())
                    {
                        storage.Download(memoryStream);
                        jsonArray.Append(System.Text.Encoding.UTF8.GetString(memoryStream.ToArray( )));
                        jsonArray.Append(",");
                    }
                }

                if (exists)
                {
                    break;
                }
            }

            fullJsonResponse.Append(jsonArray.ToString().TrimEnd(','));
            fullJsonResponse.Append("]");

            if (exists)
            {
                var content = new StreamContent(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(fullJsonResponse.ToString())));

                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(MimeMediaTypes.Json);

                if (!string.IsNullOrWhiteSpace(selectedTransfer))
                {
                    content.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("transfer-syntax", "\"" + selectedTransfer + "\""));
                }

                response.Content = content;
            }
            else
            {
                response = new HttpResponseMessage(System.Net.HttpStatusCode.NotFound);
            }

            return(response);
        }
示例#8
0
 public static bool IsMultiPartRequest(IWadoRequestHeader header)
 {
     return(((MimeMediaType)MimeMediaTypes.MultipartRelated).IsIn(header.AcceptHeader));
 }