.config
.vscode
BlurHash
BlurHash.Core
BlurHash.System.Drawing.Common
Compare
Container
Copy-Distinct
Models
Binder
.editorconfig
AppSettings.cs
Configuration.cs
AppSettings.cs
Configuration.cs
Copy-Distinct.csproj
CopyDistinct.cs
Program.cs
appsettings.Development.json
appsettings.json
Date-Group
Delete-By-Distinct
Delete-By-Relative
Distance
Drag-Drop-Explorer
Drag-Drop-Move
Drag-Drop-Search
Drag-Drop-Set-Property-Item
Duplicate-Search
Face
FaceParts
FaceRecognitionDotNet
Instance
Map
Metadata
Metadata-Query
Mirror-Length
Move-By-Id
Offset-Date-Time-Original
PhotoPrism
PrepareForOld
Property
Property-Compare
Rename
Resize
Set-Created-Date
Shared
Tests
TestsWithFaceRecognitionDotNet
ThumbHash
.editorconfig
.gitattributes
.gitignore
.prettierignore
.txt
View-by-Distance-MKLink-Console.sln
global.json
package-lock.json
package.json
87 lines
3.5 KiB
C#
87 lines
3.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace View_by_Distance.Copy.Distinct.Models.Binder;
|
|
|
|
public class AppSettings
|
|
{
|
|
|
|
public string? Company { get; set; }
|
|
public bool? CopyDuplicates { get; set; }
|
|
public string? CopyTo { get; set; }
|
|
public bool? IfCanUseId { get; set; }
|
|
public int? MaxDegreeOfParallelism { get; set; }
|
|
public string? ResultDirectoryKey { get; set; }
|
|
public string? WorkingDirectoryName { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
string result = JsonSerializer.Serialize(this, BinderAppSettingsSourceGenerationContext.Default.AppSettings);
|
|
return result;
|
|
}
|
|
|
|
private static void PreVerify(IConfigurationRoot configurationRoot, AppSettings? appSettings)
|
|
{
|
|
if (appSettings?.Company is null)
|
|
{
|
|
List<string> paths = [];
|
|
foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers)
|
|
{
|
|
if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider)
|
|
continue;
|
|
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider)
|
|
continue;
|
|
paths.Add(physicalFileProvider.Root);
|
|
}
|
|
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");
|
|
}
|
|
}
|
|
|
|
private static Models.AppSettings Get(AppSettings? appSettings)
|
|
{
|
|
Models.AppSettings result;
|
|
if (appSettings?.Company is null)
|
|
throw new NullReferenceException(nameof(appSettings.Company));
|
|
if (appSettings?.CopyDuplicates is null)
|
|
throw new NullReferenceException(nameof(appSettings.CopyDuplicates));
|
|
if (appSettings?.CopyTo is null)
|
|
throw new NullReferenceException(nameof(appSettings.CopyTo));
|
|
if (appSettings?.IfCanUseId is null)
|
|
throw new NullReferenceException(nameof(appSettings.IfCanUseId));
|
|
if (appSettings?.MaxDegreeOfParallelism is null)
|
|
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
|
if (appSettings?.ResultDirectoryKey is null)
|
|
throw new NullReferenceException(nameof(appSettings.ResultDirectoryKey));
|
|
if (appSettings?.WorkingDirectoryName is null)
|
|
throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
|
|
result = new(
|
|
appSettings.Company,
|
|
appSettings.CopyDuplicates.Value,
|
|
appSettings.CopyTo,
|
|
appSettings.IfCanUseId.Value,
|
|
appSettings.MaxDegreeOfParallelism.Value,
|
|
appSettings.ResultDirectoryKey,
|
|
appSettings.WorkingDirectoryName
|
|
);
|
|
return result;
|
|
}
|
|
|
|
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
|
{
|
|
Models.AppSettings result;
|
|
#pragma warning disable IL3050, IL2026
|
|
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
|
|
#pragma warning restore IL3050, IL2026
|
|
PreVerify(configurationRoot, appSettings);
|
|
result = Get(appSettings);
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
|
[JsonSerializable(typeof(AppSettings))]
|
|
internal partial class BinderAppSettingsSourceGenerationContext : JsonSerializerContext
|
|
{
|
|
} |