Beispiel #1
0
 /// <summary>
 /// Throw ObjectDisposedException if the MRES is disposed
 /// </summary>
 private void ThrowIfDisposed()
 {
     if ((m_combinedState & Dispose_BitMask) != 0)
     {
         throw new ObjectDisposedException(MyEnvironment.GetResourceString("ManualResetEventSlim_Disposed"));
     }
 }
Beispiel #2
0
 public ExpandableMemoryStream(byte[] buffer, int index, int count, bool writable, bool publiclyVisible)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer", MyEnvironment.GetResourceString("ArgumentNull_Buffer"));
     }
     if (index < 0)
     {
         throw new ArgumentOutOfRangeException("index", MyEnvironment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
     }
     if (count < 0)
     {
         throw new ArgumentOutOfRangeException("count", MyEnvironment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
     }
     if ((buffer.Length - index) < count)
     {
         throw new ArgumentException(MyEnvironment.GetResourceString("Argument_InvalidOffLen"));
     }
     this._buffer    = buffer;
     this._origin    = this._position = index;
     this._length    = this._capacity = index + count;
     this._writable  = writable;
     this._exposable = publiclyVisible;
     this._isOpen    = true;
 }
Beispiel #3
0
 public virtual byte[] GetBuffer()
 {
     if (!this._exposable)
     {
         throw new UnauthorizedAccessException(MyEnvironment.GetResourceString("UnauthorizedAccess_MemStreamBuffer"));
     }
     return(this._buffer);
 }
Beispiel #4
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer", MyEnvironment.GetResourceString("ArgumentNull_Buffer"));
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", MyEnvironment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", MyEnvironment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if ((buffer.Length - offset) < count)
            {
                throw new ArgumentException(MyEnvironment.GetResourceString("Argument_InvalidOffLen"));
            }
            if (!this._isOpen)
            {
                // __Error.StreamIsClosed();
                throw new NotImplementedException("");
            }
            this.EnsureWriteable();
            int num = this._position + count;

            if (num < 0)
            {
                throw new IOException(MyEnvironment.GetResourceString("IO.IO_StreamTooLong"));
            }
            if (num > this._length)
            {
                bool flag = this._position > this._length;
                if ((num > this._capacity) && this.EnsureCapacity(num))
                {
                    flag = false;
                }
                if (flag)
                {
                    Array.Clear(this._buffer, this._length, num - this._length);
                }
                this._length = num;
            }
            if ((count <= 8) && (buffer != this._buffer))
            {
                int num2 = count;
                while (--num2 >= 0)
                {
                    this._buffer[this._position + num2] = buffer[offset + num2];
                }
            }
            else
            {
                Buffer.BlockCopy(buffer, offset, this._buffer, this._position, count);
            }
            this._position = num;
        }
Beispiel #5
0
 public virtual void WriteTo(Stream stream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream", MyEnvironment.GetResourceString("ArgumentNull_Stream"));
     }
     if (!this._isOpen)
     {
         //__Error.StreamIsClosed();
         throw new NotImplementedException("");
     }
     stream.Write(this._buffer, this._origin, this._length - this._origin);
 }
Beispiel #6
0
 public ExpandableMemoryStream(byte[] buffer, bool writable)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer", MyEnvironment.GetResourceString("ArgumentNull_Buffer"));
     }
     this._buffer    = buffer;
     this._length    = this._capacity = buffer.Length;
     this._writable  = writable;
     this._exposable = false;
     this._origin    = 0;
     this._isOpen    = true;
 }
Beispiel #7
0
 public ExpandableMemoryStream(int capacity)
 {
     if (capacity < 0)
     {
         throw new ArgumentOutOfRangeException("capacity", MyEnvironment.GetResourceString("ArgumentOutOfRange_NegativeCapacity"));
     }
     this._buffer    = new byte[capacity];
     this._capacity  = capacity;
     this._writable  = true;
     this._exposable = true;
     this._origin    = 0;
     this._isOpen    = true;
 }
