public new static IAsyncResult BeginOpen(string fileName, AsyncCallback callback, object state)
        {
            var df = new DicomStructuredReport();

            // reset datasets
            df.FileMetaInfo.Clear();
            df.Dataset.Clear();

            df.File = new FileReference(fileName);

            FileByteSource source = new FileByteSource(df.File);

            EventAsyncResult result = new EventAsyncResult(callback, state);

            DicomFileReader reader = new DicomFileReader();

            var datasetObserver = new DicomDatasetReaderObserver(df.Dataset);

            reader.BeginRead(source,
                             new DicomDatasetReaderObserver(df.FileMetaInfo),
                             datasetObserver,
                             OnReadComplete, new Tuple <DicomFileReader, DicomStructuredReport, EventAsyncResult>(reader, df, result));

            return(result);
        }
示例#2
0
        public new static DicomDirectory Open(string fileName)
        {
            var df = new DicomDirectory();

            // reset datasets
            df.FileMetaInfo.Clear();
            df.Dataset.Clear();

            try {
                df.File = new FileReference(fileName);

                using (var source = new FileByteSource(df.File)) {
                    DicomFileReader reader = new DicomFileReader();

                    var datasetObserver = new DicomDatasetReaderObserver(df.Dataset);
                    var dirObserver     = new DicomDirectoryReaderObserver(df.Dataset);

                    reader.Read(source,
                                new DicomDatasetReaderObserver(df.FileMetaInfo),
                                new DicomReaderMultiObserver(datasetObserver, dirObserver));

                    df.Format = reader.FileFormat;

                    df.Dataset.InternalTransferSyntax = reader.Syntax;

                    df._directoryRecordSequence = df.Dataset.Get <DicomSequence>(DicomTag.DirectoryRecordSequence);
                    df.RootDirectoryRecord      = dirObserver.BuildDirectoryRecords();

                    return(df);
                }
            } catch (Exception e) {
                throw new DicomFileException(df, e.Message, e);
            }
        }
        public new static DicomStructuredReport Open(string fileName)
        {
            var df = new DicomStructuredReport();

            // reset datasets
            df.FileMetaInfo.Clear();
            df.Dataset.Clear();

            try {
                df.File = new FileReference(fileName);

                using (var source = new FileByteSource(df.File)) {
                    DicomFileReader reader = new DicomFileReader();

                    var datasetObserver = new DicomDatasetReaderObserver(df.Dataset);

                    reader.Read(source,
                                new DicomDatasetReaderObserver(df.FileMetaInfo),
                                datasetObserver);

                    df.Format = reader.FileFormat;

                    df.Dataset.InternalTransferSyntax = reader.Syntax;

                    return(df);
                }
            } catch (Exception e) {
                throw new DicomFileException(df, e.Message, e);
            }
        }
示例#4
0
        /// <summary>
        /// Reads the specified filename and returns a DicomFile object.  Note that the values for large
        /// DICOM elements (e.g. PixelData) are read in "on demand" to conserve memory.  Large DICOM elements
        /// are determined by their size in bytes - see the default value for this in the FileByteSource._largeObjectSize
        /// </summary>
        /// <param name="fileName">The filename of the DICOM file</param>
        /// <param name="fallbackEncoding">Encoding to apply when attribute Specific Character Set is not available.</param>
        /// <returns>DicomFile instance</returns>
        public static DicomFile Open(string fileName, Encoding fallbackEncoding)
        {
            if (fallbackEncoding == null)
            {
                throw new ArgumentNullException("fallbackEncoding");
            }
            DicomFile df = new DicomFile();

            try {
                df.File = new FileReference(fileName);

                using (var source = new FileByteSource(df.File)) {
                    DicomFileReader reader = new DicomFileReader();
                    reader.Read(source,
                                new DicomDatasetReaderObserver(df.FileMetaInfo),
                                new DicomDatasetReaderObserver(df.Dataset, fallbackEncoding));

                    df.Format = reader.FileFormat;

                    df.Dataset.InternalTransferSyntax = reader.Syntax;

                    return(df);
                }
            } catch (Exception e) {
                throw new DicomFileException(df, e.Message, e);
            }
        }
