Beispiel #1
0
        // Returns a file size given in bytes to a different unit, as a formatted string
        public static string GetSize(long from, SizeUnit to)
        {
            string outstr;

            switch (to)
            {
            case SizeUnit.B:
                outstr = from.ToString();
                break;

            case SizeUnit.KB:
                outstr = String.Format(DECIMAL_FORMATTER, ((double)from) / 1024);
                break;

            case SizeUnit.MB:
                outstr = String.Format(DECIMAL_FORMATTER, ((double)from) / 1024 / 1024);
                break;

            default:
                outstr = String.Format(DECIMAL_FORMATTER, ((double)from) / 1024 / 1024 / 1024);
                break;
            }

            return(outstr + " " + to.ToString());
        }
Beispiel #2
0
        public void It_should_support_NotSet_value()
        {
            var x = new SizeUnit();

            x.ShouldBe(SizeUnit.NotSet);
            x.Value.ShouldBe(0);
            x.IsAbsolute.ShouldBeFalse();
            x.IsUnlimited.ShouldBeFalse();
            x.IsNotSet.ShouldBeTrue();
            x.ToString().ShouldBe("-");
        }
Beispiel #3
0
        public static string Abbreviation(this SizeUnit unit)
        {
            if (unit == SizeUnit.Bytes)
            {
                return("B");
            }

            if (unit == SizeUnit.Bits)
            {
                return("b");
            }

            var firstLetter = unit.ToString()[0] + "";

            if (((int)unit & 0x00FF) == (int)SizeUnit.Bits)
            {
                return(firstLetter + "iB");
            }

            return(firstLetter + "B");
        }
Beispiel #4
0
 public static IEverything Unit(this IEverything everything, SizeUnit unit)
 {
     return(Size(everything, unit.ToString().ToLower()));
 }
Beispiel #5
0
 public ITimeConstraintBuilder SmallerThan(uint size, SizeUnit unit) => SizeQuery($"<{size}{unit.ToString()}");
Beispiel #6
0
 public ITimeConstraintBuilder Sized(uint size, SizeUnit unit) => SizeQuery($"{size}{unit.ToString()}");
Beispiel #7
0
 public static string ConvertFileSize(long byteSize, SizeUnit unit)
 {
     return((byteSize / (double)Math.Pow(1024, (long)unit)).ToString("0.00") + " " + unit.ToString());
 }