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

@ -3,25 +3,21 @@ using System.Text.Json.Serialization;
namespace View_by_Distance.Date.Group.Models;
public class AppSettings
public record AppSettings(string Company,
int MaxDegreeOfParallelism,
string WorkingDirectoryName)
{
public string Company { init; get; }
public int MaxDegreeOfParallelism { init; get; }
public string WorkingDirectoryName { init; get; }
[JsonConstructor]
public AppSettings(string company, int maxDegreeOfParallelism, string workingDirectoryName)
{
Company = company;
MaxDegreeOfParallelism = maxDegreeOfParallelism;
WorkingDirectoryName = workingDirectoryName;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
string result = JsonSerializer.Serialize(this, AppSettingsSourceGenerationContext.Default.AppSettings);
return result;
}
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(AppSettings))]
internal partial class AppSettingsSourceGenerationContext : JsonSerializerContext
{
}

View File

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

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.Date.Group.Models.Binder;
@ -10,13 +9,13 @@ public class Configuration
#nullable disable
[Display(Name = "By Create Date Shortcut"), Required] public bool? ByCreateDateShortcut { get; set; }
[Display(Name = "By Date"), Required] public bool? ByDay { get; set; }
[Display(Name = "By Hash"), Required] public bool? ByHash { get; set; }
[Display(Name = "By Season"), Required] public bool? BySeason { get; set; }
[Display(Name = "By Week"), Required] public bool? ByWeek { get; set; }
[Display(Name = "Ignore Subdirectories for Rename"), Required] public bool? KeepFullPath { get; set; }
[Display(Name = "Property Configuration"), Required] public Property.Models.Configuration PropertyConfiguration { get; set; }
public bool? ByCreateDateShortcut { get; set; }
public bool? ByDay { get; set; }
public bool? ByHash { get; set; }
public bool? BySeason { get; set; }
public bool? ByWeek { get; set; }
public bool? KeepFullPath { get; set; }
public Property.Models.Configuration PropertyConfiguration { get; set; }
#nullable restore
@ -29,20 +28,13 @@ public class Configuration
private static Models.Configuration Get(Configuration? configuration)
{
Models.Configuration result;
if (configuration is null)
throw new NullReferenceException(nameof(configuration));
if (configuration.ByCreateDateShortcut is null)
throw new NullReferenceException(nameof(configuration.ByCreateDateShortcut));
if (configuration.ByDay is null)
throw new NullReferenceException(nameof(configuration.ByDay));
if (configuration.ByHash is null)
throw new NullReferenceException(nameof(configuration.ByHash));
if (configuration.BySeason is null)
throw new NullReferenceException(nameof(configuration.BySeason));
if (configuration.ByWeek is null)
throw new NullReferenceException(nameof(configuration.ByWeek));
if (configuration.KeepFullPath is null)
throw new NullReferenceException(nameof(configuration.KeepFullPath));
if (configuration is null) throw new NullReferenceException(nameof(configuration));
if (configuration.ByCreateDateShortcut is null) throw new NullReferenceException(nameof(configuration.ByCreateDateShortcut));
if (configuration.ByDay is null) throw new NullReferenceException(nameof(configuration.ByDay));
if (configuration.ByHash is null) throw new NullReferenceException(nameof(configuration.ByHash));
if (configuration.BySeason is null) throw new NullReferenceException(nameof(configuration.BySeason));
if (configuration.ByWeek is null) throw new NullReferenceException(nameof(configuration.ByWeek));
if (configuration.KeepFullPath is null) throw new NullReferenceException(nameof(configuration.KeepFullPath));
result = new(
configuration.PropertyConfiguration,
configuration.ByCreateDateShortcut.Value,
@ -68,8 +60,7 @@ public class Configuration
configuration = configurationSection.Get<Configuration>();
}
result = Get(configuration);
if (configuration is null)
throw new NullReferenceException(nameof(configuration));
if (configuration is null) throw new NullReferenceException(nameof(configuration));
return result;
}