Пример #1
0
        /// <summary>
        /// Load a <see cref="StudyXml"/> file for the <see cref="StudyLocation"/>
        /// </summary>
        /// <returns>The <see cref="StudyXml"/> instance</returns>
        public StudyXml LoadStudyXml()
        {
            var theXml = new StudyXml();

            string streamFile = GetStudyXmlPath();

            if (File.Exists(streamFile))
            {
                using (Stream fileStream = FileStreamOpener.OpenForRead(streamFile, FileMode.Open))
                {
                    var theDoc = new XmlDocument();

                    StudyXmlIo.Read(theDoc, fileStream);

                    theXml.SetMemento(theDoc);

                    fileStream.Close();
                }
            }
            return(theXml);
        }
Пример #2
0
        /// <summary>
        /// Load a <see cref="StudyXml"/> file for a given <see cref="StudyStorageLocation"/>
        /// </summary>
        /// <param name="location">The location a study is stored.</param>
        /// <returns>The <see cref="StudyXml"/> instance for <paramref name="location"/></returns>
        protected virtual StudyXml LoadStudyXml(StudyStorageLocation location)
        {
            StudyXml theXml = new StudyXml();

            String streamFile = Path.Combine(location.GetStudyPath(), location.StudyInstanceUid + ".xml");

            if (File.Exists(streamFile))
            {
                using (Stream fileStream = FileStreamOpener.OpenForRead(streamFile, FileMode.Open))
                {
                    XmlDocument theDoc = new XmlDocument();

                    StudyXmlIo.Read(theDoc, fileStream);

                    theXml.SetMemento(theDoc);

                    fileStream.Close();
                }
            }

            return(theXml);
        }
Пример #3
0
        /// <summary>
        /// Load a <see cref="StudyXml"/> file for a given <see cref="StudyStorageLocation"/>
        /// </summary>
        /// <returns>The <see cref="StudyXml"/> instance for the study</returns>
        private StudyXml LoadStudyXml()
        {
            StudyXml theXml = new StudyXml();

            String streamFile = Path.Combine(_rootPath, _studyInstanceUid + ".xml");

            if (File.Exists(streamFile))
            {
                using (Stream fileStream = FileStreamOpener.OpenForRead(streamFile, FileMode.Open))
                {
                    XmlDocument theDoc = new XmlDocument();

                    StudyXmlIo.Read(theDoc, fileStream);

                    theXml.SetMemento(theDoc);

                    fileStream.Close();
                }
            }

            return(theXml);
        }
Пример #4
0
        /// <summary>
        /// Load the first instance from the first series of the StudyXml file for a study.
        /// </summary>
        /// <param name="location">The storage location of the study.</param>
        /// <returns></returns>
        protected static DicomFile LoadInstance(StudyStorageLocation location)
        {
            string studyXml = Path.Combine(location.GetStudyPath(), location.StudyInstanceUid + ".xml");

            if (!File.Exists(studyXml))
            {
                return(null);
            }

            FileStream stream     = FileStreamOpener.OpenForRead(studyXml, FileMode.Open);
            var        theMemento = new StudyXmlMemento();

            StudyXmlIo.Read(theMemento, stream);
            stream.Close();
            stream.Dispose();
            var xml = new StudyXml();

            xml.SetMemento(theMemento);

            IEnumerator <SeriesXml> seriesEnumerator = xml.GetEnumerator();

            if (seriesEnumerator.MoveNext())
            {
                SeriesXml seriesXml = seriesEnumerator.Current;
                IEnumerator <InstanceXml> instanceEnumerator = seriesXml.GetEnumerator();
                if (instanceEnumerator.MoveNext())
                {
                    InstanceXml instance = instanceEnumerator.Current;
                    var         file     = new DicomFile("file.dcm", new DicomAttributeCollection(), instance.Collection)
                    {
                        TransferSyntax = instance.TransferSyntax
                    };
                    return(file);
                }
            }

            return(null);
        }
