Exemplo n.º 1
0
        public void TestWriteProgressStream()
        {
            const int writeSize    = 3276;
            const int bytesToWrite = writeSize * 10;
            const int bufferSize   = 4096;
            long      bytesWritten = 0;

            using (var memoryStream = new LargeMemoryStream())
            {
                using (var progressStream = new WriteProgressStream(memoryStream, bytesToWrite))
                {
                    var eventFired = false;
                    progressStream.ProgressChanged += (sender, args) => eventFired = true;

                    var buffer = new byte[bufferSize];
                    while (bytesWritten < bytesToWrite)
                    {
                        eventFired = false;
                        progressStream.Write(buffer, 0, writeSize);
                        bytesWritten += writeSize;
                        var progress = 100 * bytesWritten / (double)bytesToWrite;
                        Assert.AreEqual(progress, progressStream.ProgressPercent, 0.01);
                        Assert.IsTrue(eventFired);
                    }

                    Assert.AreEqual(100, progressStream.ProgressPercent, 0.01);
                }
            }
        }
Exemplo n.º 2
0
        public void TestReadProgressStream()
        {
            const int streamSize = 26543;
            const int bufferSize = 4096;
            const int readSize   = 3000;
            long      bytesRead  = 0;

            using (var memoryStream = new LargeMemoryStream(new byte[streamSize]))
            {
                using (var progressStream = new ReadProgressStream(memoryStream))
                {
                    var eventFired = false;
                    progressStream.ProgressChanged += (sender, args) => eventFired = true;

                    var buffer = new byte[bufferSize];
                    while (bytesRead < memoryStream.Length)
                    {
                        eventFired = false;
                        bytesRead += progressStream.Read(buffer, 0, readSize);
                        var progress = 100 * bytesRead / (double)streamSize;
                        Assert.AreEqual(progress, progressStream.ProgressPercent, 0.01);
                        Assert.IsTrue(eventFired);
                    }

                    Assert.AreEqual(100, progressStream.ProgressPercent, 0.01);
                }
            }
        }
Exemplo n.º 3
0
		public void TestWriteProgressStream()
		{
			const int writeSize = 3276;
			const int bytesToWrite = writeSize * 10;
			const int bufferSize = 4096;
			long bytesWritten = 0;

			using (var memoryStream = new LargeMemoryStream())
			{
				using (var progressStream = new WriteProgressStream(memoryStream, bytesToWrite))
				{
					var eventFired = false;
					progressStream.ProgressChanged += (sender, args) => eventFired = true;

					var buffer = new byte[bufferSize];
					while (bytesWritten < bytesToWrite)
					{
						eventFired = false;
						progressStream.Write(buffer, 0, writeSize);
						bytesWritten += writeSize;
						var progress = 100 * bytesWritten / (double)bytesToWrite;
						Assert.AreEqual(progress, progressStream.ProgressPercent, 0.01);
						Assert.IsTrue(eventFired);
					}

					Assert.AreEqual(100, progressStream.ProgressPercent, 0.01);
				}
			}
		}
Exemplo n.º 4
0
		public void TestReadProgressStream()
		{
			const int streamSize = 26543;
			const int bufferSize = 4096;
			const int readSize = 3000;
			long bytesRead = 0;

			using (var memoryStream = new LargeMemoryStream(new byte[streamSize]))
			{
				using (var progressStream = new ReadProgressStream(memoryStream))
				{
					var eventFired = false;
					progressStream.ProgressChanged += (sender, args) => eventFired = true;

					var buffer = new byte[bufferSize];
					while (bytesRead < memoryStream.Length)
					{
						eventFired = false;
						bytesRead += progressStream.Read(buffer, 0, readSize);
						var progress = 100*bytesRead / (double)streamSize;
						Assert.AreEqual(progress, progressStream.ProgressPercent, 0.01);
						Assert.IsTrue(eventFired);
					}

					Assert.AreEqual(100, progressStream.ProgressPercent, 0.01);
				}
			}
		}
Exemplo n.º 5
0
        public void TestStreamAndArrayHashMatchOne()
        {
            LargeMemoryStream.Position = 0;
            ActualString   = HashInstance.ComputeStream(LargeMemoryStream).ToString();
            ExpectedString = HashInstance.ComputeBytes(LargeMemoryStream.ToArray()).ToString();

            AssertAreEqual(ExpectedString, ActualString);
        }
Exemplo n.º 6
0
        public void TestStreamAndArrayHashMatchTwo()
        {
            LargeMemoryStream.Position = 0;
            ActualString = HashInstance.ComputeStream(LargeMemoryStream, LargeMemoryStream.Length / 2).ToString();
            HashInstance.Initialize();
            HashInstance.TransformBytes(LargeMemoryStream.ToArray(), 0, (int)(LargeMemoryStream.Length / 2));
            ExpectedString = HashInstance.TransformFinal().ToString();

            AssertAreEqual(ExpectedString, ActualString);
        }
