public void Unit_display_mode_hide_only_for_bytes_test(int bytes, string expectedFriendlyName)
        {
            var options = new FriendlyNameOptions {
                UnitDisplayMode = UnitDisplayMode.HideOnlyForBytes
            };
            string friendlyName = ByteSizeFriendlyName.Build(bytes, options);

            Assert.Equal(expectedFriendlyName, friendlyName);
        }
Example #2
0
        public void Unit_display_mode_group_digits_test(int bytes, string expectedFriendlyName)
        {
            var options = new FriendlyNameOptions {
                GroupDigits = true
            };
            string friendlyName = ByteSizeFriendlyName.Build(bytes, options);

            friendlyName.ShouldBe(expectedFriendlyName);
        }
Example #3
0
        public void Unit_display_mode_group_digits_test(int bytes, string expectedFriendlyName)
        {
            var options = new FriendlyNameOptions
            {
                GroupDigits = true
            };
            var friendlyName = ByteSizeFriendlyName.Build(bytes, options);

            Assert.Equal(expectedFriendlyName, friendlyName);
        }
        public void Gigabyte_values()
        {
            const long size = 1024L * 1024 * 1024 * 10;

            string friendlyName = ByteSizeFriendlyName.Build(size, new FriendlyNameOptions {
                DecimalPlaces = 10
            });;

            Assert.Equal("10 GB", friendlyName);

            friendlyName = ByteSizeFriendlyName.Build(size, new FriendlyNameOptions {
                UnitDisplayMode = UnitDisplayMode.AlwaysHide
            });
            Assert.Equal("10", friendlyName);

            friendlyName = ByteSizeFriendlyName.Build(size, new FriendlyNameOptions {
                UnitDisplayMode = UnitDisplayMode.HideOnlyForBytes
            });
            Assert.Equal("10 GB", friendlyName);
        }
        public void Megabyte_values()
        {
            const long size = 1024L * 1024 * 10;

            string friendlyName = ByteSizeFriendlyName.Build(size, new FriendlyNameOptions {
                DecimalPlaces = 10
            });

            friendlyName.ShouldBe("10 MB");

            friendlyName = ByteSizeFriendlyName.Build(size, new FriendlyNameOptions {
                UnitDisplayMode = UnitDisplayMode.AlwaysHide
            });
            friendlyName.ShouldBe("10");

            friendlyName = ByteSizeFriendlyName.Build(size, new FriendlyNameOptions {
                UnitDisplayMode = UnitDisplayMode.HideOnlyForBytes
            });
            friendlyName.ShouldBe("10 MB");
        }
Example #6
0
        public override void SetContent()
        {
            base.SetContent();

            var gridRow = this.RowInfo as GridViewGroupRowInfo;

            if (gridRow == null)
            {
                return;
            }

            int  remainingFileCount = 0;
            long copiedBytes        = 0;
            long totalBytes         = 0;
            bool hasErrors          = false;

            foreach (var dataRow in RadGridViewHelper.GetChildDataRows(gridRow))
            {
                remainingFileCount = Math.Max(remainingFileCount, dataRow.Field <int>("remainingFileCount"));
                copiedBytes       += dataRow.Field <long>("copiedBytes");
                totalBytes        += dataRow.Field <long>("totalBytes");
                hasErrors         |= dataRow.Field <bool>("hasErrors");
            }

            _headerElement.Text     = gridRow.HeaderText;
            _hasErrorsElement.Image = hasErrors ? Resources.ExclamationRed : Resources.CheckedGreen;

            _progressElement.Value1 = totalBytes <= 0 ? 0 : Convert.ToInt32((double)copiedBytes / (double)totalBytes * 100);
            _progressElement.Text   = string.Format("{0} remaining ({1}/{2})", remainingFileCount, ByteSizeFriendlyName.Build(copiedBytes), ByteSizeFriendlyName.Build(totalBytes));
            _progressElement.IndicatorElement1.BackColor = (hasErrors || _progressElement.Value1 < 100) ? _defaultProgressBarColor : Color.LimeGreen;

            this.Text = string.Empty;
        }
