Exemplo n.º 1
0
 public static IAsyncResult BeginWrite(
     this DicomFileWriter @this,
     IByteTarget target,
     DicomFileMetaInformation fileMetaInfo,
     DicomDataset dataset,
     AsyncCallback callback,
     object state)
 {
     return(AsyncFactory.ToBegin(@this.WriteAsync(target, fileMetaInfo, dataset), callback, state));
 }
Exemplo n.º 2
0
		public void Save(Stream stream) {
			if (Format == DicomFileFormat.ACRNEMA1 || Format == DicomFileFormat.ACRNEMA2)
				throw new DicomFileException(this, "Unable to save ACR-NEMA file");

			if (Format == DicomFileFormat.DICOM3NoFileMetaInfo) {
				// create file meta information from dataset
				FileMetaInfo = new DicomFileMetaInformation(Dataset);
			}

			OnSave();

			using (var target = new StreamByteTarget(stream)) {
				DicomFileWriter writer = new DicomFileWriter(DicomWriteOptions.Default);
				writer.Write(target, FileMetaInfo, Dataset);
			}
		}
Exemplo n.º 3
0
		public void Save(string fileName) {
			if (Format == DicomFileFormat.ACRNEMA1 || Format == DicomFileFormat.ACRNEMA2)
				throw new DicomFileException(this, "Unable to save ACR-NEMA file");

			if (Format == DicomFileFormat.DICOM3NoFileMetaInfo) {
				// create file meta information from dataset
				FileMetaInfo = new DicomFileMetaInformation(Dataset);
			}

			File = new FileReference(fileName);
			File.Delete();

			OnSave();

			using (var target = new FileByteTarget(File)) {
				DicomFileWriter writer = new DicomFileWriter(DicomWriteOptions.Default);
				writer.Write(target, FileMetaInfo, Dataset);
			}
		}
Exemplo n.º 4
0
        public void Write_SimpleFile_CommentMaintained()
        {
            lock (this.locker)
            {
                const string fileName = @".\Test Data\dicomfilewriter_write.dcm";
                var          file     = IOManager.CreateFileReference(fileName);

                using (var target = new FileByteTarget(file))
                {
                    var writer = new DicomFileWriter(new DicomWriteOptions());
                    writer.Write(target, this.metaInfo, this.dataset);
                }

                var expected = Comment;
                var readFile = DicomFile.Open(fileName);
                var actual   = readFile.Dataset.Get <string>(DoseCommentTag);
                Assert.Equal(expected, actual);

                var syntax = readFile.FileMetaInfo.TransferSyntax;
                Assert.Equal(DicomTransferSyntax.JPEG2000Lossless, syntax);
            }
        }
