Beispiel #1
0
        /// <summary>
        /// Create a size format based on the size passed in
        /// <list type="bullet">
        /// <item>Size >=     1024 * 1024 * 1024 (1 GB) -> GigaByte Format</item>
        /// <item>else                             -> MegaByte Format</item>
        /// </list>
        /// </summary>
        /// <param name="sizeInBytes">size to base format on</param>
        /// <param name="type">Type to be used for labels, e.g. KB for size, KBps for data rate</param>
        public SizeFormat(Int64 sizeInBytes, SizeFormatType type)
        {
            switch (type)
            {
            case SizeFormatType.DataRate:
                this.KiloSizeLabel = "KBps";
                this.MegaSizeLabel = "MBps";
                this.GigaSizeLabel = "GBps";
                break;

            case SizeFormatType.Size:
            default:
                this.KiloSizeLabel = "KB";
                this.MegaSizeLabel = "MB";
                this.GigaSizeLabel = "GB";
                break;
            }

            if (sizeInBytes >= GIGABYTE_FACTOR)
            {
                this.byteFactor = GIGABYTE_FACTOR;
                this.style      = DecimalStyle;
                this.label      = this.GigaSizeLabel;
            }
            else if (sizeInBytes >= MEGABYTE_FACTOR)
            {
                this.byteFactor = MEGABYTE_FACTOR;
                this.style      = DecimalStyle;
                this.label      = this.MegaSizeLabel;
            }
            else
            {
                this.byteFactor = KILOBYTE_FACTOR;
                this.style      = NumberStyle;
                this.label      = this.KiloSizeLabel;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Static version of format size with label, if the sizeformat doesn't need to be reused
 /// </summary>
 /// <param name="sizeInBytes">size to format</param>
 /// <returns></returns>
 public static string Format(Int64 sizeInBytes, SizeFormatType type)
 {
     return(new SizeFormat(sizeInBytes, type).FormatSizeWithLabel(sizeInBytes));
 }