Beispiel #1
0
        /// <summary>
        /// The method will read all files in a directory/sub-directories and send a DICOMweb Store request (STOW-RS)
        /// Each 5 DICOM files will be grouped as a multi-part content and sent in a single request.
        /// </summary>
        /// <param name="directory"></param>
        public void StoreDicomInDirectory(string directory)
        {
            var mimeType = "application/dicom";
            MultipartContent multiContent = GetMultipartContent(mimeType);
            int count = 0;

            //Enumerate all files in a directory/sub-directories
            foreach (var path in Directory.EnumerateFiles(directory, "*.*", SearchOption.AllDirectories))
            {
                count++;

                StreamContent sContent = new StreamContent(File.OpenRead(path));

                sContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(mimeType);

                multiContent.Add(sContent);

                if (count % 5 == 0)
                {
                    count = 0;

                    StoreToServer(multiContent);

                    multiContent = GetMultipartContent(mimeType);
                }
            }

            //Flush any remaining images (should be less than 5)
            if (multiContent.Count( ) > 0)
            {
                StoreToServer(multiContent);
            }
        }