From ca6e2c89198cea110cb9a7f2b89b64dfc40f45ec Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Wed, 6 Jun 2018 08:35:46 +0200 Subject: [PATCH] Add conversion jobs to progress indicators converters --- .../FileConverter/FileConverter.csproj | 2 + .../ConversionJobsToProgressState.cs | 48 +++++++++++++++++++ .../ConversionJobsToProgressValue.cs | 40 ++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 Application/FileConverter/ValueConverters/ConversionJobsToProgressState.cs create mode 100644 Application/FileConverter/ValueConverters/ConversionJobsToProgressValue.cs diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 3b3278a..b0c0174 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -165,8 +165,10 @@ + + diff --git a/Application/FileConverter/ValueConverters/ConversionJobsToProgressState.cs b/Application/FileConverter/ValueConverters/ConversionJobsToProgressState.cs new file mode 100644 index 0000000..0a5f0cf --- /dev/null +++ b/Application/FileConverter/ValueConverters/ConversionJobsToProgressState.cs @@ -0,0 +1,48 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.ValueConverters +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Windows.Data; + using System.Windows.Shell; + + using FileConverter.ConversionJobs; + + public class ConversionJobsToProgressState : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (!(value is IEnumerable)) + { + return TaskbarItemProgressState.None; + } + + IEnumerable jobs = (IEnumerable)value; + + TaskbarItemProgressState progressState = TaskbarItemProgressState.None; + foreach (ConversionJob job in jobs) + { + if (job.State == ConversionJob.ConversionState.Failed) + { + progressState = TaskbarItemProgressState.Error; + break; + } + + if (job.State == ConversionJob.ConversionState.InProgress) + { + progressState = TaskbarItemProgressState.Normal; + break; + } + } + + return progressState; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Application/FileConverter/ValueConverters/ConversionJobsToProgressValue.cs b/Application/FileConverter/ValueConverters/ConversionJobsToProgressValue.cs new file mode 100644 index 0000000..95c75a7 --- /dev/null +++ b/Application/FileConverter/ValueConverters/ConversionJobsToProgressValue.cs @@ -0,0 +1,40 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.ValueConverters +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Windows.Data; + using System.Windows.Shell; + + using FileConverter.ConversionJobs; + + public class ConversionJobsToProgressValue : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (!(value is IEnumerable)) + { + return TaskbarItemProgressState.None; + } + + IEnumerable jobs = (IEnumerable)value; + + int jobCount = 0; + float progressValue = 0f; + foreach (ConversionJob job in jobs) + { + progressValue += job.Progress; + jobCount++; + } + + return jobCount > 0 ? progressValue / jobCount : 0f; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +}