private void ScanDirectory(string path)
        {
            if (_stop)
            {
                return;
            }

            if (Progress != null && ProgressOnDirectoryChange)
            {
                Progress(this, path, _count);
            }

            try
            {
                var directory = IOManager.CreateDirectoryReference(path);
                var files     = directory.EnumerateFileNames(_pattern);

                foreach (string file in files)
                {
                    if (_stop)
                    {
                        return;
                    }

                    ScanFile(file);

                    _count++;
                    if ((_count % ProgressFilesCount) == 0 && Progress != null)
                    {
                        Progress(this, path, _count);
                    }
                }

                if (!_recursive)
                {
                    return;
                }

                var dirs = directory.EnumerateDirectoryNames();
                foreach (string dir in dirs)
                {
                    if (_stop)
                    {
                        return;
                    }

                    ScanDirectory(dir);
                }
            }
            catch
            {
                // ignore exceptions?
            }
        }
Exemple #2
0
        /// <summary>
        /// Load a film box for a specific session from a specific folder.
        /// </summary>
        /// <param name="filmSession">Film session.</param>
        /// <param name="filmBoxFolder">Folder in which film box is stored.</param>
        /// <returns>Film box for the specified <paramref name="filmSession"/> located in the <paramref name="filmBoxFolder"/>.</returns>
        public static FilmBox Load(FilmSession filmSession, string filmBoxFolder)
        {
            var filmBoxFile = string.Format(@"{0}\FilmBox.dcm", filmBoxFolder);

            var file = DicomFile.Open(filmBoxFile);

            var filmBox = new FilmBox(filmSession, file.FileMetaInfo.MediaStorageSOPInstanceUID, file.Dataset);

            var imagesFolder = IOManager.CreateDirectoryReference(string.Format(@"{0}\Images", filmBoxFolder));

            foreach (var image in imagesFolder.EnumerateFileNames("*.dcm"))
            {
                var imageBox = ImageBox.Load(filmBox, image);

                filmBox.BasicImageBoxes.Add(imageBox);
            }
            return(filmBox);
        }
Exemple #3
0
        /// <summary>
        /// Save the contents of the film box.
        /// </summary>
        /// <param name="filmBoxFolder">Folder in which to save the film box contents.</param>
        public void Save(string filmBoxFolder)
        {
            var filmBoxDicomFile = string.Format(@"{0}\FilmBox.dcm", filmBoxFolder);
            var filmBoxTextFile  = string.Format(@"{0}\FilmBox.txt", filmBoxFolder);
            var file             = new DicomFile(this);

            file.Save(filmBoxDicomFile);

            using (var stream = IOManager.CreateFileReference(filmBoxTextFile).Create())
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(this.WriteToString());
                }

            var imageBoxFolderInfo = IOManager.CreateDirectoryReference(string.Format(@"{0}\Images", filmBoxFolder));

            imageBoxFolderInfo.Create();
            for (int i = 0; i < this.BasicImageBoxes.Count; i++)
            {
                var imageBox = this.BasicImageBoxes[i];
                imageBox.Save(string.Format(@"{0}\I{1:000000}", imageBoxFolderInfo.Name, i + 1));
            }
        }