Пример #5
0
        protected static StudyXml LoadStudyXml(StudyStorageLocation location)
        {
            // This method should be combined with StudyStorageLocation.LoadStudyXml()
            StudyXml theXml = new StudyXml(location.StudyInstanceUid);

            String streamFile = Path.Combine(location.GetStudyPath(), location.StudyInstanceUid + ".xml");

            if (File.Exists(streamFile))
            {
                using (Stream fileStream = FileStreamOpener.OpenForRead(streamFile, FileMode.Open))
                {
                    var theMemento = new StudyXmlMemento();

                    StudyXmlIo.Read(theMemento, fileStream);

                    theXml.SetMemento(theMemento);

                    fileStream.Close();
                }
            }

            return(theXml);
        }
        public MimeTypeProcessorOutput Process(ImageStreamingContext context)
        {
            MimeTypeProcessorOutput output = new MimeTypeProcessorOutput();

            output.ContentType = OutputMimeType;
            using (FileStream stream = FileStreamOpener.OpenForRead(context.ImagePath, FileMode.Open))
            {
                output.ContentType = OutputMimeType;
                byte[] buffer    = new byte[stream.Length];
                int    offset    = 0;
                int    readBytes = 0;
                do
                {
                    readBytes = stream.Read(buffer, offset, buffer.Length - offset);
                    if (readBytes > 0)
                    {
                        offset += readBytes;
                    }
                } while (readBytes > 0);
                output.Output = buffer;
                stream.Close();
            }
            return(output);
        }
        /// <summary>
        /// Apply the rules.
        /// </summary>
        /// <remarks>
        /// When rules are applied, we are simply adding new <see cref="ServerDatabaseCommand"/> instances
        /// for the rules to the currently executing <see cref="ServerCommandProcessor"/>.  They will be
        /// executed after all other rules have been executed.
        /// </remarks>
        protected override void OnExecute(CommandProcessor theProcessor)
        {
            string   studyXmlFile = Path.Combine(_directory, String.Format("{0}.xml", _studyInstanceUid));
            StudyXml theXml       = new StudyXml(_studyInstanceUid);

            if (File.Exists(studyXmlFile))
            {
                using (Stream fileStream = FileStreamOpener.OpenForRead(studyXmlFile, FileMode.Open))
                {
                    XmlDocument theDoc = new XmlDocument();

                    StudyXmlIo.Read(theDoc, fileStream);

                    theXml.SetMemento(theDoc);

                    fileStream.Close();
                }
            }
            else
            {
                string errorMsg = String.Format("Unable to load study XML file of restored study: {0}", studyXmlFile);

                Platform.Log(LogLevel.Error, errorMsg);
                throw new ApplicationException(errorMsg);
            }

            DicomFile defaultFile   = null;
            bool      rulesExecuted = false;

            foreach (SeriesXml seriesXml in theXml)
            {
                foreach (InstanceXml instanceXml in seriesXml)
                {
                    // Skip non-image objects
                    if (instanceXml.SopClass.Equals(SopClass.KeyObjectSelectionDocumentStorage) ||
                        instanceXml.SopClass.Equals(SopClass.GrayscaleSoftcopyPresentationStateStorageSopClass) ||
                        instanceXml.SopClass.Equals(SopClass.BlendingSoftcopyPresentationStateStorageSopClass) ||
                        instanceXml.SopClass.Equals(SopClass.ColorSoftcopyPresentationStateStorageSopClass))
                    {
                        // Save the first one encountered, just in case the whole study is non-image objects.
                        if (defaultFile == null)
                        {
                            defaultFile = new DicomFile("test", new DicomAttributeCollection(), instanceXml.Collection);
                        }
                        continue;
                    }

                    DicomFile file = new DicomFile("test", new DicomAttributeCollection(), instanceXml.Collection);
                    _context.Message = file;
                    _engine.Execute(_context);
                    rulesExecuted = true;
                    break;
                }
                if (rulesExecuted)
                {
                    break;
                }
            }

            if (!rulesExecuted && defaultFile != null)
            {
                _context.Message = defaultFile;
                _engine.Execute(_context);
            }
        }