示例#1
0
        public void CalculationOfBitsPerSecondFailsOnIllegalDifference()
        {
            DateTime start = DateTime.Now;
            DateTime end   = start.AddSeconds(1);

            Assert.Throws <ArgumentException>(() => TransmissionProgressEventArgs.CalcBitsPerSecond(end, start, 100));
        }
示例#2
0
        /// <summary>
        /// Calculates the bandwidth.
        /// </summary>
        /// <param name='transmittedBytes'>
        /// Transmitted bytes.
        /// </param>
        private void CalculateBandwidth(int transmittedBytes)
        {
            this.bytesTransmittedSinceLastSecond += transmittedBytes;
            TimeSpan diff = DateTime.Now - this.start;
            long?    pos;
            long?    length = null;

            try {
                pos = Stream.Position;
                if (pos > this.transmissionEvent.Status.Length)
                {
                    length = this.Stream.Length;
                }
            } catch (NotSupportedException) {
                pos = null;
            }

            if (diff.Seconds >= 1)
            {
                long?result = TransmissionProgressEventArgs.CalcBitsPerSecond(this.start, DateTime.Now, this.bytesTransmittedSinceLastSecond);
                this.transmissionEvent.ReportProgress(new TransmissionProgressEventArgs {
                    ActualPosition = pos, BitsPerSecond = result, Length = length
                });
                this.bytesTransmittedSinceLastSecond = 0;
                this.start = this.start + diff;
                this.blockingDetectionTimer.Stop();
                this.blockingDetectionTimer.Start();
            }
            else
            {
                this.transmissionEvent.ReportProgress(new TransmissionProgressEventArgs {
                    ActualPosition = pos, Length = length
                });
            }
        }
示例#3
0
        public void CalculateBitsPerSecondWithOneMilisecondDifference()
        {
            DateTime start         = DateTime.Now;
            DateTime end           = start.AddMilliseconds(1);
            long?    bitsPerSecond = TransmissionProgressEventArgs.CalcBitsPerSecond(start, end, 1);

            Assert.AreEqual(8000, bitsPerSecond);
        }
示例#4
0
        /// <summary>
        /// Close this instance and calculates the bandwidth of the last second.
        /// </summary>
        public override void Close()
        {
            long?result = TransmissionProgressEventArgs.CalcBitsPerSecond(this.start, DateTime.Now.AddMilliseconds(1), this.bytesTransmittedSinceLastSecond);

            this.transmissionEvent.ReportProgress(new TransmissionProgressEventArgs()
            {
                BitsPerSecond = result
            });
            base.Close();
        }
示例#5
0
        public void CalcBitsPerSecondWithOneSecondDifference()
        {
            DateTime start         = DateTime.Now;
            DateTime end           = start.AddSeconds(1);
            long?    bitsPerSecond = TransmissionProgressEventArgs.CalcBitsPerSecond(start, end, 1);

            Assert.AreEqual(8, bitsPerSecond);
            bitsPerSecond = TransmissionProgressEventArgs.CalcBitsPerSecond(start, start, 100);
            Assert.Null(bitsPerSecond);
            bitsPerSecond = TransmissionProgressEventArgs.CalcBitsPerSecond(start, end, 100);
            Assert.AreEqual(8 * 100, bitsPerSecond);
        }