This commit is contained in:
2023-10-15 09:51:56 -07:00
parent 2cd2c2b434
commit cd5ab223c9
75 changed files with 895 additions and 722 deletions

View File

@ -0,0 +1,2 @@
[*.cs]
csharp_preserve_single_line_statements = true

View File

@ -24,20 +24,13 @@ public class AppSettings
private static Models.AppSettings Get(AppSettings? appSettings)
{
Models.AppSettings result;
if (appSettings?.Company is null)
throw new NullReferenceException(nameof(appSettings.Company));
if (appSettings?.DefaultUnknownDirectoryName is null)
throw new NullReferenceException(nameof(appSettings.DefaultUnknownDirectoryName));
if (appSettings?.ForceIdName is null)
throw new NullReferenceException(nameof(appSettings.ForceIdName));
if (appSettings?.MaxDegreeOfParallelism is null)
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
if (appSettings?.MaxMinutesDelta is null)
throw new NullReferenceException(nameof(appSettings.MaxMinutesDelta));
if (appSettings?.RenameUndo is null)
throw new NullReferenceException(nameof(appSettings.RenameUndo));
if (appSettings?.WorkingDirectoryName is null)
throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
if (appSettings?.Company is null) throw new NullReferenceException(nameof(appSettings.Company));
if (appSettings?.DefaultUnknownDirectoryName is null) throw new NullReferenceException(nameof(appSettings.DefaultUnknownDirectoryName));
if (appSettings?.ForceIdName is null) throw new NullReferenceException(nameof(appSettings.ForceIdName));
if (appSettings?.MaxDegreeOfParallelism is null) throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
if (appSettings?.MaxMinutesDelta is null) throw new NullReferenceException(nameof(appSettings.MaxMinutesDelta));
if (appSettings?.RenameUndo is null) throw new NullReferenceException(nameof(appSettings.RenameUndo));
if (appSettings?.WorkingDirectoryName is null) throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
result = new(
appSettings.Company,
appSettings.DefaultUnknownDirectoryName,

View File

@ -1,6 +1,5 @@
using Microsoft.Extensions.Configuration;
using Phares.Shared;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
namespace View_by_Distance.Rename.Models.Binder;
@ -10,9 +9,9 @@ public class Configuration
#nullable disable
[Display(Name = "Ignore Extensions"), Required] public string[] IgnoreExtensions { get; set; }
[Display(Name = "Property Configuration"), Required] public Property.Models.Configuration PropertyConfiguration { get; set; }
[Display(Name = "Person Birthday Format"), Required] public string PersonBirthdayFormat { get; set; }
public string[] IgnoreExtensions { get; set; }
public Property.Models.Configuration PropertyConfiguration { get; set; }
public string PersonBirthdayFormat { get; set; }
#nullable restore
@ -25,12 +24,9 @@ public class Configuration
private static Models.Configuration Get(Configuration? configuration)
{
Models.Configuration result;
if (configuration is null)
throw new NullReferenceException(nameof(configuration));
if (configuration.IgnoreExtensions is null)
throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
if (configuration.PersonBirthdayFormat is null)
throw new NullReferenceException(nameof(configuration.PersonBirthdayFormat));
if (configuration is null) throw new NullReferenceException(nameof(configuration));
if (configuration.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
if (configuration.PersonBirthdayFormat is null) throw new NullReferenceException(nameof(configuration.PersonBirthdayFormat));
result = new(
configuration.IgnoreExtensions,
configuration.PersonBirthdayFormat,

View File

@ -1,32 +1,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.Rename.Models;
public class Configuration
{
protected Property.Models.Configuration _PropertyConfiguration;
public string[] IgnoreExtensions { init; get; }
public string PersonBirthdayFormat { init; get; }
public Property.Models.Configuration PropertyConfiguration => _PropertyConfiguration;
[JsonConstructor]
public Configuration(
string[] ignoreExtensions,
string personBirthdayFormat,
Property.Models.Configuration propertyConfiguration)
{
IgnoreExtensions = ignoreExtensions;
PersonBirthdayFormat = personBirthdayFormat;
_PropertyConfiguration = propertyConfiguration;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}
public record Configuration(string[] IgnoreExtensions,
string PersonBirthdayFormat,
Property.Models.Configuration PropertyConfiguration);

View File

@ -47,6 +47,7 @@ public class Rename
_PropertyConfiguration = propertyConfiguration;
_Configuration = configuration;
log.Information(propertyConfiguration.RootDirectory);
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
Verify();
List<string> lines = RenameFilesInDirectories(log);
if (lines.Any())
@ -81,7 +82,6 @@ public class Rename
ProgressBar progressBar;
List<Record> records = new();
const string fileSearchFilter = "*";
int offset = IDirectory.GetOffset();
const bool useCeilingAverage = false;
const string directorySearchFilter = "*";
List<string> distinctDirectories = new();
@ -115,12 +115,12 @@ public class Rename
progressBar = new(files.Length, message, options);
nefPresentCheck = files.Any(l => l.EndsWith(".NEF"));
if (!nefPresentCheck)
records.AddRange(GetRecords(metadata, offset + records.Count, progressBar, files));
records.AddRange(GetRecords(metadata, _PropertyConfiguration.Offset + records.Count, progressBar, files));
else
{
if (!nefPresent)
nefPresent = true;
records.AddRange(GetRecords(metadata, offset + records.Count, progressBar, (from l in files where l.EndsWith(".JPG") select l).ToArray()));
records.AddRange(GetRecords(metadata, _PropertyConfiguration.Offset + records.Count, progressBar, (from l in files where l.EndsWith(".JPG") select l).ToArray()));
}
}
progressBar.Dispose();
@ -226,7 +226,7 @@ public class Rename
bool nameWithoutExtensionIsIdFormat;
bool nameWithoutExtensionIsPaddedIdFormat;
IReadOnlyList<MetadataExtractor.Directory> directories;
int sortOrderOnlyLengthIndex = IDirectory.GetSortOrderOnlyLengthIndex();
int sortOrderOnlyLengthIndex = IDirectory.GetSortOrderOnlyLengthIndex(_PropertyConfiguration.Offset);
for (int i = 0; i < files.Length; i++)
{
progressBar.Tick();