예제 #1
0
        public SizeLength ToNewLength(TimeSpan length, bool keepSize)
        {
            if (length.Ticks < 0)
            {
                throw new ArgumentException("The length must be greater than zero.", "length");
            }

            var bitrate = Kbps;
            var ratio   = (decimal)this.length.Ticks / (decimal)length.Ticks;

            if (ratio == 0 || keepSize)
            {
                ratio = 1;
            }
            var result = new SizeLength((long)((decimal)this.bytes / ratio), length);

            //Trace.Assert(Math.Abs(result.Kbps - bitrate) < 0.01 || keepSize);
            return(result);
        }
예제 #2
0
        private void NumUpDown_ValueChanged(object sender, EventArgs e)
        {
            switch (unit)
            {
            //case SizeUnit.Bytes:
            //    sizeLength = sizeLength.ToNewSize((long)NumUpDown.Value);
            //    break;
            case SizeUnit.KB:
                sizeLength = sizeLength.ToNewSize((long)(NumUpDown.Value * 1024M));
                break;

            case SizeUnit.MB:
                sizeLength = sizeLength.ToNewSize((long)(NumUpDown.Value * 1024M * 1024M));
                break;

            case SizeUnit.GB:
                sizeLength = sizeLength.ToNewSize((long)(NumUpDown.Value * 1024M * 1024M * 1024M));
                break;

            case SizeUnit.Kbps:
                if (sizeLength.Length.TotalSeconds > 0)
                {
                    sizeLength = sizeLength.ToNewSize((long)(NumUpDown.Value / 8M * 1000M * (decimal)sizeLength.Length.TotalSeconds));
                }
                //else
                //    sizeLength = new SizeLength((long)(NumUpDown.Value / 8M * 1000M), TimeSpan.FromTicks(1));
                break;

            case SizeUnit.Mbps:
                if (sizeLength.Length.TotalSeconds > 0)
                {
                    sizeLength = sizeLength.ToNewSize((long)(NumUpDown.Value / 8M * 1000000M * (decimal)sizeLength.Length.TotalSeconds));
                }
                break;
            }
            if (ValueChanged != null)
            {
                ValueChanged(sender, e);
            }
        }
예제 #3
0
        public SizeLength ToNewLength(TimeSpan length, bool keepSize)
        {
            if (length.Ticks < 0) throw new ArgumentException("The length must be greater than zero.", "length");

            var bitrate = Kbps;
            var ratio = (decimal)this.length.Ticks / (decimal)length.Ticks;
            if (ratio == 0 || keepSize) ratio = 1;
            var result = new SizeLength((long)((decimal)this.bytes / ratio), length);
            //Trace.Assert(Math.Abs(result.Kbps - bitrate) < 0.01 || keepSize);
            return result;
        }
예제 #4
0
 private void NumUpDown_ValueChanged(object sender, EventArgs e)
 {
     switch (unit)
     {
         //case SizeUnit.Bytes:
         //    sizeLength = sizeLength.ToNewSize((long)NumUpDown.Value);
         //    break;
         case SizeUnit.KB:
             sizeLength = sizeLength.ToNewSize((long)(NumUpDown.Value * 1024M));
             break;
         case SizeUnit.MB:
             sizeLength = sizeLength.ToNewSize((long)(NumUpDown.Value * 1024M * 1024M));
             break;
         case SizeUnit.GB:
             sizeLength = sizeLength.ToNewSize((long)(NumUpDown.Value * 1024M * 1024M * 1024M));
             break;
         case SizeUnit.Kbps:
             if (sizeLength.Length.TotalSeconds > 0)
                 sizeLength = sizeLength.ToNewSize((long)(NumUpDown.Value / 8M * 1000M * (decimal)sizeLength.Length.TotalSeconds));
             //else
             //    sizeLength = new SizeLength((long)(NumUpDown.Value / 8M * 1000M), TimeSpan.FromTicks(1));
             break;
         case SizeUnit.Mbps:
             if (sizeLength.Length.TotalSeconds > 0)
                 sizeLength = sizeLength.ToNewSize((long)(NumUpDown.Value / 8M * 1000000M * (decimal)sizeLength.Length.TotalSeconds));
             break;
     }
     if (ValueChanged != null) ValueChanged(sender, e);
 }