コード例 #1
0
ファイル: StreamByteSource.cs プロジェクト: zcr01/fo-dicom
 /// <summary>
 /// Verifies that there is a sufficient number of bytes to read.
 /// </summary>
 /// <param name="count">Required number of bytes.</param>
 /// <param name="callback">Byte source callback.</param>
 /// <param name="state">Callback state.</param>
 /// <returns>true if source contains sufficient number of remaining bytes, false otherwise.</returns>
 public bool Require(uint count, ByteSourceCallback callback, object state)
 {
     lock (_lock)
     {
         return((_stream.Length - _stream.Position) >= count);
     }
 }
コード例 #2
0
        /// <summary>
        /// Verifies that there is a sufficient number of bytes to read.
        /// </summary>
        /// <param name="count">Required number of bytes.</param>
        /// <param name="callback">Byte source callback.</param>
        /// <param name="state">Callback state.</param>
        /// <returns>true if source contains sufficient number of remaining bytes, false otherwise.</returns>
        public bool Require(uint count, ByteSourceCallback callback, object state)
        {
            lock (_lock)
            {
                if ((_position + count) <= _length)
                {
                    return(true);
                }

                if (_fixed)
                {
                    throw new DicomIoException("Requested {0} bytes past end of byte source.", count);
                }

                if (callback == null)
                {
                    throw new DicomIoException(
                              "Requested {0} bytes past end of byte source without providing a callback.",
                              count);
                }

                _required      = count;
                _callback      = callback;
                _callbackState = state;

                return(false);
            }
        }
コード例 #3
0
        /// <summary>
        /// Add byte buffer to byte source.
        /// </summary>
        /// <param name="buffer">Byte buffer to add.</param>
        /// <param name="last">true if added buffer is the last to add, false otherwise.</param>
        public void Add(IByteBuffer buffer, bool last)
        {
            lock (_lock)
            {
                if (_fixed)
                {
                    throw new DicomIoException("Tried to extend fixed length byte source.");
                }

                if (buffer != null && buffer.Size > 0)
                {
                    _buffers.Add(buffer);
                    _length += buffer.Size;

                    if (_callback != null)
                    {
                        if ((_length - _position) >= _required)
                        {
                            _callback.BeginInvoke(this, _callbackState, Callback, _callback);
                            _callback      = null;
                            _callbackState = null;
                            _required      = 0;
                        }
                    }
                }

                _fixed = last;
            }
        }
コード例 #4
0
 private void Callback(IAsyncResult result)
 {
     try {
         ByteSourceCallback cb = (ByteSourceCallback)result.AsyncState;
         cb.EndInvoke(result);
     } catch {
     }
 }
コード例 #5
0
        public bool Require(uint count, ByteSourceCallback callback, object state)
        {
            lock (_lock) {
                if ((_stream.Length - _stream.Position) >= count)
                {
                    return(true);
                }

                throw new DicomIoException("Requested {0} bytes past end of file.", count);
            }
        }
コード例 #6
0
        /// <summary>
        /// Add byte buffer to byte source.
        /// </summary>
        /// <param name="buffer">Byte buffer to add.</param>
        /// <param name="last">true if added buffer is the last to add, false otherwise.</param>
        public void Add(IByteBuffer buffer, bool last)
        {
            lock (_lock)
            {
                if (_fixed) throw new DicomIoException("Tried to extend fixed length byte source.");

                if (buffer != null && buffer.Size > 0)
                {
                    _buffers.Add(buffer);
                    _length += buffer.Size;

                    if (_callback != null)
                    {
                        if ((_length - _position) >= _required)
                        {
                            _callback.BeginInvoke(this, _callbackState, Callback, _callback);
                            _callback = null;
                            _callbackState = null;
                            _required = 0;
                        }
                    }
                }

                _fixed = last;
            }
        }
コード例 #7
0
        /// <summary>
        /// Verifies that there is a sufficient number of bytes to read.
        /// </summary>
        /// <param name="count">Required number of bytes.</param>
        /// <param name="callback">Byte source callback.</param>
        /// <param name="state">Callback state.</param>
        /// <returns>true if source contains sufficient number of remaining bytes, false otherwise.</returns>
        public bool Require(uint count, ByteSourceCallback callback, object state)
        {
            lock (_lock)
            {
                if ((_position + count) <= _length) return true;

                if (_fixed) throw new DicomIoException("Requested {0} bytes past end of byte source.", count);

                if (callback == null)
                    throw new DicomIoException(
                        "Requested {0} bytes past end of byte source without providing a callback.",
                        count);

                _required = count;
                _callback = callback;
                _callbackState = state;

                return false;
            }
        }
コード例 #8
0
 /// <summary>
 /// Verifies that there is a sufficient number of bytes to read.
 /// </summary>
 /// <param name="count">Required number of bytes.</param>
 /// <param name="callback">Byte source callback.</param>
 /// <param name="state">Callback state.</param>
 /// <returns>true if source contains sufficient number of remaining bytes, false otherwise.</returns>
 public bool Require(uint count, ByteSourceCallback callback, object state)
 {
     lock (_lock)
     {
         return (_stream.Length - _stream.Position) >= count;
     }
 }
コード例 #9
0
ファイル: FileByteSource.cs プロジェクト: ZeryZhang/fo-dicom
		public bool Require(uint count, ByteSourceCallback callback, object state) {
			lock (_lock) {
				if ((_stream.Length - _stream.Position) >= count)
					return true;

				throw new DicomIoException("Requested {0} bytes past end of file.", count);
			}
		}
コード例 #10
0
 public bool Require(uint count, ByteSourceCallback callback, object state) => throw new NotImplementedException();