Exemplo n.º 5
0
        public void BeginWrite_SimpleFile_CommentMaintained()
        {
            lock (this.locker)
            {
                const string fileName = @".\Test Data\dicomfilewriter_beginwrite.dcm";
                var file = IOManager.CreateFileReference(fileName);

                using (var target = new FileByteTarget(file))
                {
                    var writer = new DicomFileWriter(new DicomWriteOptions());
                    writer.EndWrite(writer.BeginWrite(target, this.metaInfo, this.dataset, null, null));
                }

                var expected = Comment;
                var readFile = DicomFile.Open(fileName);
                var actual = readFile.Dataset.Get<string>(DoseCommentTag);
                Assert.Equal(expected, actual);

                var syntax = readFile.FileMetaInfo.TransferSyntax;
                Assert.Equal(DicomTransferSyntax.JPEG2000Lossless, syntax);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Save DICOM file.
        /// </summary>
        /// <param name="fileName">File name.</param>
        public void Save(string fileName)
        {
            this.PreprocessFileMetaInformation();

            this.File = IOManager.CreateFileReference(fileName);
            this.File.Delete();

            this.OnSave();

            using (var target = new FileByteTarget(this.File))
            {
                var writer = new DicomFileWriter(DicomWriteOptions.Default);
                writer.Write(target, this.FileMetaInfo, this.Dataset);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Asynchronously save DICOM file to stream.
        /// </summary>
        /// <param name="stream">Stream on which to save DICOM file.</param>
        /// <returns>Awaitable task.</returns>
        public async Task SaveAsync(Stream stream)
        {
            this.PreprocessFileMetaInformation();
            this.OnSave();

            var target = new StreamByteTarget(stream);
            var writer = new DicomFileWriter(DicomWriteOptions.Default);
            await writer.WriteAsync(target, this.FileMetaInfo, this.Dataset).ConfigureAwait(false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Save to file asynchronously.
        /// </summary>
        /// <param name="fileName">Name of file.</param>
        /// <returns>Awaitable <see cref="Task"/>.</returns>
        public async Task SaveAsync(string fileName)
        {
            this.PreprocessFileMetaInformation();

            this.File = IOManager.CreateFileReference(fileName);
            this.File.Delete();

            this.OnSave();

            using (var target = new FileByteTarget(this.File))
            {
                var writer = new DicomFileWriter(DicomWriteOptions.Default);
                await writer.WriteAsync(target, this.FileMetaInfo, this.Dataset).ConfigureAwait(false);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Save DICOM file to stream.
        /// </summary>
        /// <param name="stream">Stream on which to save DICOM file.</param>
        public void Save(Stream stream)
        {
            this.PreprocessFileMetaInformation();
            this.OnSave();

            var target = new StreamByteTarget(stream);
            var writer = new DicomFileWriter(DicomWriteOptions.Default);
            writer.Write(target, this.FileMetaInfo, this.Dataset);
        }
Exemplo n.º 10
0
		public void BeginSave(string fileName, AsyncCallback callback, object state) {
			if (Format == DicomFileFormat.ACRNEMA1 || Format == DicomFileFormat.ACRNEMA2)
				throw new DicomFileException(this, "Unable to save ACR-NEMA file");

			if (Format == DicomFileFormat.DICOM3NoFileMetaInfo) {
				// create file meta information from dataset
				FileMetaInfo = new DicomFileMetaInformation(Dataset);
			}

			File = new FileReference(fileName);
			File.Delete();

			OnSave();

			FileByteTarget target = new FileByteTarget(File);

			EventAsyncResult result = new EventAsyncResult(callback, state);

			DicomFileWriter writer = new DicomFileWriter(DicomWriteOptions.Default);
			writer.BeginWrite(target, FileMetaInfo, Dataset, OnWriteComplete, new Tuple<DicomFileWriter, EventAsyncResult>(writer, result));
		}
Exemplo n.º 11
0
        /// <summary>
        /// Asynchronously save DICOM file to stream.
        /// </summary>
        /// <param name="stream">Stream on which to save DICOM file.</param>
        /// <returns>Awaitable task.</returns>
        public async Task SaveAsync(Stream stream)
        {
            if (this.Format == DicomFileFormat.ACRNEMA1 || this.Format == DicomFileFormat.ACRNEMA2)
            {
                throw new DicomFileException(this, "Unable to save ACR-NEMA file");
            }

            if (this.Format == DicomFileFormat.DICOM3NoFileMetaInfo)
            {
                // create file meta information from dataset
                this.FileMetaInfo = new DicomFileMetaInformation(this.Dataset);
            }

            this.OnSave();

            var target = new StreamByteTarget(stream);
            var writer = new DicomFileWriter(DicomWriteOptions.Default);
            await writer.WriteAsync(target, this.FileMetaInfo, this.Dataset).ConfigureAwait(false);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Save to file asynchronously.
        /// </summary>
        /// <param name="fileName">Name of file.</param>
        /// <returns>Awaitable <see cref="Task"/>.</returns>
        public async Task SaveAsync(string fileName)
        {
            if (this.Format == DicomFileFormat.ACRNEMA1 || this.Format == DicomFileFormat.ACRNEMA2)
            {
                throw new DicomFileException(this, "Unable to save ACR-NEMA file");
            }

            if (this.Format == DicomFileFormat.DICOM3NoFileMetaInfo)
            {
                // create file meta information from dataset
                this.FileMetaInfo = new DicomFileMetaInformation(this.Dataset);
            }

            this.File = IOManager.CreateFileReference(fileName);
            this.File.Delete();

            this.OnSave();

            using (var target = new FileByteTarget(this.File))
            {
                var writer = new DicomFileWriter(DicomWriteOptions.Default);
                await writer.WriteAsync(target, this.FileMetaInfo, this.Dataset).ConfigureAwait(false);
            }
        }
Exemplo n.º 13
0
 public static void EndWrite(this DicomFileWriter @this, IAsyncResult result)
 {
     AsyncFactory.ToEnd(result);
 }