AddUserSecrets, RenameByDateTaken and BlurHash
This commit is contained in:
@ -2,7 +2,9 @@
|
||||
using Phares.Shared;
|
||||
using ShellProgressBar;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using View_by_Distance.Distance.Models;
|
||||
using View_by_Distance.Face.Models;
|
||||
@ -30,6 +32,7 @@ public partial class DlibDotNet
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
private readonly D2_FaceParts _FaceParts;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly IBlurHasher _IBlurHasher;
|
||||
private readonly List<string> _Exceptions;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
private readonly bool _PropertyRootExistedBefore;
|
||||
@ -56,6 +59,7 @@ public partial class DlibDotNet
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
_Exceptions = new List<string>();
|
||||
_Log = Serilog.Log.ForContext<DlibDotNet>();
|
||||
_IBlurHasher = new BlurHash.Models.BlurHasher();
|
||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||
Models.Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||
_Log.Information(propertyConfiguration.RootDirectory);
|
||||
@ -367,12 +371,37 @@ public partial class DlibDotNet
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
List<Shared.Models.Face> faces;
|
||||
Shared.Models.Property property;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
Shared.Models.Property? property;
|
||||
List<string> parseExceptions = new();
|
||||
List<Tuple<string, DateTime>> subFileTuples = new();
|
||||
List<KeyValuePair<string, string>> metadataCollection;
|
||||
if (item.Property is not null && item.Property.Id is not null && !item.Any() && item.Property.BlurHash is null)
|
||||
{
|
||||
(string aResultsFullGroupDirectory, _) = GetResultsFullGroupDirectories();
|
||||
string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, "{}");
|
||||
string[] files = Directory.GetFiles(aPropertySingletonDirectory, $"{item.Property.Id.Value}*", SearchOption.AllDirectories);
|
||||
if (files.Length == 1)
|
||||
{
|
||||
string matchFile = files.First();
|
||||
string json = File.ReadAllText(matchFile);
|
||||
string find = "\"CreationTime\":";
|
||||
if (!json.Contains(find))
|
||||
throw new NotImplementedException();
|
||||
#pragma warning disable CA1416
|
||||
using Image image = Image.FromFile(item.ImageFileHolder.FullName);
|
||||
#pragma warning restore CA1416
|
||||
string blurHash = _IBlurHasher.Encode(image);
|
||||
json = json.Replace(find, $"\"{nameof(item.Property.BlurHash)}\": \"{blurHash}\", {find}");
|
||||
property = JsonSerializer.Deserialize<Shared.Models.Property>(json);
|
||||
if (property is null || property.BlurHash is null)
|
||||
throw new NullReferenceException(nameof(property));
|
||||
json = JsonSerializer.Serialize(property, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(matchFile, json);
|
||||
File.SetLastWriteTime(matchFile, item.Property.LastWriteTime);
|
||||
}
|
||||
}
|
||||
if (item.Property is not null && item.Property.Id is not null && !item.Any())
|
||||
{
|
||||
property = item.Property;
|
||||
@ -398,7 +427,7 @@ public partial class DlibDotNet
|
||||
_Log.Information(string.Concat("LastWriteTimeChanged <", item.ImageFileHolder.FullName, '>'));
|
||||
else if (item.Moved.HasValue && item.Moved.Value)
|
||||
_Log.Information(string.Concat("Moved <", item.ImageFileHolder.FullName, '>'));
|
||||
property = propertyLogic.GetProperty(item, subFileTuples, parseExceptions);
|
||||
property = propertyLogic.GetProperty(_IBlurHasher, item, subFileTuples, parseExceptions);
|
||||
item.Update(property);
|
||||
if (propertyHashCode is null)
|
||||
{
|
||||
@ -1134,7 +1163,7 @@ public partial class DlibDotNet
|
||||
List<Shared.Models.Face> distinctFilteredFaces = Map.Models.Stateless.Methods.IMapLogic.GetFaces(distinctFilteredItems);
|
||||
Mapping[] distinctFilteredMappingCollection = GetMappings(_Configuration.PropertyConfiguration, containers, mapLogic, distinctItems: true);
|
||||
int totalNotMapped = mapLogic.UpdateMappingFromPerson(distinctFilteredMappingCollection);
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(distinctFilteredMappingCollection);
|
||||
string json = JsonSerializer.Serialize(distinctFilteredMappingCollection);
|
||||
File.WriteAllText(Path.Combine(eDistanceContentDirectory, $"{ticks}.json"), json);
|
||||
for (int i = 1; i < 5; i++)
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(eDistanceContentDirectory);
|
||||
|
@ -40,8 +40,8 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||
<PackageReference Include="MetadataExtractor" Version="2.7.2" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.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" />
|
||||
@ -49,6 +49,7 @@
|
||||
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BlurHash\BlurHash.csproj" />
|
||||
<ProjectReference Include="..\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" />
|
||||
<ProjectReference Include="..\Distance\Distance.csproj" />
|
||||
<ProjectReference Include="..\Face\Face.csproj" />
|
||||
|
@ -19,7 +19,8 @@ public class Program
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true);
|
||||
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true)
|
||||
.AddUserSecrets<Program>();
|
||||
IConfigurationRoot configurationRoot = configurationBuilder.Build();
|
||||
AppSettings appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (appSettings.MaxDegreeOfParallelism > Environment.ProcessorCount)
|
||||
|
Reference in New Issue
Block a user