示例#5
0
        public new static IAsyncResult BeginOpen(string fileName, Encoding fallbackEncoding, AsyncCallback callback, object state)
        {
            var df = new DicomDirectory();

            // reset datasets
            df.FileMetaInfo.Clear();
            df.Dataset.Clear();

            df.File = new FileReference(fileName);

            FileByteSource source = new FileByteSource(df.File);

            EventAsyncResult result = new EventAsyncResult(callback, state);

            DicomFileReader reader = new DicomFileReader();

            var datasetObserver = new DicomDatasetReaderObserver(df.Dataset, fallbackEncoding);
            var dirObserver     = new DicomDirectoryReaderObserver(df.Dataset);

            reader.BeginRead(source,
                             new DicomDatasetReaderObserver(df.FileMetaInfo),
                             new DicomReaderMultiObserver(datasetObserver, dirObserver),
                             OnReadComplete, new Tuple <DicomFileReader, DicomDirectory, DicomDirectoryReaderObserver, EventAsyncResult>(reader, df, dirObserver, result));

            return(result);
        }
示例#6
0
        /// <summary>
        /// Reads the specified file and returns a DicomFile object.  Note that the values for large
        /// DICOM elements (e.g. PixelData) are read in "on demand" to conserve memory.  Large DICOM elements
        /// are determined by their size in bytes - see the default value for this in the FileByteSource._largeObjectSize
        /// </summary>
        /// <param name="file">The file reference of the DICOM file</param>
        /// <param name="fallbackEncoding">Encoding to apply when attribute Specific Character Set is not available.</param>
        /// <param name="readOption">Option how to deal with large values, if they should be loaded directly into memory or lazy loaded on demand</param>
        /// <param name="largeObjectSize">Custom limit of what are large values and what are not. If 0 is passend, then the default of 64k is used.</param>
        /// <returns>DicomFile instance</returns>
        internal static DicomFile Open(IFileReference file, Encoding fallbackEncoding, FileReadOption readOption = FileReadOption.Default, int largeObjectSize = 0)
        {
            if (fallbackEncoding == null)
            {
                throw new ArgumentNullException(nameof(fallbackEncoding));
            }
            var df = new DicomFile();

            try
            {
                df.File = file;

                using var source      = new FileByteSource(file, readOption, largeObjectSize);
                using var unvalidated = new UnvalidatedScope(df.Dataset);
                var reader = new DicomFileReader();
                var result = reader.Read(
                    source,
                    new DicomDatasetReaderObserver(df.FileMetaInfo),
                    new DicomDatasetReaderObserver(df.Dataset, fallbackEncoding));

                HandleOpenError(df, result);

                df.IsPartial = result == DicomReaderResult.Stopped || result == DicomReaderResult.Suspended;
                df.Format    = reader.FileFormat;
                df.Dataset.InternalTransferSyntax = reader.Syntax;

                return(df);
            }
            catch (Exception e)
            {
                throw new DicomFileException(df, e.Message, e);
            }
        }
示例#7
0
        /// <summary>
        /// Asynchronously read DICOM Directory.
        /// </summary>
        /// <param name="fileName">File name.</param>
        /// <param name="fallbackEncoding">Encoding to apply if it cannot be identified from DICOM directory.</param>
        /// <param name="stop">Stop criterion in dataset.</param>
        /// <returns>Awaitable <see cref="DicomDirectory"/> instance.</returns>
        public static new async Task <DicomDirectory> OpenAsync(string fileName, Encoding fallbackEncoding, Func <ParseState, bool> stop = null)
        {
            if (fallbackEncoding == null)
            {
                throw new ArgumentNullException(nameof(fallbackEncoding));
            }
            var df = new DicomDirectory();

            try
            {
                df.File = IOManager.CreateFileReference(fileName);

                using (var source = new FileByteSource(df.File))
                {
                    var reader      = new DicomFileReader();
                    var dirObserver = new DicomDirectoryReaderObserver(df.Dataset);

                    var result =
                        await
                        reader.ReadAsync(
                            source,
                            new DicomDatasetReaderObserver(df.FileMetaInfo),
                            new DicomReaderMultiObserver(
                                new DicomDatasetReaderObserver(df.Dataset, fallbackEncoding),
                                dirObserver),
                            stop).ConfigureAwait(false);

                    return(FinalizeDicomDirectoryLoad(df, reader, dirObserver, result));
                }
            }
            catch (Exception e)
            {
                throw new DicomFileException(df, e.Message, e);
            }
        }
