Ejemplo n.º 1
0
        public void ReturnsBits()
        {
            var value  = ByteSize.FromBits(10);
            var result = value.ToString("##.#### b");

            Assert.Equal("10 b", result);
        }
Ejemplo n.º 2
0
        public void FromBits()
        {
            var result = ByteSize.FromBits(8);

            Assert.Equal(8, result.Bits);
            Assert.Equal(1, result.Bytes);
        }
Ejemplo n.º 3
0
        public void ReturnsZeroBits()
        {
            var value  = ByteSize.FromBits(0);
            var result = value.ToString();

            Assert.Equal("0 b", result);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Builds an index from the files in a given folder
        /// </summary>
        /// <param name="path">The path to folder to index</param>
        /// <param name="batchSize">The size of a batch, after which the buffers are flushed</param>
        /// <param name="progress">Returns progress messages, use <seealso cref="Progress{T}" /></param>
        /// <returns></returns>
        public async Task Build(string path, int batchSize, IProgress <string> progress)
        {
            var root = new DirectoryInfo(path);

            var batches = Crawl(root).Batch(batchSize, r => r.Select(fi => (fi.FullName, fi.Length)).ToList()).ToList();
            var count   = 0;

            foreach (var part in batches)
            {
                //Measure speed and progress
                count++;
                var partStart = DateTime.Now;
                var size      = ByteSize.FromBits(0);

                progress.Report($"Processing part {count}/{batches.Count}");

                foreach (var(fullName, length) in part)
                {
                    try
                    {
                        //Decode email
                        var email = await MimeMessage.LoadAsync(fullName);

                        //Gather fields
                        var fields = new List <IIndexableField>
                        {
                            new StringField("path", fullName, Field.Store.YES),
                            new Int64Field("Date", email.Date.Ticks, Field.Store.YES),
                            new TextField("Subject", email.Subject, Field.Store.YES)
                        };
                        var listFields = new[]
Ejemplo n.º 5
0
        public void ParseBits()
        {
            var val      = "1b";
            var expected = ByteSize.FromBits(1);
            var result   = ByteSize.Parse(val);

            Assert.Equal(expected, result);
        }
Ejemplo n.º 6
0
        public void ThowsOnUnsupportedData(TimeUnit units)
        {
            var dummyRate = ByteSize.FromBits(1).Per(TimeSpan.FromSeconds(1));

            Assert.Throws <NotSupportedException>(() =>
            {
                dummyRate.Humanize(units);
            });
        }
Ejemplo n.º 7
0
        public void FromBitsMethod()
        {
            long value = 8;

            var result = ByteSize.FromBits(value);

            Assert.Equal(8, result.Bits);
            Assert.Equal(1, result.Bytes);
        }
Ejemplo n.º 8
0
        public void ReturnsBits()
        {
            // Arrange
            var b = ByteSize.FromBits(10);

            // Act
            var result = b.ToString("##.#### b");

            // Assert
            Assert.Equal("10 b", result);
        }
Ejemplo n.º 9
0
        public void ReturnsZeroBits()
        {
            // Arrange
            var b = ByteSize.FromBits(0);

            // Act
            var result = b.ToString();

            // Assert
            Assert.Equal("0 b", result);
        }
 public Download()
 {
     //random data to test display
     this.DownloadName = "Car";
     this.DownloadSize = ByteSize.FromBits(50000);
     this.Hoster       = "Google Drive";
     this.Status       = "Online";
     this.Speed        = "5";
     this.ETA          = "1 minute";
     this.BytesLoaded  = "50 mb";
     this.SaveTo       = "Downloads";
 }
Ejemplo n.º 11
0
        public void FromBitsFraction()
        {
            // Arrange
            long value = 12;

            // Act
            var result = ByteSize.FromBits(value);

            // Assert
            Assert.Equal(12, result.Bits);
            Assert.Equal(1.5, result.Bytes);
        }
Ejemplo n.º 12
0
        public void FromBitsMethod()
        {
            // Arrange
            long value = 8;

            // Act
            var result = ByteSize.FromBits(value);

            // Assert
            Assert.Equal(8, result.Bits);
            Assert.Equal(1, result.Bytes);
        }
Ejemplo n.º 13
0
        private ActionResult FromLongBytes(long quantity, ByteMultiple multiple)
        {
            ByteSize calculatedSize;

            switch (multiple)
            {
            case ByteMultiple.Byte:
                calculatedSize = ByteSize.FromBytes(quantity);
                break;

            case ByteMultiple.KiloByte:
                calculatedSize = ByteSize.FromKiloBytes(quantity);
                break;

            case ByteMultiple.MegaByte:
                calculatedSize = ByteSize.FromMegaBytes(quantity);
                break;

            case ByteMultiple.GigaByte:
                calculatedSize = ByteSize.FromGigaBytes(quantity);
                break;

            case ByteMultiple.TeraByte:
                calculatedSize = ByteSize.FromTeraBytes(quantity);
                break;

            case ByteMultiple.PetaByte:
                calculatedSize = ByteSize.FromPetaBytes(quantity);
                break;

            default:
                calculatedSize = ByteSize.FromBits(quantity);
                break;
            }

            var viewModel = new ByteCalculatorViewModel();

            viewModel.Results.Add(ByteMultiple.Bit.ToString(), calculatedSize.Bits.ToString());
            viewModel.Results.Add(ByteMultiple.Byte.ToString(), calculatedSize.Bytes.ToString());
            viewModel.Results.Add(ByteMultiple.KiloByte.ToString(), calculatedSize.KiloBytes.ToString());
            viewModel.Results.Add(ByteMultiple.MegaByte.ToString(), calculatedSize.MegaBytes.ToString());
            viewModel.Results.Add(ByteMultiple.GigaByte.ToString(), calculatedSize.GigaBytes.ToString());
            viewModel.Results.Add(ByteMultiple.TeraByte.ToString(), calculatedSize.TeraBytes.ToString());
            viewModel.Results.Add(ByteMultiple.PetaByte.ToString(), calculatedSize.PetaBytes.ToString());

            return(this.PartialView("_CalculatorResults", viewModel));
        }
Ejemplo n.º 14
0
 public void ReturnsPluralBits()
 {
     Assert.Equal("2 bits", ByteSize.FromBits(2).ToFullWords());
 }
Ejemplo n.º 15
0
 public void ReturnsSingularBit()
 {
     Assert.Equal("1 bit", ByteSize.FromBits(1).ToFullWords());
 }
Ejemplo n.º 16
0
        public void LongBits()
        {
            const long size = 2;

            Assert.Equal(ByteSize.FromBits(size), size.Bits());
        }
Ejemplo n.º 17
0
 public void Bits()
 {
     Assert.Equal(ByteSize.FromBits(2), (2).Bits());
 }
Ejemplo n.º 18
0
 public void ParseBits()
 {
     Assert.Equal(ByteSize.FromBits(1), ByteSize.Parse("1b"));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Considers input as bits
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public static ByteSize Bits(this ushort input)
 {
     return(ByteSize.FromBits(input));
 }
Ejemplo n.º 20
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var sent = (uint)value;

            return(string.Format("{0} kbps", ByteSize.FromBits(sent).KiloBytes.ToString().Split('.')[0]));
        }
Ejemplo n.º 21
0
 // Token: 0x06000005 RID: 5 RVA: 0x00002074 File Offset: 0x00000274
 public static ByteSize Bits(this int input)
 {
     return(ByteSize.FromBits((long)input));
 }
Ejemplo n.º 22
0
 // Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
 public static ByteSize Bits(this byte input)
 {
     return(ByteSize.FromBits((long)((ulong)input)));
 }
Ejemplo n.º 23
0
        public void SbyteBits()
        {
            const sbyte size = 2;

            Assert.Equal(ByteSize.FromBits(size), size.Bits());
        }
Ejemplo n.º 24
0
        public void ShortBits()
        {
            const short size = 2;

            Assert.Equal(ByteSize.FromBits(size), size.Bits());
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Considers input as bits
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public static ByteSize Bits(this long input)
 {
     return(ByteSize.FromBits(input));
 }
Ejemplo n.º 26
0
        public void UintBits()
        {
            const uint size = 2;

            Assert.Equal(ByteSize.FromBits(size), size.Bits());
        }
Ejemplo n.º 27
0
 public void ReturnsBits()
 {
     Assert.Equal("10 b", ByteSize.FromBits(10).ToString("##.#### b"));
 }
Ejemplo n.º 28
0
        public void MaxValueBits()
        {
            var size = ByteSize.FromBits(long.MaxValue);

            Assert.Equal(long.MaxValue, size.Bits);
        }