Clean and rename

This commit is contained in:
Adrien Allard committed 2018-09-25 19:28:31 +02:00
1 parent 35b8af73b9
commit 0191b6bf7c
18 files changed
+111 -110

No files matched your search

@@ -373,10 +373,10 @@ namespace FileConverter
for (int jobIndex = 0; jobIndex < this.conversionJobs.Count; jobIndex++)
{
ConversionJob conversionJob = this.conversionJobs[jobIndex];
allJobAreFinished &= !(conversionJob.State == ConversionJob.ConversionState.Ready ||
conversionJob.State == ConversionJob.ConversionState.InProgress);
allJobAreFinished &= !(conversionJob.State == ConversionState.Ready ||
conversionJob.State == ConversionState.InProgress);
if (conversionJob.State == ConversionJob.ConversionState.InProgress)
if (conversionJob.State == ConversionState.InProgress)
{
conversionFlags |= conversionJob.StateFlags;
}
@@ -391,7 +391,7 @@ namespace FileConverter
for (int jobIndex = 0; jobIndex < this.conversionJobs.Count; jobIndex++)
{
ConversionJob conversionJob = this.conversionJobs[jobIndex];
if (conversionJob.State == ConversionJob.ConversionState.Ready &&
if (conversionJob.State == ConversionState.Ready &&
conversionJob.CanStartConversion(conversionFlags))
{
// Find a thread to execute the job.
@@ -411,7 +411,7 @@ namespace FileConverter
{
jobThread.Start(conversionJob);
while (conversionJob.State == ConversionJob.ConversionState.Ready)
while (conversionJob.State == ConversionState.Ready)
{
Debug.Log("Wait the launch of the conversion thread before launching any other thread.");
Thread.Sleep(20);
@@ -430,7 +430,7 @@ namespace FileConverter
bool allConversionsSucceed = true;
for (int index = 0; index < this.conversionJobs.Count; index++)
{
allConversionsSucceed &= this.conversionJobs[index].State == ConversionJob.ConversionState.Done;
allConversionsSucceed &= this.conversionJobs[index].State == ConversionState.Done;
}
if (this.cancelAutoExit)
@@ -472,10 +472,10 @@ namespace FileConverter
ConversionJob conversionJob = parameter as ConversionJob;
if (conversionJob == null)
{
throw new System.ArgumentException("The parameter must be a conversion job.", "parameter");
throw new System.ArgumentException("The parameter must be a conversion job.", nameof(parameter));
}
if (conversionJob.State != ConversionJob.ConversionState.Ready)
if (conversionJob.State != ConversionState.Ready)
{
Debug.LogError("Fail to execute conversion job.");
return;
@@ -483,7 +483,7 @@ namespace FileConverter
try
{
conversionJob.StartConvertion();
conversionJob.StartConversion();
}
catch (Exception exception)
{
@@ -24,7 +24,7 @@ namespace FileConverter.Commands
return false;
}
return this.conversionJob.IsCancelable && this.conversionJob.State == ConversionJob.ConversionState.InProgress;
return this.conversionJob.IsCancelable && this.conversionJob.State == ConversionState.InProgress;
}
public void Execute(object parameter)
@@ -19,9 +19,18 @@ namespace FileConverter.ConversionJobs
private string userState = string.Empty;
private CancelConversionJobCommand cancelCommand;
private string initialInputPath = string.Empty;
private int currentOuputFilePathIndex;
private string initialInputPath;
private int currentOutputFilePathIndex;
public ConversionJob()
{
this.State = ConversionState.InProgress;
this.ConversionPreset = null;
this.initialInputPath = string.Empty;
this.InputFilePath = "C:\\My file.png";
this.UserState = "Design Mode";
}
public ConversionJob(ConversionPreset conversionPreset, string inputFilePath)
{
if (conversionPreset == null)
@@ -41,27 +50,8 @@ namespace FileConverter.ConversionJobs
this.UserState = Properties.Resources.ConversionStatePrepareConversion;
}
public ConversionJob()
{
this.State = ConversionState.InProgress;
this.ConversionPreset = null;
this.initialInputPath = string.Empty;
this.InputFilePath = "C:\\My file.png";
this.UserState = "DesignMode";
}
public event PropertyChangedEventHandler PropertyChanged;
public enum ConversionState
{
Unknown,
Ready,
InProgress,
Done,
Failed,
}
public ConversionPreset ConversionPreset
{
get;
@@ -71,7 +61,7 @@ namespace FileConverter.ConversionJobs
public string InputFilePath
{
get;
private set;
set;
}
public string OutputFilePath
@@ -83,26 +73,23 @@ namespace FileConverter.ConversionJobs
return string.Empty;
}
if (this.CurrentOuputFilePathIndex < 0)
if (this.CurrentOutputFilePathIndex < 0)
{
return this.OutputFilePaths[0];
}
if (this.CurrentOuputFilePathIndex >= this.OutputFilePaths.Length)
if (this.CurrentOutputFilePathIndex >= this.OutputFilePaths.Length)
{
return this.OutputFilePaths[this.OutputFilePaths.Length - 1];
}
return this.OutputFilePaths[this.CurrentOuputFilePathIndex];
return this.OutputFilePaths[this.CurrentOutputFilePathIndex];
}
}
public ConversionState State
{
get
{
return this.state;
}
get => this.state;
private set
{
@@ -198,16 +185,16 @@ namespace FileConverter.ConversionJobs
private set;
}
protected int CurrentOuputFilePathIndex
protected int CurrentOutputFilePathIndex
{
get
{
return this.currentOuputFilePathIndex;
return this.currentOutputFilePathIndex;
}
set
{
this.currentOuputFilePathIndex = value;
this.currentOutputFilePathIndex = value;
this.NotifyPropertyChanged(nameof(this.OutputFilePath));
}
}
@@ -257,7 +244,7 @@ namespace FileConverter.ConversionJobs
this.OutputFilePaths = outputFilePaths;
if (this.OutputFilePaths.Length == 0)
{
int outputFilesCount = this.GetOuputFilesCount();
int outputFilesCount = this.GetOutputFilesCount();
this.OutputFilePaths = new string[outputFilesCount];
}
@@ -313,7 +300,7 @@ namespace FileConverter.ConversionJobs
this.OutputFilePaths[index] = path;
}
this.CurrentOuputFilePathIndex = 0;
this.CurrentOutputFilePathIndex = 0;
// Check if the input file is located on a cd drive.
if (PathHelpers.IsOnCDDrive(this.InputFilePath))
@@ -321,7 +308,16 @@ namespace FileConverter.ConversionJobs
this.StateFlags = ConversionFlags.CdDriveExtraction;
}
this.Initialize();
try
{
this.Initialize();
}
catch (Exception exception)
{
this.ConversionFailed("Error during job initialization.");
Debug.Log(exception.ToString());
return;
}
if (this.State == ConversionState.Unknown)
{
@@ -336,7 +332,7 @@ namespace FileConverter.ConversionJobs
}
}
public void StartConvertion()
public void StartConversion()
{
if (this.ConversionPreset == null)
{
@@ -373,11 +369,11 @@ namespace FileConverter.ConversionJobs
this.OnConversionSucceed();
}
if (this.State == ConversionJob.ConversionState.Done && !this.AllOuputFilesExists())
if (this.State == ConversionState.Done && !this.AllOutputFilesExists())
{
Debug.LogError(Properties.Resources.ErrorCantFindOutputFiles);
}
else if (this.State == ConversionJob.ConversionState.Failed && this.AtLeastOneOuputFilesExists())
else if (this.State == ConversionState.Failed && this.AtLeastOneOutputFilesExists())
{
Debug.Log(Properties.Resources.ErrorConversionFailedWithOutput);
}
@@ -394,7 +390,7 @@ namespace FileConverter.ConversionJobs
this.ConversionFailed(Properties.Resources.ErrorCanceled);
}
protected virtual int GetOuputFilesCount()
protected virtual int GetOutputFilesCount()
{
return 1;
}
@@ -521,7 +517,7 @@ namespace FileConverter.ConversionJobs
Debug.Log("... timestamp matching finished.");
}
private bool AllOuputFilesExists()
private bool AllOutputFilesExists()
{
for (int index = 0; index < this.OutputFilePaths.Length; index++)
{
@@ -535,7 +531,7 @@ namespace FileConverter.ConversionJobs
return true;
}
private bool AtLeastOneOuputFilesExists()
private bool AtLeastOneOutputFilesExists()
{
for (int index = 0; index < this.OutputFilePaths.Length; index++)
{
@@ -34,7 +34,7 @@ namespace FileConverter.ConversionJobs
}
}
protected override int GetOuputFilesCount()
protected override int GetOutputFilesCount()
{
if (this.ConversionPreset.OutputType == OutputType.Pdf)
{
@@ -132,7 +132,7 @@ namespace FileConverter.ConversionJobs
Diagnostics.Debug.Log("Convert pdf to images.");
this.pdf2ImageConversionJob.StartConvertion();
this.pdf2ImageConversionJob.StartConversion();
if (this.pdf2ImageConversionJob.State != ConversionState.Done)
{
@@ -220,7 +220,7 @@ namespace FileConverter.ConversionJobs
private void CompressAsync()
{
this.compressionConversionJob.StartConvertion();
this.compressionConversionJob.StartConversion();
}
}
}
@@ -79,7 +79,7 @@ namespace FileConverter.ConversionJobs
Diagnostics.Debug.Log(string.Empty);
Diagnostics.Debug.Log("Convert image to PNG (intermediate format).");
this.pngConversionJob.StartConvertion();
this.pngConversionJob.StartConversion();
if (this.pngConversionJob.State != ConversionState.Done)
{
@@ -90,7 +90,7 @@ namespace FileConverter.ConversionJobs
Diagnostics.Debug.Log(string.Empty);
Diagnostics.Debug.Log("Convert png intermediate image to gif.");
this.gifConversionJob.StartConvertion();
this.gifConversionJob.StartConversion();
if (this.gifConversionJob.State != ConversionState.Done)
{
@@ -59,7 +59,7 @@ namespace FileConverter.ConversionJobs
Diagnostics.Debug.Log(string.Empty);
Diagnostics.Debug.Log("Convert image to PNG (intermediate format).");
this.pngConversionJob.StartConvertion();
this.pngConversionJob.StartConversion();
if (this.pngConversionJob.State != ConversionState.Done)
{
@@ -69,7 +69,7 @@ namespace FileConverter.ConversionJobs
Diagnostics.Debug.Log(string.Empty);
Diagnostics.Debug.Log("Convert png intermediate image to ICO.");
this.icoConversionJob.StartConvertion();
this.icoConversionJob.StartConversion();
if (this.icoConversionJob.State != ConversionState.Done)
{
@@ -40,7 +40,7 @@ namespace FileConverter.ConversionJobs
}
}
protected override int GetOuputFilesCount()
protected override int GetOutputFilesCount()
{
if (System.IO.Path.GetExtension(this.InputFilePath).ToLowerInvariant() == ".pdf")
{
@@ -64,7 +64,7 @@ namespace FileConverter.ConversionJobs
throw new Exception("The conversion preset must be valid.");
}
this.CurrentOuputFilePathIndex = 0;
this.CurrentOutputFilePathIndex = 0;
if (this.isInputFilePdf)
{
@@ -112,7 +112,7 @@ namespace FileConverter.ConversionJobs
foreach (MagickImage image in images)
{
Debug.Log("Write page {0}/{1}.", this.CurrentOuputFilePathIndex + 1, this.pageCount);
Debug.Log("Write page {0}/{1}.", this.CurrentOutputFilePathIndex + 1, this.pageCount);
if (PdfSuperSamplingRatio > 1)
{
@@ -121,7 +121,7 @@ namespace FileConverter.ConversionJobs
this.ConvertImage(image, true);
this.CurrentOuputFilePathIndex++;
this.CurrentOutputFilePathIndex++;
}
}
}
@@ -223,7 +223,7 @@ namespace FileConverter.ConversionJobs
return;
}
float alreadyCompletedPages = this.CurrentOuputFilePathIndex / (float)this.pageCount;
float alreadyCompletedPages = this.CurrentOutputFilePathIndex / (float)this.pageCount;
this.Progress = alreadyCompletedPages + ((float)eventArgs.Progress.ToDouble() / (100f * this.pageCount));
}
}
@@ -35,7 +35,7 @@ namespace FileConverter.ConversionJobs
}
}
protected override int GetOuputFilesCount()
protected override int GetOutputFilesCount()
{
if (this.ConversionPreset.OutputType == OutputType.Pdf)
{
@@ -121,7 +121,7 @@ namespace FileConverter.ConversionJobs
Diagnostics.Debug.Log("Convert pdf to images.");
this.pdf2ImageConversionJob.StartConvertion();
this.pdf2ImageConversionJob.StartConversion();
if (this.pdf2ImageConversionJob.State != ConversionState.Done)
{
@@ -34,7 +34,7 @@ namespace FileConverter.ConversionJobs
}
}
protected override int GetOuputFilesCount()
protected override int GetOutputFilesCount()
{
if (this.ConversionPreset.OutputType == OutputType.Pdf)
{
@@ -124,7 +124,7 @@ namespace FileConverter.ConversionJobs
Diagnostics.Debug.Log("Convert pdf to images.");
this.pdf2ImageConversionJob.StartConvertion();
this.pdf2ImageConversionJob.StartConversion();
if (this.pdf2ImageConversionJob.State != ConversionState.Done)
{
@@ -0,0 +1,14 @@
// <copyright file="ConversionState.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.ConversionJobs
{
public enum ConversionState
{
Unknown,
Ready,
InProgress,
Done,
Failed,
}
}
@@ -66,8 +66,8 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Magick.NET-Q16-AnyCPU, Version=7.4.6.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=MSIL">
<HintPath>..\..\packages\Magick.NET-Q16-AnyCPU.7.4.6\lib\net40\Magick.NET-Q16-AnyCPU.dll</HintPath>
<Reference Include="Magick.NET-Q16-AnyCPU, Version=7.8.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=MSIL">
<HintPath>..\..\packages\Magick.NET-Q16-AnyCPU.7.8.0\lib\net40\Magick.NET-Q16-AnyCPU.dll</HintPath>
</Reference>
<Reference Include="Markdown.Xaml">
<HintPath>..\..\Middleware\Markdown.Xaml.dll</HintPath>
@@ -122,8 +122,8 @@
<Compile Include="ApplicationTerminateArgs.cs" />
<Compile Include="Commands\DelegateCommand.cs" />
<Compile Include="Commands\OpenUrlCommand.cs" />
<Compile Include="Controls\ConversionJob.xaml.cs">
<DependentUpon>ConversionJob.xaml</DependentUpon>
<Compile Include="Controls\ConversionJobControl.xaml.cs">
<DependentUpon>ConversionJobControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\EncodingQualitySliderControl.xaml.cs">
<DependentUpon>EncodingQualitySliderControl.xaml</DependentUpon>
@@ -141,6 +141,7 @@
<Compile Include="ConversionJobs\ConversionJob_Excel.cs" />
<Compile Include="ConversionJobs\ConversionJob_Word.cs" />
<Compile Include="ConversionJobs\ConversionJob_ImageMagick.cs" />
<Compile Include="ConversionJobs\ConversionState.cs" />
<Compile Include="ConversionJobs\VideoEncodingSpeed.cs" />
<Compile Include="ConversionPreset\ConversionSettingsOverride.cs" />
<Compile Include="ConversionPreset\ConversionSettings.cs" />
@@ -210,7 +211,7 @@
<DependentUpon>UpgradeWindow.xaml</DependentUpon>
</Compile>
<Compile Include="XmlHelpers.cs" />
<Page Include="Controls\ConversionJob.xaml">
<Page Include="Controls\ConversionJobControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
@@ -342,9 +343,7 @@
<ItemGroup>
<Resource Include="Resources\SayThanks-Icon.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="SampleData\ConversionPreset\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(SolutionDir)Middleware\ffmpeg\$(PlatformName)\ffmpeg.exe" "$(TargetDir)ffmpeg.exe"
+1 -1
View File
@@ -96,7 +96,7 @@ namespace FileConverter.Upgrade
{
if (upgradeVersionDescription == null)
{
throw new ArgumentNullException("upgradeVersionDescription");
throw new ArgumentNullException(nameof(upgradeVersionDescription));
}
if (Helpers.currentlyDownloadedVersionDescription != null)
@@ -17,12 +17,12 @@ namespace FileConverter.ValueConverters
return string.Empty;
}
ConversionJob.ConversionState state = (ConversionJob.ConversionState)values[0];
ConversionState state = (ConversionState)values[0];
DateTime startTime = (DateTime)values[1];
float progress = (float)values[2];
if (state == ConversionJob.ConversionState.Unknown ||
state == ConversionJob.ConversionState.Ready ||
if (state == ConversionState.Unknown ||
state == ConversionState.Ready ||
progress < 0.05f)
{
return "-";
@@ -24,13 +24,13 @@ namespace FileConverter.ValueConverters
TaskbarItemProgressState progressState = TaskbarItemProgressState.None;
foreach (ConversionJob job in jobs)
{
if (job.State == ConversionJob.ConversionState.Failed)
if (job.State == ConversionState.Failed)
{
progressState = TaskbarItemProgressState.Error;
break;
}
if (job.State == ConversionJob.ConversionState.InProgress)
if (job.State == ConversionState.InProgress)
{
progressState = TaskbarItemProgressState.Normal;
break;
@@ -13,31 +13,31 @@ namespace FileConverter.ValueConverters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is ConversionJob.ConversionState))
if (!(value is ConversionState))
{
throw new ArgumentException("The value must be a conversion state.");
}
ConversionJob.ConversionState conversionState = (ConversionJob.ConversionState)value;
ConversionState conversionState = (ConversionState)value;
string type = parameter as string;
if (type == "Background")
{
switch (conversionState)
{
case ConversionJob.ConversionState.Unknown:
case ConversionState.Unknown:
return new SolidColorBrush(Color.FromRgb(230, 230, 230));
case ConversionJob.ConversionState.Ready:
case ConversionState.Ready:
return new SolidColorBrush(Color.FromRgb(230, 230, 230));
case ConversionJob.ConversionState.InProgress:
case ConversionState.InProgress:
return new SolidColorBrush(Color.FromRgb(250, 236, 179));
case ConversionJob.ConversionState.Done:
case ConversionState.Done:
return new SolidColorBrush(Color.FromRgb(200, 230, 201));
case ConversionJob.ConversionState.Failed:
case ConversionState.Failed:
return new SolidColorBrush(Color.FromRgb(255, 205, 210));
}
}
@@ -45,19 +45,19 @@ namespace FileConverter.ValueConverters
{
switch (conversionState)
{
case ConversionJob.ConversionState.Unknown:
case ConversionState.Unknown:
return new SolidColorBrush(Color.FromRgb(128, 128, 128));
case ConversionJob.ConversionState.Ready:
case ConversionState.Ready:
return new SolidColorBrush(Color.FromRgb(32, 32, 32));
case ConversionJob.ConversionState.InProgress:
case ConversionState.InProgress:
return new SolidColorBrush(Color.FromRgb(255, 160, 0));
case ConversionJob.ConversionState.Done:
case ConversionState.Done:
return new SolidColorBrush(Color.FromRgb(56, 142, 60));
case ConversionJob.ConversionState.Failed:
case ConversionState.Failed:
return new SolidColorBrush(Color.FromRgb(255, 82, 82));
}
}
@@ -5,29 +5,21 @@
xmlns:local="clr-namespace:FileConverter"
xmlns:valueConverters="clr-namespace:FileConverter.ValueConverters"
xmlns:conversionJobs="clr-namespace:FileConverter.ConversionJobs"
xmlns:generic="clr-namespace:FileConverter.ValueConverters.Generic"
xmlns:project="clr-namespace:FileConverter.Properties"
xmlns:controls="clr-namespace:FileConverter.Controls"
mc:Ignorable="d" x:Class="FileConverter.MainWindow"
x:Name="FileConverterMainWindow" Height="500" Width="950" MinHeight="250" MinWidth="500" WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico">
<Window.Resources>
<valueConverters:ConversionStateToBrush x:Key="ConversionStateToColor" />
<valueConverters:ConversionJobsToProgressState x:Key="ConversionJobsToProgressState" />
<valueConverters:ConversionJobsToProgressValue x:Key="ConversionJobsToProgressValue" />
<generic:ValueConverterGroup x:Key="EnumEqualsToVisibility">
<generic:ValueToString/>
<generic:EqualsConverter/>
<generic:BoolToVisibility/>
</generic:ValueConverterGroup>
</Window.Resources>
<Window.Title>
<Binding Converter="{StaticResource ApplicationVersionToApplicationName}" Mode="OneWay" Path="(local:Application.ApplicationVersion)"/>
</Window.Title>
<Window.TaskbarItemInfo>
<TaskbarItemInfo
ProgressState="{Binding ConvertionJobs, Converter={StaticResource ConversionJobsToProgressState}, ElementName=FileConverterMainWindow}"
ProgressValue="{Binding ConvertionJobs, Converter={StaticResource ConversionJobsToProgressValue}, ElementName=FileConverterMainWindow}" />
ProgressState="{Binding ConversionJobs, Converter={StaticResource ConversionJobsToProgressState}, ElementName=FileConverterMainWindow}"
ProgressValue="{Binding ConversionJobs, Converter={StaticResource ConversionJobsToProgressValue}, ElementName=FileConverterMainWindow}" />
</Window.TaskbarItemInfo>
<Grid Margin="10">
@@ -52,10 +44,10 @@
</Grid>
<ScrollViewer x:Name="ScrollViewer" Grid.Row="1" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
<ItemsControl ItemsSource="{Binding ConvertionJobs, ElementName=FileConverterMainWindow}">
<ItemsControl ItemsSource="{Binding ConversionJobs, ElementName=FileConverterMainWindow}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:ConversionJob></controls:ConversionJob>
<controls:ConversionJobControl></controls:ConversionJobControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.DataContext>
@@ -25,7 +25,7 @@ namespace FileConverter
this.InitializeComponent();
Application application = Application.Current as Application;
this.ConvertionJobs = new ObservableCollection<ConversionJob>(application.ConvertionJobs);
this.ConversionJobs = new ObservableCollection<ConversionJob>(application.ConvertionJobs);
application.OnApplicationTerminate += this.Application_OnApplicationTerminate;
@@ -62,7 +62,7 @@ namespace FileConverter
}
}
public ObservableCollection<ConversionJob> ConvertionJobs
public ObservableCollection<ConversionJob> ConversionJobs
{
get
{
@@ -122,7 +122,7 @@ namespace FileConverter
return;
}
this.OnPropertyChanged(nameof(this.ConvertionJobs));
this.OnPropertyChanged(nameof(this.ConversionJobs));
}
private void SettingsButton_OnClick(object sender, RoutedEventArgs e)