示例#8
0
        /// <summary>
        /// Asynchronously read DICOM Directory.
        /// </summary>
        /// <param name="fileName">File name.</param>
        /// <param name="fallbackEncoding">Encoding to apply if it cannot be identified from DICOM directory.</param>
        /// <param name="stop">Stop criterion in dataset.</param>
        /// <returns>Awaitable <see cref="DicomDirectory"/> instance.</returns>
        public static new async Task <DicomDirectory> OpenAsync(string fileName, Encoding fallbackEncoding, Func <ParseState, bool> stop = null)
        {
            if (fallbackEncoding == null)
            {
                throw new ArgumentNullException("fallbackEncoding");
            }
            var df = new DicomDirectory();

            // reset datasets
            df.FileMetaInfo.Clear();
            df.Dataset.Clear();

            try
            {
                df.File = IOManager.CreateFileReference(fileName);

                using (var source = new FileByteSource(df.File))
                {
                    var reader = new DicomFileReader();

                    var datasetObserver = new DicomDatasetReaderObserver(df.Dataset, fallbackEncoding);
                    var dirObserver     = new DicomDirectoryReaderObserver(df.Dataset);

                    var result =
                        await
                        reader.ReadAsync(
                            source,
                            new DicomDatasetReaderObserver(df.FileMetaInfo),
                            new DicomReaderMultiObserver(datasetObserver, dirObserver),
                            stop).ConfigureAwait(false);

                    if (result == DicomReaderResult.Processing)
                    {
                        throw new DicomFileException(df, "Invalid read return state: {state}", result);
                    }
                    if (result == DicomReaderResult.Error)
                    {
                        return(null);
                    }
                    df.IsPartial = result == DicomReaderResult.Stopped || result == DicomReaderResult.Suspended;

                    df.Format = reader.FileFormat;

                    df.Dataset.InternalTransferSyntax = reader.Syntax;

                    df._directoryRecordSequence = df.Dataset.Get <DicomSequence>(DicomTag.DirectoryRecordSequence);
                    df.RootDirectoryRecord      = dirObserver.BuildDirectoryRecords();

                    return(df);
                }
            }
            catch (Exception e)
            {
                throw new DicomFileException(df, e.Message, e);
            }
        }
示例#9
0
        public static DicomFile Open(string fileName)
        {
            DicomFile      df     = new DicomFile();
            FileReference  file   = new FileReference(fileName);
            FileByteSource source = new FileByteSource(file);

            DicomFileReader reader = new DicomFileReader();

            reader.Read(source,
                        new DicomDatasetReaderObserver(df.FileMetaInfo),
                        new DicomDatasetReaderObserver(df.Dataset));

            df.Dataset.InternalTransferSyntax = df.FileMetaInfo.TransferSyntax;
            df.File = file;

            return(df);
        }
