Exemplo n.º 1
0
        /// <summary>Retrieves the FileSizeType.</summary>
        /// <param name="value">The value.</param>
        /// <param name="formatted">The formatting toggle.</param>
        /// <returns>The <see cref="FileSizeTypes" />.</returns>
        public static FileSizeTypes GetFileSizeType(long value, bool formatted)
        {
            int           _count         = formatted ? GetStepCount(value) : 0;
            FileSizeTypes _fileSizeTypes = (FileSizeTypes)_count;

            return(_fileSizeTypes);
        }
Exemplo n.º 2
0
        /// <summary>Initializes a new instance of the <see cref="Bytes" /> class.</summary>
        public Bytes()
        {
            _abbreviated   = false;
            _abbreviations = Abbreviations.B;
            _fileSizeTypes = FileSizeTypes.Bytes;
            _formatted     = true;
            _formattedSize = 0;
            _totalSize     = 0;

            Update(_totalSize);
        }
Exemplo n.º 3
0
        /// <summary>Update the structure.</summary>
        /// <param name="value">The total bytes value.</param>
        private void Update(long value)
        {
            _formattedSize = value;
            _totalSize     = value;

            if (_formatted)
            {
                _formattedSize = FormatBytes(_totalSize);
            }

            _fileSizeTypes = GetFileSizeType(_totalSize, _formatted);
            _abbreviations = ConvertToAbbreviation(_fileSizeTypes);
        }
Exemplo n.º 4
0
        /// <summary>Get the full size type.</summary>
        /// <param name="abbreviations">The abbreviation.</param>
        /// <returns>The <see cref="FileSizeTypes" />.</returns>
        public static FileSizeTypes ConvertToSizeType(Abbreviations abbreviations)
        {
            FileSizeTypes _fileSizeTypes;

            switch (abbreviations)
            {
            case Abbreviations.B:
            {
                _fileSizeTypes = FileSizeTypes.Bytes;
                break;
            }

            case Abbreviations.KB:
            {
                _fileSizeTypes = FileSizeTypes.Kilobytes;
                break;
            }

            case Abbreviations.MB:
            {
                _fileSizeTypes = FileSizeTypes.Megabytes;
                break;
            }

            case Abbreviations.GB:
            {
                _fileSizeTypes = FileSizeTypes.Gigabytes;
                break;
            }

            case Abbreviations.TB:
            {
                _fileSizeTypes = FileSizeTypes.Terabytes;
                break;
            }

            case Abbreviations.PB:
            {
                _fileSizeTypes = FileSizeTypes.Petabytes;
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(abbreviations), abbreviations, null);
            }
            }

            return(_fileSizeTypes);
        }
Exemplo n.º 5
0
        /// <summary>Get the abbreviation of the size type.</summary>
        /// <param name="fileSizeTypes">The size type.</param>
        /// <returns>The <see cref="Abbreviations" />.</returns>
        public static Abbreviations ConvertToAbbreviation(FileSizeTypes fileSizeTypes)
        {
            Abbreviations _abbreviations;

            switch (fileSizeTypes)
            {
            case FileSizeTypes.Bytes:
            {
                _abbreviations = Abbreviations.B;
                break;
            }

            case FileSizeTypes.Kilobytes:
            {
                _abbreviations = Abbreviations.KB;
                break;
            }

            case FileSizeTypes.Megabytes:
            {
                _abbreviations = Abbreviations.MB;
                break;
            }

            case FileSizeTypes.Gigabytes:
            {
                _abbreviations = Abbreviations.GB;
                break;
            }

            case FileSizeTypes.Terabytes:
            {
                _abbreviations = Abbreviations.TB;
                break;
            }

            case FileSizeTypes.Petabytes:
            {
                _abbreviations = Abbreviations.PB;
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(fileSizeTypes), fileSizeTypes, null);
            }
            }

            return(_abbreviations);
        }