Exemplo n.º 7
0
        public ImportSopResponse ImportSop(ImportSopRequest request)
        {
            try
            {
                var theFile = new DicomFile(string.Format("{0}{1}", request.SopInstanceUid, ServerPlatform.DicomFileExtension));

                using (var stream = new LargeMemoryStream(request.SopInstance))
                {
                    theFile.Load(stream);
                }

                var partition = ServerPartitionMonitor.Instance.GetPartition(request.CalledAETitle);

                string aeTitle = theFile.SourceApplicationEntityTitle;

                if (_importerContext == null)
                {
                    _importerContext = new SopInstanceImporterContext(
                        String.Format("{0}_{1}", aeTitle, DateTime.Now.ToString("yyyyMMddhhmmss")),
                        partition.AeTitle, partition);
                }

                var utility = new SopInstanceImporter(_importerContext);


                var importResult = utility.Import(theFile);
                if (!importResult.Successful)
                {
                    Platform.Log(LogLevel.Error, "Failure importing file file from Web Service: {0}, SOP Instance UID: {1}", importResult.ErrorMessage, request.SopInstanceUid);
                }
                else
                {
                    Platform.Log(LogLevel.Info, "Processed import for SOP through Web Service: {0}.", request.SopInstanceUid);
                }

                var result = new ImportSopResponse
                {
                    DicomStatusCode = importResult.DicomStatus.Code,
                    FailureMessage  = importResult.ErrorMessage,
                    Successful      = importResult.Successful
                };

                return(result);
            }
            catch (Exception ex)
            {
                var message = string.Format("Failed to import files: {0}, SOP Instance UID: {1}", ex.Message, request.SopInstanceUid);
                Platform.Log(LogLevel.Error, message);
                throw new FaultException(message);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of <see cref="DicomElementBinaryData{T}"/> filled with zero values.
 /// </summary>
 /// <param name="count">Number of initial values.</param>
 /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="count"/> is negative.</exception>
 public DicomElementBinaryData(int count)
 {
     if (count < 0)
     {
         throw new ArgumentOutOfRangeException("count");
     }
     if (count * _sizeOfT <= _thresholdBytes)
     {
         _array = new T[count];
     }
     else
     {
         _stream = new LargeMemoryStream();
         _stream.SetLength(count * _sizeOfT);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of <see cref="DicomElementBinaryData{T}"/> with the values from a <see cref="ByteBuffer"/>.
 /// </summary>
 /// <param name="buffer">Source <see cref="ByteBuffer"/>.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="buffer"/> is null.</exception>
 public DicomElementBinaryData(ByteBuffer buffer)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     if (buffer.Length < _thresholdBytes)
     {
         _array = new T[buffer.Length / _sizeOfT];
         Buffer.BlockCopy(buffer.ToBytes(), 0, _array, 0, _array.Length * _sizeOfT);
     }
     else
     {
         _stream = new LargeMemoryStream();
         buffer.CopyTo(_stream, 0, buffer.Length - (buffer.Length % _sizeOfT));
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of <see cref="DicomElementBinaryData{T}"/> as a copy of another instance.
 /// </summary>
 /// <param name="other">Source <see cref="DicomElementBinaryData{T}"/>.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="other"/> is null.</exception>
 public DicomElementBinaryData(DicomElementBinaryData <T> other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     if (other._array != null)
     {
         _array = new T[other._array.Length];
         other._array.CopyTo(_array, 0);
     }
     else if (other._stream != null)
     {
         _stream = new LargeMemoryStream();
         other._stream.WriteTo(_stream);
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Imports in memory <see cref="DicomFile"/> to a remote server.
        /// </summary>
        /// <param name="callingAETitle">AE title of the local application.</param>
        /// <param name="calledAeTitle">AE title of the remote server</param>
        /// <param name="file">The DICOM file to import</param>
        /// <returns></returns>
        public ImportSopResponse ImportFile(string callingAETitle, string calledAeTitle, DicomFile file)
        {
            var request = new ImportSopRequest
            {
                CallingAETitle = callingAETitle,
                CalledAETitle  = calledAeTitle,
                SopInstanceUid = file.DataSet[DicomTags.SopInstanceUid].ToString(),
            };

            using (var stream = new LargeMemoryStream())
            {
                file.Save(stream, DicomWriteOptions.Default);
                request.SopInstance = stream.ToArray();
            }

            var response = ImportSop(request);

            return(response);
        }
Exemplo n.º 12
0
        public static void WriteXmlAndGzip(StudyXmlMemento theMemento, Stream theXmlStream, Stream theGzipStream)
        {
            // Write to a memory stream, then flush to disk and to gzip file
            var ms = new LargeMemoryStream();

            Write(theMemento, ms);

            var compressedzipStream = new GZipStream(theGzipStream, CompressionMode.Compress, true);

            ms.Seek(0, SeekOrigin.Begin);
            ms.WriteTo(compressedzipStream);

            // Close the stream.
            compressedzipStream.Flush();
            compressedzipStream.Close();

            ms.Seek(0, SeekOrigin.Begin);
            ms.WriteTo(theXmlStream);

            // Force a flush.
            theXmlStream.Flush();
            theGzipStream.Flush();
        }
Exemplo n.º 13
0
        private void ConvertToStream()
        {
            if (_array == null)
            {
                return;
            }

            var stream       = new LargeMemoryStream();
            var buffer       = new byte[_bufferSize];
            var streamLength = _sizeOfT * _array.Length;

            var bytesPosition = 0;
            int bytesInBuffer;

            while ((bytesInBuffer = Math.Min(_bufferSize, streamLength - bytesPosition)) > 0)
            {
                Buffer.BlockCopy(_array, bytesPosition, buffer, 0, bytesInBuffer);
                stream.Write(buffer, 0, bytesInBuffer);
                bytesPosition += bytesInBuffer;
            }

            _stream = stream;
            _array  = null;
        }