示例#10
0
        /// <summary>
        /// Asynchronously reads the specified filename and returns a DicomFile object.  Note that the values for large
        /// DICOM elements (e.g. PixelData) are read in "on demand" to conserve memory.  Large DICOM elements
        /// are determined by their size in bytes - see the default value for this in the FileByteSource._largeObjectSize
        /// </summary>
        /// <param name="fileName">The filename of the DICOM file</param>
        /// <param name="fallbackEncoding">Encoding to apply when attribute Specific Character Set is not available.</param>
        /// <param name="stop">Stop criterion in dataset.</param>
        /// <returns>Awaitable <see cref="DicomFile"/> instance.</returns>
        public static async Task <DicomFile> OpenAsync(string fileName, Encoding fallbackEncoding, Func <ParseState, bool> stop = null, FileReadOption readOption = FileReadOption.Default)
        {
            if (fallbackEncoding == null)
            {
                throw new ArgumentNullException(nameof(fallbackEncoding));
            }
            var df = new DicomFile();

            try
            {
                df.File = IOManager.CreateFileReference(fileName);

                using (var unvalidated = new UnvalidatedScope(df.Dataset))
                    using (var source = new FileByteSource(df.File, readOption))
                    {
                        var reader = new DicomFileReader();
                        var result =
                            await
                            reader.ReadAsync(
                                source,
                                new DicomDatasetReaderObserver(df.FileMetaInfo),
                                new DicomDatasetReaderObserver(df.Dataset, fallbackEncoding),
                                stop).ConfigureAwait(false);

                        if (result == DicomReaderResult.Processing)
                        {
                            throw new DicomFileException(df, $"Invalid read return state: {result}");
                        }
                        if (result == DicomReaderResult.Error)
                        {
                            return(null);
                        }
                        df.IsPartial = result == DicomReaderResult.Stopped || result == DicomReaderResult.Suspended;

                        df.Format = reader.FileFormat;
                        df.Dataset.InternalTransferSyntax = reader.Syntax;

                        return(df);
                    }
            }
            catch (Exception e)
            {
                throw new DicomFileException(df, e.Message, e);
            }
        }
示例#11
0
        public static IAsyncResult BeginOpen(string fileName, AsyncCallback callback, object state)
        {
            DicomFile df = new DicomFile();

            df.File = new FileReference(fileName);
            FileByteSource source = new FileByteSource(df.File);

            EventAsyncResult async = new EventAsyncResult(callback, state);

            DicomFileReader reader = new DicomFileReader();

            reader.BeginRead(source,
                             new DicomDatasetReaderObserver(df.FileMetaInfo),
                             new DicomDatasetReaderObserver(df.Dataset),
                             OnReadComplete, new Tuple <DicomFileReader, DicomFile, EventAsyncResult>(reader, df, async));

            return(async);
        }
示例#12
0
        /// <summary>
        /// Reads the specified filename and returns a DicomFile object.  Note that the values for large
        /// DICOM elements (e.g. PixelData) are read in "on demand" to conserve memory.  Large DICOM elements
        /// are determined by their size in bytes - see the default value for this in the FileByteSource._largeObjectSize
        /// </summary>
        /// <param name="fileName">The filename of the DICOM file</param>
        /// <param name="fallbackEncoding">Encoding to apply when attribute Specific Character Set is not available.</param>
        /// <param name="stop">Stop criterion in dataset.</param>
        /// <returns>DicomFile instance</returns>
        public static DicomFile Open(string fileName, Encoding fallbackEncoding, Func <ParseState, bool> stop = null)
        {
            if (fallbackEncoding == null)
            {
                throw new ArgumentNullException("fallbackEncoding");
            }
            DicomFile df = new DicomFile();

            try
            {
                df.File = IOManager.CreateFileReference(fileName);

                using (var source = new FileByteSource(df.File))
                {
                    var reader = new DicomFileReader();
                    var result = reader.Read(
                        source,
                        new DicomDatasetReaderObserver(df.FileMetaInfo),
                        new DicomDatasetReaderObserver(df.Dataset, fallbackEncoding),
                        stop);

                    if (result == DicomReaderResult.Processing)
                    {
                        throw new DicomFileException(df, "Invalid read return state: {state}", result);
                    }
                    if (result == DicomReaderResult.Error)
                    {
                        return(null);
                    }
                    df.IsPartial = result == DicomReaderResult.Stopped || result == DicomReaderResult.Suspended;

                    df.Format = reader.FileFormat;

                    df.Dataset.InternalTransferSyntax = reader.Syntax;

                    return(df);
                }
            }
            catch (Exception e)
            {
                throw new DicomFileException(df, e.Message, e);
            }
        }
