Exemplo n.º 1
0
        public WADOResponse Process(WADORequestTypeHandlerContext context)
        {
            Platform.CheckForNullReference(context, "httpContext");
            Platform.CheckForNullReference(context.ServerAE, "context.ServerAE");
            Platform.CheckForNullReference(context.HttpContext, "context.HttpContext");

            // Cache the query string for performance purpose. Every time Request.QueryString is called, .NET will rebuild the entire dictionary.
            NameValueCollection query = context.HttpContext.Request.QueryString;

            ServerPartition partition = ServerPartitionMonitor.Instance.GetPartition(context.ServerAE);

            if (partition == null)
            {
                throw new WADOException(HttpStatusCode.NotFound, String.Format(SR.FaultPartitionNotExists, context.ServerAE));
            }

            if (!partition.Enabled)
            {
                throw new WADOException(HttpStatusCode.Forbidden, String.Format(SR.FaultPartitionDisabled, context.ServerAE));
            }

            ImageStreamingContext streamingContext = new ImageStreamingContext(context.HttpContext);

            streamingContext.ServerAE          = context.ServerAE;
            streamingContext.ContentType       = query["ContentType"];
            streamingContext.AcceptTypes       = context.HttpContext.Request.AcceptTypes;
            streamingContext.StudyInstanceUid  = query["studyuid"];
            streamingContext.SeriesInstanceUid = query["seriesuid"];
            streamingContext.ObjectUid         = query["objectuid"];

            string             sessionId     = context.HttpContext.Request.RemoteEndPoint.Address.ToString();
            StudyStorageLoader storageLoader = new StudyStorageLoader(sessionId);

            storageLoader.CacheEnabled       = _enableCache;
            storageLoader.CacheRetentionTime = _cacheRetentionTime;
            streamingContext.StorageLocation = storageLoader.Find(streamingContext.StudyInstanceUid, partition);

            // convert the dicom image into the appropriate mime type
            WADOResponse            response  = new WADOResponse();
            IImageMimeTypeProcessor processor = GetMimeTypeProcessor(streamingContext);

            MimeTypeProcessorOutput output = processor.Process(streamingContext);

            response.Output      = output.Output;
            response.ContentType = output.ContentType;
            response.IsLast      = output.IsLast;

            return(response);
        }
Exemplo n.º 2
0
        protected static bool ClientAcceptable(ImageStreamingContext context, string contentType)
        {
            if (context.AcceptTypes == null)
            {
                return(false);
            }

            foreach (string rawmime in context.AcceptTypes)
            {
                string mime = rawmime;
                if (rawmime.Contains(";"))
                {
                    mime = rawmime.Substring(0, rawmime.IndexOf(";"));
                }

                if (mime == "*/*" || mime == contentType)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        protected virtual IImageMimeTypeProcessor GetMimeTypeProcessor(ImageStreamingContext context)
        {
            string responseContentType = context.ContentType;

            if (String.IsNullOrEmpty(responseContentType))
            {
                if (context.IsMultiFrame)
                {
                    responseContentType = "application/dicom";
                }
                else
                {
                    responseContentType = "image/jpeg";
                    if (!ClientAcceptable(context, responseContentType))
                    {
                        responseContentType = "application/dicom";
                    }
                }
            }

            if (_processorMap.ContainsKey(responseContentType))
            {
                Type processorType = _processorMap[responseContentType];

                var processor = (IImageMimeTypeProcessor)Activator.CreateInstance(processorType);

                if (!ClientAcceptable(context, processor.OutputMimeType))
                {
                    Platform.Log(LogLevel.Warn, "Client requested for {0} but did not indicate in the request headers that it could support this mime-type (check HTTP-Accept)", context.ContentType);
                }

                return(processor);
            }

            throw new WADOException(HttpStatusCode.BadRequest,
                                    String.Format("The specified contentType '{0}' is not supported", responseContentType));
        }
Exemplo n.º 4
0
 internal PixelDataLoader(ImageStreamingContext context)
 {
     _context = context;
 }