Skip to content

Commit

Permalink
Added file size info and MB uploaded info to upload control.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drexel2k committed Jun 17, 2020
1 parent 6b8d526 commit 2c48f18
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
13 changes: 9 additions & 4 deletions VidUp.Business/Upload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class Upload : INotifyPropertyChanged
[JsonProperty]
private long bytesSent;

private long fileLength;

public event PropertyChangedEventHandler PropertyChanged;

public Guid Guid { get => this.guid; }
Expand Down Expand Up @@ -248,13 +250,16 @@ public long FileLength
{
get
{
FileInfo fileInfo = new FileInfo(this.filePath);
if (fileInfo.Exists)
if (this.fileLength <= 0)
{
return fileInfo.Length;
FileInfo fileInfo = new FileInfo(this.filePath);
if (fileInfo.Exists)
{
this.fileLength = fileInfo.Length;
}
}

return 0;
return this.fileLength;
}
}

Expand Down
9 changes: 8 additions & 1 deletion VidUp.UI/Controls/UploadControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<RowDefinition MinHeight="30" Height="10*"></RowDefinition>
<RowDefinition MinHeight="30" Height="10*"></RowDefinition>
<RowDefinition MinHeight="30" Height="10*"></RowDefinition>
<RowDefinition MinHeight="30" Height="10*"></RowDefinition>
</Grid.RowDefinitions>
<Canvas Grid.Row="0" Grid.ColumnSpan="3" Margin="1 0 1 0">
<Canvas.Background>
Expand Down Expand Up @@ -145,7 +146,7 @@
</ComboBox.ItemTemplate>
</ComboBox>

<StackPanel Grid.Row="7" Grid.Column="3" Orientation="Horizontal">
<StackPanel Grid.Row="7" Grid.Column="2" Orientation="Horizontal">
<CheckBox IsChecked="{Binding PublishAt}" VerticalAlignment="Top" Margin="0 3 0 0" IsEnabled="{Binding ControlsEnabled}" />
<Label Content="Publish At: " Width="96" />
<DatePicker Width="100" materialDesign:HintAssist.Hint="Pick Date" Style="{StaticResource MaterialDesignDatePicker}" SelectedDate="{Binding PublishAtDate}" IsEnabled="{Binding PublishAt}" DisplayDateStart="{Binding PublishAtFirstDate, Mode=OneWay}" Margin="0 3 0 0" />
Expand Down Expand Up @@ -177,6 +178,12 @@
</StackPanel>
</StackPanel>

<Label Grid.Row="10" Grid.Column="0" Content="File Size: " Width="110" />
<Label Grid.Row="10" Grid.Column="1" Content="{Binding FileSizeInMegaByte}" Width="190" HorizontalAlignment="Left" />
<StackPanel Grid.Row="10" Grid.Column="2" Orientation="Horizontal">
<Label Content="Uploaded: " Width="96" />
<Label Content="{Binding UploadedInMegaByte}" Width="96" />
</StackPanel>

</Grid>

Expand Down
2 changes: 1 addition & 1 deletion VidUp.UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
<Label Content="Current File MB left: " />
<Label Content="{Binding CurrentFileMbLeft, Mode=OneWay}" />
<Label Content=" | " />
<Label Content="Current Upload Speed (KByte/s): " />
<Label Content="Current Upload Speed (KBytes/s): " />
<Label Content="{Binding CurrentUploadSpeedInKiloBytesPerSecond, Mode=OneWay}" />
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="right">
Expand Down
18 changes: 18 additions & 0 deletions VidUp.UI/ViewModels/UploadViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Runtime.Remoting.Messaging;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using Drexel.VidUp.Business;
using Drexel.VidUp.JSON;
using Drexel.VidUp.Utils;

#endregion

Expand Down Expand Up @@ -245,6 +248,16 @@ public Visibility Visibility
}
}

public string FileSizeInMegaByte
{
get => $"{((float)this.upload.FileLength / Constants.ByteMegaByteFactor).ToString("N0", CultureInfo.CurrentCulture)} MB";
}

public string UploadedInMegaByte
{
get => $"{((float)this.upload.BytesSent / Constants.ByteMegaByteFactor).ToString("N0", CultureInfo.CurrentCulture)} MB";
}

public string ShowFileNotExistsIcon
{
get
Expand Down Expand Up @@ -432,6 +445,11 @@ private void uploadPropertyChanged(object sender, PropertyChangedEventArgs e)

return;
}

if (e.PropertyName == "BytesSent")
{
this.raisePropertyChanged("UploadedInMegaByte");
}
}

private void raisePropertyChanged(string propertyName)
Expand Down

0 comments on commit 2c48f18

Please sign in to comment.