Facebook logic, IsDefaultName, GetFiles update and
HardCoded tests
This commit is contained in:
26
Person/.vscode/launch.json
vendored
Normal file
26
Person/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/bin/Debug/net7.0/win-x64/Person.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach"
|
||||
}
|
||||
]
|
||||
}
|
41
Person/.vscode/tasks.json
vendored
Normal file
41
Person/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/Person.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/Person.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"--project",
|
||||
"${workspaceFolder}/Person.csproj"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
32
Person/Models/AppSettings.cs
Normal file
32
Person/Models/AppSettings.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Person.Models;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
public string Company { init; get; }
|
||||
public int MaxDegreeOfParallelism { init; get; }
|
||||
public string SaveDirectory { init; get; }
|
||||
public string WorkingDirectoryName { init; get; }
|
||||
|
||||
[JsonConstructor]
|
||||
public AppSettings(string company,
|
||||
int maxDegreeOfParallelism,
|
||||
string saveDirectory,
|
||||
string workingDirectoryName)
|
||||
{
|
||||
Company = company;
|
||||
MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
SaveDirectory = saveDirectory;
|
||||
WorkingDirectoryName = workingDirectoryName;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
46
Person/Models/Binder/AppSettings.cs
Normal file
46
Person/Models/Binder/AppSettings.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Person.Models.Binder;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
#nullable disable
|
||||
|
||||
public string Company { get; set; }
|
||||
public int? MaxDegreeOfParallelism { get; set; }
|
||||
public string SaveDirectory { get; set; }
|
||||
public string WorkingDirectoryName { get; set; }
|
||||
|
||||
#nullable restore
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Models.AppSettings Get(AppSettings? appSettings)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
if (appSettings?.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
result = new(
|
||||
appSettings.Company,
|
||||
appSettings.MaxDegreeOfParallelism.Value,
|
||||
appSettings.SaveDirectory,
|
||||
appSettings.WorkingDirectoryName
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
|
||||
result = Get(appSettings);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
59
Person/Models/Binder/Configuration.cs
Normal file
59
Person/Models/Binder/Configuration.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Phares.Shared;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Person.Models.Binder;
|
||||
|
||||
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; }
|
||||
|
||||
#nullable restore
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
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));
|
||||
result = new(
|
||||
configuration.IgnoreExtensions,
|
||||
configuration.PersonBirthdayFormat,
|
||||
configuration.PropertyConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Models.Configuration Get(IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, Property.Models.Configuration propertyConfiguration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
Configuration? configuration;
|
||||
if (isEnvironment is null)
|
||||
configuration = configurationRoot.Get<Configuration>();
|
||||
else
|
||||
{
|
||||
string environmentName = IsEnvironment.GetEnvironmentName(isEnvironment);
|
||||
string section = string.Concat(environmentName, ":", nameof(Configuration));
|
||||
IConfigurationSection configurationSection = configurationRoot.GetSection(section);
|
||||
configuration = configurationSection.Get<Configuration>();
|
||||
}
|
||||
result = Get(configuration);
|
||||
result.SetAndUpdate(propertyConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
38
Person/Models/Configuration.cs
Normal file
38
Person/Models/Configuration.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Person.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 void SetAndUpdate(Property.Models.Configuration configuration)
|
||||
{
|
||||
_PropertyConfiguration = configuration;
|
||||
_PropertyConfiguration.Update();
|
||||
}
|
||||
|
||||
}
|
10
Person/Models/Stateless/SerilogExtensionMethods.cs
Normal file
10
Person/Models/Stateless/SerilogExtensionMethods.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Person.Models.Stateless;
|
||||
|
||||
public static class SerilogExtensionMethods
|
||||
{
|
||||
|
||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
||||
|
||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
||||
|
||||
}
|
232
Person/Person.cs
Normal file
232
Person/Person.cs
Normal file
@ -0,0 +1,232 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Phares.Shared;
|
||||
using Serilog;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Person.Models;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
namespace View_by_Distance.Person;
|
||||
|
||||
public class Person
|
||||
{
|
||||
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly string _WorkingDirectory;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
private readonly Configuration _Configuration;
|
||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||
|
||||
public Person(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, Shared.Models.Methods.IConsole console)
|
||||
{
|
||||
if (isSilent)
|
||||
{ }
|
||||
if (console is null)
|
||||
{ }
|
||||
_AppSettings = appSettings;
|
||||
_IsEnvironment = isEnvironment;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
_WorkingDirectory = workingDirectory;
|
||||
_ConfigurationRoot = configurationRoot;
|
||||
ILogger? log = Log.ForContext<Person>();
|
||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_Configuration = configuration;
|
||||
propertyConfiguration.Update();
|
||||
string? comparePathRoot = Path.GetDirectoryName(appSettings.SaveDirectory);
|
||||
if (comparePathRoot is null || comparePathRoot == propertyConfiguration.RootDirectory)
|
||||
throw new Exception("Nested isn't allowed!");
|
||||
if (!Directory.Exists(appSettings.SaveDirectory))
|
||||
_ = Directory.CreateDirectory(appSettings.SaveDirectory);
|
||||
log.Information(propertyConfiguration.RootDirectory);
|
||||
Verify();
|
||||
Loop(ticks, log);
|
||||
}
|
||||
|
||||
private void Verify()
|
||||
{
|
||||
if (_AppSettings is null)
|
||||
{ }
|
||||
if (_IsEnvironment is null)
|
||||
{ }
|
||||
if (_Configuration is null)
|
||||
{ }
|
||||
if (_ConfigurationRoot is null)
|
||||
{ }
|
||||
if (_WorkingDirectory is null)
|
||||
{ }
|
||||
if (_PropertyConfiguration is null)
|
||||
{ }
|
||||
}
|
||||
|
||||
private void Loop(long ticks, ILogger log)
|
||||
{
|
||||
int age;
|
||||
string json;
|
||||
string code;
|
||||
string? day;
|
||||
string alias;
|
||||
string? line;
|
||||
string? year;
|
||||
string? month;
|
||||
bool deceased;
|
||||
ConsoleKey sex;
|
||||
long personKey;
|
||||
string? lastName;
|
||||
string middleName;
|
||||
string? firstName;
|
||||
DateTime? dateTime;
|
||||
PersonName personName;
|
||||
string checkDirectory;
|
||||
ConsoleKey? consoleKey;
|
||||
string? approximateYears;
|
||||
string personKeyFormatted;
|
||||
string personDisplayDirectory;
|
||||
log.Information($"Ready to create / update a person? [{ticks}]");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
log.Information("Press \"Y\" key to continue, \"N\" key exit or close console");
|
||||
consoleKey = System.Console.ReadKey().Key;
|
||||
log.Information(". . .");
|
||||
if (consoleKey is not ConsoleKey.Y and not ConsoleKey.N)
|
||||
break;
|
||||
firstName = null;
|
||||
for (int f = 0; f < 5; f++)
|
||||
{
|
||||
log.Information("Enter persons first name (minimum length of two characters)");
|
||||
line = System.Console.ReadLine();
|
||||
log.Information(". . .");
|
||||
if (string.IsNullOrEmpty(line) || line.Length < 2)
|
||||
continue;
|
||||
firstName = line;
|
||||
break;
|
||||
}
|
||||
if (firstName is null)
|
||||
continue;
|
||||
lastName = null;
|
||||
for (int f = 0; f < 5; f++)
|
||||
{
|
||||
log.Information("Enter persons last name (minimum length of two characters)");
|
||||
line = System.Console.ReadLine();
|
||||
log.Information(". . .");
|
||||
if (string.IsNullOrEmpty(line) || line.Length < 2)
|
||||
continue;
|
||||
lastName = line;
|
||||
break;
|
||||
}
|
||||
if (lastName is null)
|
||||
continue;
|
||||
log.Information("Enter persons middle name (press enter if they don't have a middle name)");
|
||||
line = System.Console.ReadLine();
|
||||
log.Information(". . .");
|
||||
middleName = string.IsNullOrEmpty(line) ? string.Empty : line;
|
||||
log.Information("Enter persons alias (press enter if they don't have a alias)");
|
||||
line = System.Console.ReadLine();
|
||||
log.Information(". . .");
|
||||
alias = string.IsNullOrEmpty(line) ? string.Empty : line;
|
||||
personName = new(new(firstName), new(middleName), new(lastName), new(alias));
|
||||
json = JsonSerializer.Serialize(personName, new JsonSerializerOptions { WriteIndented = true });
|
||||
log.Information("Is the person \"M\" (Male), \"F\" (Female) or \"U\" (Unknown)");
|
||||
consoleKey = System.Console.ReadKey().Key;
|
||||
log.Information(". . .");
|
||||
if (consoleKey is not ConsoleKey.M and not ConsoleKey.F and not ConsoleKey.U)
|
||||
continue;
|
||||
sex = consoleKey.Value;
|
||||
log.Information("Is the person deceased \"Y\" or \"N\"");
|
||||
consoleKey = System.Console.ReadKey().Key;
|
||||
log.Information(". . .");
|
||||
if (consoleKey is not ConsoleKey.Y and not ConsoleKey.N)
|
||||
continue;
|
||||
deceased = consoleKey == ConsoleKey.Y;
|
||||
dateTime = null;
|
||||
approximateYears = null;
|
||||
for (int f = 0; f < 5; f++)
|
||||
{
|
||||
day = null;
|
||||
year = null;
|
||||
month = null;
|
||||
approximateYears = null;
|
||||
log.Information("Enter persons birthday month (press enter if not known) [MMMM || MMM || MM || M]");
|
||||
line = System.Console.ReadLine();
|
||||
log.Information(". . .");
|
||||
if (!string.IsNullOrEmpty(line))
|
||||
month = line;
|
||||
else
|
||||
{
|
||||
log.Information("Enter persons approximate age");
|
||||
line = System.Console.ReadLine();
|
||||
log.Information(". . .");
|
||||
if (string.IsNullOrEmpty(line) || !int.TryParse(line, out _))
|
||||
continue;
|
||||
approximateYears = line;
|
||||
}
|
||||
log.Information("Enter persons birthday day (press enter if not known)");
|
||||
line = System.Console.ReadLine();
|
||||
log.Information(". . .");
|
||||
if (!string.IsNullOrEmpty(line))
|
||||
day = line;
|
||||
else
|
||||
{
|
||||
log.Information("Enter persons approximate age");
|
||||
line = System.Console.ReadLine();
|
||||
log.Information(". . .");
|
||||
if (string.IsNullOrEmpty(line) || !int.TryParse(line, out _))
|
||||
continue;
|
||||
approximateYears = line;
|
||||
}
|
||||
log.Information("Enter persons birthday year (press enter if not known)");
|
||||
line = System.Console.ReadLine();
|
||||
log.Information(". . .");
|
||||
if (!string.IsNullOrEmpty(line))
|
||||
year = line;
|
||||
else
|
||||
{
|
||||
log.Information("Enter persons approximate age");
|
||||
line = System.Console.ReadLine();
|
||||
log.Information(". . .");
|
||||
if (string.IsNullOrEmpty(line) || !int.TryParse(line, out _))
|
||||
continue;
|
||||
approximateYears = line;
|
||||
}
|
||||
if (month is null || day is null || year is null)
|
||||
dateTime = null;
|
||||
else
|
||||
{
|
||||
dateTime = IPersonBirthday.GetDate(month, day, year);
|
||||
if (dateTime is not null)
|
||||
{
|
||||
(age, _) = IAge.GetAge(new DateTime(ticks).Ticks, dateTime.Value);
|
||||
approximateYears = age.ToString();
|
||||
}
|
||||
}
|
||||
if (approximateYears is null && (dateTime is null || dateTime == DateTime.MinValue))
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
if (approximateYears is null)
|
||||
continue;
|
||||
personDisplayDirectory = Path.Combine(_AppSettings.SaveDirectory, ticks.ToString(), $"{personName.First.Value} {personName.Last.Value}~{approximateYears}");
|
||||
if (!Directory.Exists(personDisplayDirectory))
|
||||
_ = Directory.CreateDirectory(personDisplayDirectory);
|
||||
if (dateTime is null)
|
||||
personKeyFormatted = "2";
|
||||
else
|
||||
{
|
||||
personKey = dateTime.Value.Ticks;
|
||||
if (deceased)
|
||||
code = sex is ConsoleKey.M ? "05" : sex is ConsoleKey.F ? "04" : sex is ConsoleKey.U ? "02" : throw new NotImplementedException();
|
||||
else
|
||||
code = sex is ConsoleKey.M ? "15" : sex is ConsoleKey.F ? "14" : sex is ConsoleKey.U ? "03" : throw new NotImplementedException();
|
||||
personKeyFormatted = $"{IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, personKey)[..^2]}{code}";
|
||||
}
|
||||
checkDirectory = Path.Combine(personDisplayDirectory, personKeyFormatted);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
_ = IPath.WriteAllText(Path.Combine(checkDirectory, $"{personKeyFormatted}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
log.Information(". . .");
|
||||
}
|
||||
|
||||
}
|
59
Person/Person.csproj
Normal file
59
Person/Person.csproj
Normal file
@ -0,0 +1,59 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<UserSecretsId>7ca5318a-9332-4217-b9d8-cae696629934</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Person</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>7.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
|
||||
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
|
||||
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsWindows)'=='true'">
|
||||
<DefineConstants>Windows</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsOSX)'=='true'">
|
||||
<DefineConstants>OSX</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsLinux)'=='true'">
|
||||
<DefineConstants>Linux</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'browser-wasm'">
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
70
Person/Program.cs
Normal file
70
Person/Program.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Phares.Shared;
|
||||
using Serilog;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using View_by_Distance.Person.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
namespace View_by_Distance.Person;
|
||||
|
||||
public class Program
|
||||
{
|
||||
|
||||
public static void Secondary(List<string> args)
|
||||
{
|
||||
LoggerConfiguration loggerConfiguration = new();
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true);
|
||||
IConfigurationRoot configurationRoot = configurationBuilder.Build();
|
||||
AppSettings appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (appSettings.MaxDegreeOfParallelism > Environment.ProcessorCount)
|
||||
throw new Exception("MaxDegreeOfParallelism must be =< Environment.ProcessorCount!");
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
throw new Exception("Working directory name must have a value!");
|
||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
||||
Log.Logger = loggerConfiguration.CreateLogger();
|
||||
ILogger log = Log.ForContext<Program>();
|
||||
int silentIndex = args.IndexOf("s");
|
||||
if (silentIndex > -1)
|
||||
args.RemoveAt(silentIndex);
|
||||
try
|
||||
{
|
||||
if (args is null)
|
||||
throw new Exception("args is null!");
|
||||
Shared.Models.Console console = new();
|
||||
_ = new Person(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
if (silentIndex > -1)
|
||||
log.Debug("Done. Bye");
|
||||
else
|
||||
{
|
||||
log.Debug("Done. Press 'Enter' to end");
|
||||
_ = Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
if (args is not null)
|
||||
Secondary(args.ToList());
|
||||
else
|
||||
Secondary(new List<string>());
|
||||
}
|
||||
|
||||
}
|
17
Person/appsettings.Development.json
Normal file
17
Person/appsettings.Development.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Log4netProvider": "Debug"
|
||||
}
|
||||
},
|
||||
"MaxDegreeOfParallelism": 6,
|
||||
"Serilog": {
|
||||
"MinimumLevel": "Debug"
|
||||
},
|
||||
"Windows": {
|
||||
"Configuration": {
|
||||
"RootDirectory": "C:/",
|
||||
"VerifyToSeason": []
|
||||
}
|
||||
}
|
||||
}
|
120
Person/appsettings.json
Normal file
120
Person/appsettings.json
Normal file
@ -0,0 +1,120 @@
|
||||
{
|
||||
"Company": "Mike Phares",
|
||||
"Linux": {},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Log4netProvider": "Debug",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"MaxDegreeOfParallelism": 6,
|
||||
"SaveDirectory": "~/",
|
||||
"Serilog": {
|
||||
"Using": [
|
||||
"Serilog.Sinks.Console",
|
||||
"Serilog.Sinks.File"
|
||||
],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Debug",
|
||||
"Args": {
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Console",
|
||||
"Args": {
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "%workingDirectory% - Log/log-.txt",
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{MethodName}) ({InstanceId}) ({RemoteIpAddress}) {Message}{NewLine}{Exception}",
|
||||
"rollingInterval": "Hour"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [
|
||||
"FromLogContext",
|
||||
"WithMachineName",
|
||||
"WithThreadId"
|
||||
],
|
||||
"Properties": {
|
||||
"Application": "Sample"
|
||||
}
|
||||
},
|
||||
"Windows": {
|
||||
"Configuration": {
|
||||
"DateGroup": "9b89679",
|
||||
"DiffPropertyDirectory": "",
|
||||
"FileNameDirectorySeparator": ".Z.",
|
||||
"ForcePropertyLastWriteTimeToCreationTime": false,
|
||||
"MaxImagesInDirectoryForTopLevelFirstPass": 10,
|
||||
"OutputExtension": ".jpg",
|
||||
"Pattern": "[^ABCDEFGHIJKLMNOPQRSTUVWXYZbcdfghjklmnpqrstvwxyz0-9]",
|
||||
"PersonBirthdayFormat": "yyyy-MM-dd_HH",
|
||||
"PopulatePropertyId": true,
|
||||
"PropertiesChangedForProperty": false,
|
||||
"ResultAllInOne": "_ _ _",
|
||||
"ResultCollection": "[]",
|
||||
"ResultContent": "()",
|
||||
"ResultSingleton": "{}",
|
||||
"RootDirectory": "C:/Tmp/Phares/Compare/Images-9b89679",
|
||||
"WriteBitmapDataBytes": false,
|
||||
"IgnoreExtensions": [
|
||||
".gif",
|
||||
".GIF",
|
||||
".pdf",
|
||||
".PDF"
|
||||
],
|
||||
"ValidImageFormatExtensions": [
|
||||
".bmp",
|
||||
".BMP",
|
||||
".gif",
|
||||
".GIF",
|
||||
".jpeg",
|
||||
".JPEG",
|
||||
".jpg",
|
||||
".JPG",
|
||||
".png",
|
||||
".PNG",
|
||||
".tiff",
|
||||
".TIFF"
|
||||
],
|
||||
"ValidMetadataExtensions": [
|
||||
".3gp",
|
||||
".3GP",
|
||||
".avi",
|
||||
".AVI",
|
||||
".bmp",
|
||||
".BMP",
|
||||
".gif",
|
||||
".GIF",
|
||||
".ico",
|
||||
".ICO",
|
||||
".jpeg",
|
||||
".JPEG",
|
||||
".jpg",
|
||||
".JPG",
|
||||
".m4v",
|
||||
".M4V",
|
||||
".mov",
|
||||
".MOV",
|
||||
".mp4",
|
||||
".MP4",
|
||||
".mta",
|
||||
".MTA",
|
||||
".png",
|
||||
".PNG",
|
||||
".tiff",
|
||||
".TIFF"
|
||||
]
|
||||
}
|
||||
},
|
||||
"WorkingDirectoryName": "PharesApps"
|
||||
}
|
Reference in New Issue
Block a user