mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-28 17:31:56 +01:00
Add ConversionJobToEstimatedRemainingDuration
This commit is contained in:
1 parent
94f1d0742d
commit
7daf387f8a
2 files changed
+49
No files matched your search
@@ -168,6 +168,7 @@
|
||||
<Compile Include="ValueConverters\ConversionJobsToProgressState.cs" />
|
||||
<Compile Include="ValueConverters\ApplicationVersionToApplicationName.cs" />
|
||||
<Compile Include="ConversionPreset\ConversionPreset.cs" />
|
||||
<Compile Include="ValueConverters\ConversionJobToEstimatedRemainingDuration.cs" />
|
||||
<Compile Include="ValueConverters\ConversionJobsToProgressValue.cs" />
|
||||
<Compile Include="ValueConverters\OutputTypeEnumToViewModel.cs" />
|
||||
<Compile Include="ValueConverters\BitrateToString.cs" />
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
// <copyright file="ConversionJobsToProgressValue.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
using ConversionJobs;
|
||||
|
||||
public class ConversionJobToEstimatedRemainingDuration : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (values.Length != 3)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
ConversionJob.ConversionState state = (ConversionJob.ConversionState)values[0];
|
||||
DateTime startTime = (DateTime)values[1];
|
||||
float progress = (float)values[2];
|
||||
|
||||
if (state == ConversionJob.ConversionState.Unknown ||
|
||||
state == ConversionJob.ConversionState.Ready ||
|
||||
progress < 0.05f)
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
|
||||
if (progress >= 1f)
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
|
||||
TimeSpan elapsedTime = DateTime.Now - startTime;
|
||||
|
||||
double remainingTimeInSeconds = (1 - progress) * elapsedTime.TotalSeconds / progress;
|
||||
TimeSpan remainingTime = TimeSpan.FromSeconds(Math.Floor(remainingTimeInSeconds));
|
||||
return remainingTime.ToString("g");
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user