Beispiel #8
0
        public override long Seek(long offset, SeekOrigin loc)
        {
            if (!this._isOpen)
            {
                // __Error.StreamIsClosed();
                throw new NotImplementedException("");
            }
            if (offset > 2147483647L)
            {
                throw new ArgumentOutOfRangeException("offset", MyEnvironment.GetResourceString("ArgumentOutOfRange_StreamLength"));
            }
            switch (loc)
            {
            case SeekOrigin.Begin:
            {
                int num = this._origin + ((int)offset);
                if ((offset < 0L) || (num < this._origin))
                {
                    throw new IOException(MyEnvironment.GetResourceString("IO.IO_SeekBeforeBegin"));
                }
                this._position = num;
                break;
            }

            case SeekOrigin.Current:
            {
                int num2 = this._position + ((int)offset);
                if (((this._position + offset) < this._origin) || (num2 < this._origin))
                {
                    throw new IOException(MyEnvironment.GetResourceString("IO.IO_SeekBeforeBegin"));
                }
                this._position = num2;
                break;
            }

            case SeekOrigin.End:
            {
                int num3 = this._length + ((int)offset);
                if (((this._length + offset) < this._origin) || (num3 < this._origin))
                {
                    throw new IOException(MyEnvironment.GetResourceString("IO.IO_SeekBeforeBegin"));
                }
                this._position = num3;
                break;
            }

            default:
                throw new ArgumentException(MyEnvironment.GetResourceString("Argument_InvalidSeekOrigin"));
            }
            return((long)this._position);
        }
Beispiel #9
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer", MyEnvironment.GetResourceString("ArgumentNull_Buffer"));
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", MyEnvironment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", MyEnvironment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if ((buffer.Length - offset) < count)
            {
                throw new ArgumentException(MyEnvironment.GetResourceString("Argument_InvalidOffLen"));
            }
            if (!this._isOpen)
            {
                //__Error.StreamIsClosed();
                throw new NotImplementedException("");
            }
            int byteCount = this._length - this._position;

            if (byteCount > count)
            {
                byteCount = count;
            }
            if (byteCount <= 0)
            {
                return(0);
            }
            if (byteCount <= 8)
            {
                int num2 = byteCount;
                while (--num2 >= 0)
                {
                    buffer[offset + num2] = this._buffer[this._position + num2];
                }
            }
            else
            {
                Buffer.BlockCopy(this._buffer, this._position, buffer, offset, byteCount);
            }
            this._position += byteCount;
            return(byteCount);
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ManualResetEventSlim"/>
        /// class with a Boolen value indicating whether to set the intial state to signaled and a specified
        /// spin count.
        /// </summary>
        /// <param name="initialState">true to set the initial state to signaled; false to set the initial state
        /// to nonsignaled.</param>
        /// <param name="spinCount">The number of spin waits that will occur before falling back to a true
        /// wait.</param>
        /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="spinCount"/> is less than
        /// 0.</exception>
        public ManualResetEventSlim(bool initialState, int spinCount)
        {
            if (spinCount < 0)
            {
                throw new ArgumentOutOfRangeException("spinCount");
            }

            if (spinCount > SpinCountState_MaxValue)
            {
                throw new ArgumentOutOfRangeException(
                          "spinCount",
                          String.Format(MyEnvironment.GetResourceString("ManualResetEventSlim_ctor_SpinCountOutOfRange"), SpinCountState_MaxValue));
            }

            // We will suppress default spin  because the user specified a count.
            Initialize(initialState, spinCount);
        }
Beispiel #11
0
        public override void SetLength(long value)
        {
            if ((value < 0L) || (value > 2147483647L))
            {
                throw new ArgumentOutOfRangeException("value", MyEnvironment.GetResourceString("ArgumentOutOfRange_StreamLength"));
            }
            this.EnsureWriteable();
            if (value > (2147483647 - this._origin))
            {
                throw new ArgumentOutOfRangeException("value", MyEnvironment.GetResourceString("ArgumentOutOfRange_StreamLength"));
            }
            int num = this._origin + ((int)value);

            if (!this.EnsureCapacity(num) && (num > this._length))
            {
                Array.Clear(this._buffer, this._length, num - this._length);
            }
            this._length = num;
            if (this._position > num)
            {
                this._position = num;
            }
        }
Beispiel #12
0
        private bool EnsureCapacity(int value)
        {
            if (value < 0)
            {
                throw new IOException(MyEnvironment.GetResourceString("IO.IO_StreamTooLong"));
            }
            if (value <= this._capacity)
            {
                return(false);
            }
            int num = value;

            if (num < 256)
            {
                num = 256;
            }
            if (num < (this._capacity * 2))
            {
                num = this._capacity * 2;
            }
            this.Capacity = num;
            return(true);
        }