public void CalculationOfBitsPerSecondFailsOnIllegalDifference() { DateTime start = DateTime.Now; DateTime end = start.AddSeconds(1); Assert.Throws <ArgumentException>(() => TransmissionProgressEventArgs.CalcBitsPerSecond(end, start, 100)); }
/// <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 }); } }
public void CalculateBitsPerSecondWithOneMilisecondDifference() { DateTime start = DateTime.Now; DateTime end = start.AddMilliseconds(1); long? bitsPerSecond = TransmissionProgressEventArgs.CalcBitsPerSecond(start, end, 1); Assert.AreEqual(8000, bitsPerSecond); }
/// <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(); }
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); }