示例#13
0
        /// <summary>
        /// Reads the specified file and returns a DicomFile object.  Note that the values for large
        /// DICOM elements (e.g. PixelData) are read in "on demand" to conserve memory.  Large DICOM elements
        /// are determined by their size in bytes - see the default value for this in the FileByteSource._largeObjectSize
        /// </summary>
        /// <param name="file">The file reference of the DICOM file</param>
        /// <param name="fallbackEncoding">Encoding to apply when attribute Specific Character Set is not available.</param>
        /// <returns>DicomFile instance</returns>
        internal static DicomFile Open(IFileReference file, Encoding fallbackEncoding, FileReadOption readOption = FileReadOption.Default)
        {
            if (fallbackEncoding == null)
            {
                throw new ArgumentNullException(nameof(fallbackEncoding));
            }
            DicomFile df = new DicomFile();

            try
            {
                df.File = file;

                using (var source = new FileByteSource(file, readOption))
                    using (var unvalidated = new UnvalidatedScope(df.Dataset))
                    {
                        DicomFileReader reader = new DicomFileReader();
                        var             result = reader.Read(
                            source,
                            new DicomDatasetReaderObserver(df.FileMetaInfo),
                            new DicomDatasetReaderObserver(df.Dataset, fallbackEncoding));

                        if (result == DicomReaderResult.Processing)
                        {
                            throw new DicomFileException(df, $"Invalid read return state: {result}");
                        }
                        if (result == DicomReaderResult.Error)
                        {
                            return(null);
                        }
                        df.IsPartial = result == DicomReaderResult.Stopped || result == DicomReaderResult.Suspended;

                        df.Format = reader.FileFormat;

                        df.Dataset.InternalTransferSyntax = reader.Syntax;

                        return(df);
                    }
            }
            catch (Exception e)
            {
                throw new DicomFileException(df, e.Message, e);
            }
        }
示例#14
0
        /// <summary>
        /// Asynchronously reads the specified filename and returns a DicomFile object.  Note that the values for large
        /// DICOM elements (e.g. PixelData) are read in "on demand" to conserve memory.  Large DICOM elements
        /// are determined by their size in bytes - see the default value for this in the FileByteSource._largeObjectSize
        /// </summary>
        /// <param name="fileName">The filename of the DICOM file</param>
        /// <param name="fallbackEncoding">Encoding to apply when attribute Specific Character Set is not available.</param>
        /// <param name="stop">Stop criterion in dataset.</param>
        /// <param name="readOption">Option how to deal with large values, if they should be loaded directly into memory or lazy loaded on demand</param>
        /// <param name="largeObjectSize">Custom limit of what are large values and what are not. If 0 is passend, then the default of 64k is used.</param>
        /// <returns>Awaitable <see cref="DicomFile"/> instance.</returns>
        public static async Task <DicomFile> OpenAsync(string fileName, Encoding fallbackEncoding, Func <ParseState, bool> stop = null, FileReadOption readOption = FileReadOption.Default, int largeObjectSize = 0)
        {
            if (fallbackEncoding == null)
            {
                throw new ArgumentNullException(nameof(fallbackEncoding));
            }
            var df = new DicomFile();

            try
            {
                df.File = Setup.ServiceProvider.GetService <IFileReferenceFactory>().Create(fileName);

                using var unvalidated = new UnvalidatedScope(df.Dataset);
                using var source      = new FileByteSource(df.File, readOption, largeObjectSize);
                var reader = new DicomFileReader();
                var result =
                    await
                    reader.ReadAsync(
                        source,
                        new DicomDatasetReaderObserver(df.FileMetaInfo),
                        new DicomDatasetReaderObserver(df.Dataset, fallbackEncoding),
                        stop).ConfigureAwait(false);

                HandleOpenError(df, result);

                df.IsPartial = result == DicomReaderResult.Stopped || result == DicomReaderResult.Suspended;
                df.Format    = reader.FileFormat;
                df.Dataset.InternalTransferSyntax = reader.Syntax;

                return(df);
            }
            catch (Exception e)
            {
                throw new DicomFileException(df, e.Message, e);
            }
        }