Example #7
0
        static void Main(string[] args)
        {
            //para filtrar os arquivos
            //se atente ao método GetFiles("*")
            //mude o parametro para por exemplo: GetFiles("*.png")
            //com isso o sistema irá fazer o search em todos os arquivos com extensão .png
            try
            {
                new DirectoryInfo(@"C:\Users\Roberto\Desktop\Wallpapers").GetFiles("*", SearchOption.AllDirectories).ToList().ForEach((i) =>
                {
                    WriteLine(string.Format("Arquivo: {0} - Tamanho: {1}", i.FullName, ByteSizeFriendlyName.Build(i.Length)));
                });
            } catch (Exception erro)
            {
                throw new Exception("Erro ao processar os arquivos: " + erro.Message);
            }



            ReadKey();
        }
Example #8
0
        public void Bytes_test(int bytes, string expectedFriendlyName)
        {
            string friendlyName = ByteSizeFriendlyName.Build(bytes);

            friendlyName.ShouldBe(expectedFriendlyName);
        }
Example #9
0
 public void Negative_byte_values_should_throw_exception(int bytes)
 {
     Should.Throw <ArgumentOutOfRangeException>(() => ByteSizeFriendlyName.Build(bytes));
 }
Example #10
0
        public void Bytes_test(int bytes, string expectedFriendlyName)
        {
            var friendlyName = ByteSizeFriendlyName.Build(bytes);

            Assert.Equal(expectedFriendlyName, friendlyName);
        }
Example #11
0
        //TODO: review UI reset of cells (they are reused by the gridview)
        private void gridFiles_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.Row.DataBoundItem == null)
            {
                return;
            }

            e.CellElement.ToolTipText = e.CellElement.Text;

            if (string.Equals(e.CellElement.ColumnInfo.FieldName, "progressBar", StringComparison.Ordinal))
            {
                RadProgressBarElement pbElement;
                if (e.CellElement.Children.Count == 0)
                {
                    pbElement = new RadProgressBarElement {
                        SmoothingMode       = SmoothingMode.AntiAlias,
                        Padding             = new Padding(5),
                        StretchHorizontally = true
                    };

                    e.CellElement.Children.Add(pbElement);
                }
                else
                {
                    pbElement            = e.CellElement.Children[0] as RadProgressBarElement;
                    pbElement.Visibility = ElementVisibility.Visible;
                }

                var dataRowView = e.Row.DataBoundItem as DataRowView;

                if (dataRowView != null && dataRowView.Row.RowState != DataRowState.Detached)
                {
                    var progress           = (double)dataRowView.Row["progressBar"];
                    var remainingFileCount = (int)dataRowView.Row["remainingFileCount"];
                    var copiedBytes        = (long)dataRowView.Row["copiedBytes"];
                    var totalBytes         = (long)dataRowView.Row["totalBytes"];

                    progress *= 100;

                    pbElement.Value1 = Convert.ToInt32(progress);
                    pbElement.Text   = string.Format("{0} remaining ({1}/{2})", remainingFileCount, ByteSizeFriendlyName.Build(copiedBytes), ByteSizeFriendlyName.Build(totalBytes));

                    pbElement.IndicatorElement1.BackColor = progress < 100 ? _defaultProgressBarColor : Color.LimeGreen;
                }

                e.CellElement.DrawText  = false;
                e.CellElement.DrawImage = false;
            }
            else
            {
                if (e.CellElement.Children.Count > 0)
                {
                    e.CellElement.Children[0].Visibility = ElementVisibility.Hidden;
                }

                if (string.Equals(e.CellElement.ColumnInfo.FieldName, "hasErrors", StringComparison.Ordinal))
                {
                    e.CellElement.DrawImage = true;
                    e.CellElement.DrawText  = false;

                    var row = ((DataRowView)e.Row.DataBoundItem).Row;

                    if (row.RowState != DataRowState.Detached)
                    {
                        if ((bool)row["hasErrors"])
                        {
                            e.CellElement.Image = Resources.ExclamationRed;
                        }
                        else
                        {
                            e.CellElement.Image = Resources.CheckedGreen;
                        }
                    }
                }
                else
                {
                    e.CellElement.DrawImage = false;
                    e.CellElement.DrawText  = true;
                }
            }
        }