Example #1
0
        /// <summary>
        /// Constructs a new <see cref="MeteringStream"/> that will meter the given
        /// stream.
        /// </summary>
        /// <param name="stream">The inner stream this meter will delegate to</param>
        public MeteringStream(Stream stream)
            : base(stream)
        {
            if (this.CanRead)
            {
                readMeter = new MutableMeter();
            }

            if (this.CanWrite)
            {
                writeMeter = new MutableMeter();
            }

            if (readMeter != null)
            {
                readMeter.SetMinimumValue(0L);
                readMeter.SetCurrentValue(0L);
            }

            if (writeMeter != null)
            {
                writeMeter.SetCurrentValue(0L);
                writeMeter.SetMinimumValue(0L);
            }

            if (this.CanSeek)
            {
                if (readMeter != null)
                {
                    readMeter.SetMaximumValue(this.Length);
                }

                if (writeMeter != null)
                {
                    writeMeter.SetMaximumValue(this.Length);
                }
            }
            else
            {
                if (readMeter != null)
                {
                    readMeter.SetMaximumValue(Int64.MaxValue);
                }

                if (writeMeter != null)
                {
                    writeMeter.SetMaximumValue(Int64.MaxValue);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Constructs a new <see cref="MeteringStream"/> that will meter the given
        /// stream.
        /// </summary>
        /// <param name="stream">The inner stream this meter will delegate to</param>
        public MeteringStream(Stream stream)
            : base(stream)
        {
            if (this.CanRead)
            {
                readMeter = new MutableMeter();
            }

            if (this.CanWrite)
            {
                writeMeter = new MutableMeter();
            }

            if (readMeter != null)
            {
                readMeter.SetMinimumValue(0L);
                readMeter.SetCurrentValue(0L);
            }

            if (writeMeter != null)
            {
                writeMeter.SetCurrentValue(0L);
                writeMeter.SetMinimumValue(0L);
            }

            if (this.CanSeek)
            {
                if (readMeter != null)
                {
                    readMeter.SetMaximumValue(this.Length);
                }

                if (writeMeter != null)
                {
                    writeMeter.SetMaximumValue(this.Length);
                }
            }
            else
            {
                if (readMeter != null)
                {
                    readMeter.SetMaximumValue(Int64.MaxValue);
                }

                if (writeMeter != null)
                {
                    writeMeter.SetMaximumValue(Int64.MaxValue);
                }
            }
        }