From 738103ad4fca24e4800acd5f89115922de0b8c6b Mon Sep 17 00:00:00 2001 From: mne Date: Thu, 26 May 2022 15:03:29 +0200 Subject: [PATCH] changes from master branch on innovatrics\smartface repo --- .../RegisterWatchlistMembersFromDirCmd.cs | 2 +- ...gisterWatchlistMemberExtendedJsonLoader.cs | 27 ++++++++++++++++++- .../WatchlistMemberRegistrationManager.cs | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/SmartFace.Cli/Commands/SubWatchlistMember/RegisterWatchlistMembersFromDirCmd.cs b/SmartFace.Cli/Commands/SubWatchlistMember/RegisterWatchlistMembersFromDirCmd.cs index 5cffeee..7a7f202 100644 --- a/SmartFace.Cli/Commands/SubWatchlistMember/RegisterWatchlistMembersFromDirCmd.cs +++ b/SmartFace.Cli/Commands/SubWatchlistMember/RegisterWatchlistMembersFromDirCmd.cs @@ -60,7 +60,7 @@ public class RegisterWatchlistMembersFromDirCmd [Option("-p|--parallel", "Max degree of parallelism, default value is 1", CommandOptionType.SingleValue)] public int MaxDegreeOfParallelism { get; set; } = 1; - [Option("--fileNameAs", "Use file name as ID, FullName", CommandOptionType.SingleValue)] + [Option("--fileNameAs", "Use file name as ID or FullName", CommandOptionType.SingleValue)] public string FileNameToProperty { get; set; } = "id"; public RegisterWatchlistMembersFromDirCmd(IWatchlistMemberRegistrationManager registrationManager, ILogger logger) diff --git a/SmartFace.Cli/Core/Domain/WatchlistMember/Impl/RegisterWatchlistMemberExtendedJsonLoader.cs b/SmartFace.Cli/Core/Domain/WatchlistMember/Impl/RegisterWatchlistMemberExtendedJsonLoader.cs index 0e2f3e2..24581cb 100644 --- a/SmartFace.Cli/Core/Domain/WatchlistMember/Impl/RegisterWatchlistMemberExtendedJsonLoader.cs +++ b/SmartFace.Cli/Core/Domain/WatchlistMember/Impl/RegisterWatchlistMemberExtendedJsonLoader.cs @@ -27,7 +27,7 @@ public WatchlistMemberMetadata[] GetWatchlistMemberRegistrationData(string path) { MatchCasing = MatchCasing.CaseInsensitive }); - + if (files.Length == 0) { throw new ProcessingException($"Selected directory does not contain any json file with RegisterWatchlistMemberExtended data [{path}]"); @@ -41,7 +41,32 @@ public WatchlistMemberMetadata[] GetWatchlistMemberRegistrationData(string path) var content = File.ReadAllText(file); var result = JsonConvert.DeserializeObject(content); + + foreach (var metadata in result) + { + metadata.PhotoFiles = metadata.PhotoFiles.Select(s => NormalizePhotoPath(path, s)).ToArray(); + } + return result; } + + private string NormalizePhotoPath(string directory, string photoFile) + { + if (string.IsNullOrEmpty(photoFile)) + { + return photoFile; + } + + if (Path.IsPathRooted(photoFile)) + { + return photoFile; + } + + var normalizedPhotoPath = Path.Combine(directory, photoFile); + + Log.LogInformation($"PhotoFile {photoFile} is relative, normalize to rooted path : {normalizedPhotoPath}"); + + return normalizedPhotoPath; + } } } diff --git a/SmartFace.Cli/Core/Domain/WatchlistMember/Impl/WatchlistMemberRegistrationManager.cs b/SmartFace.Cli/Core/Domain/WatchlistMember/Impl/WatchlistMemberRegistrationManager.cs index d9f4cec..abb7511 100644 --- a/SmartFace.Cli/Core/Domain/WatchlistMember/Impl/WatchlistMemberRegistrationManager.cs +++ b/SmartFace.Cli/Core/Domain/WatchlistMember/Impl/WatchlistMemberRegistrationManager.cs @@ -226,6 +226,7 @@ private IEnumerable BuildWatchlistMemberRegisterDat break; case "name": + case "fullname": watchlistMemberPhotoPaths.Add(new WatchlistMemberPhotoPath() { Name = validFileName, PhotoPath = file }); break; }