Set-Created-Date
This commit is contained in:
parent
5996ec2a5a
commit
dd514b8873
17
.vscode/launch.json
vendored
17
.vscode/launch.json
vendored
@ -258,6 +258,23 @@
|
||||
"console": "externalTerminal",
|
||||
"stopAtEntry": false,
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": "Set-Created-Date",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Set-Created-Date/bin/Debug/net7.0/win-x64/Set-Created-Date.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "externalTerminal",
|
||||
"stopAtEntry": false,
|
||||
"requireExactSource": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
<UserSecretsId>d862524f-2b48-4f47-b4c3-5a8615814ec2</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Rename</PackageId>
|
||||
<PackageId>Phares.View.by.Distance.Copy.Distinct</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>7.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
@ -45,9 +45,7 @@
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
<ProjectReference Include="..\Resize\Resize.csproj" />
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -8,6 +8,11 @@ public interface IMetadata
|
||||
static DateTime? GetMinimumDateTime(IReadOnlyList<MetadataExtractor.Directory> directories) =>
|
||||
Metadata.GetMinimumDateTime(directories);
|
||||
|
||||
DateTime? TestStatic_GetMinimumDateTime(IReadOnlyList<MetadataExtractor.Directory> directories, Shared.Models.FileHolder fileHolder) =>
|
||||
GetMinimumDateTime(directories, fileHolder);
|
||||
static DateTime? GetMinimumDateTime(IReadOnlyList<MetadataExtractor.Directory> directories, Shared.Models.FileHolder fileHolder) =>
|
||||
Metadata.GetMinimumDateTime(directories, fileHolder);
|
||||
|
||||
string? TestStatic_GetModel(IReadOnlyList<MetadataExtractor.Directory> directories) =>
|
||||
GetModel(directories);
|
||||
static string? GetModel(IReadOnlyList<MetadataExtractor.Directory> directories) =>
|
||||
|
@ -93,6 +93,15 @@ internal class Metadata
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static DateTime? GetMinimumDateTime(IReadOnlyList<MetadataExtractor.Directory> directories, Shared.Models.FileHolder fileHolder)
|
||||
{
|
||||
DateTime? result;
|
||||
DateTime? dateTime = GetMinimumDateTime(directories);
|
||||
List<DateTime?> results = new() { fileHolder.CreationTime, fileHolder.LastWriteTime, dateTime };
|
||||
result = results.Min();
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string? GetModel(IReadOnlyList<MetadataExtractor.Directory> directories)
|
||||
{
|
||||
string? result;
|
||||
|
@ -128,7 +128,7 @@ public class MoveById
|
||||
if (nameWithoutExtensionIsIdFormat)
|
||||
continue;
|
||||
}
|
||||
(_, dateTimes, id, message) = Shared.Models.Stateless.Methods.IProperty.Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension);
|
||||
(_, dateTimes, id, message) = Shared.Models.Stateless.Methods.IProperty.Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension, _PropertyConfiguration.PopulatePropertyId);
|
||||
if (id is null)
|
||||
continue;
|
||||
matches = (from l in allFiles where l.Contains($"{id}{fileHolder.ExtensionLowered}") select l).ToArray();
|
||||
|
@ -281,7 +281,7 @@ public class Rename
|
||||
}
|
||||
}
|
||||
dateTimeFromName = Shared.Models.Stateless.Methods.IProperty.GetDateTimeFromName(fileHolder);
|
||||
(dateTimeOriginal, dateTimes, id, message) = Shared.Models.Stateless.Methods.IProperty.Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension);
|
||||
(dateTimeOriginal, dateTimes, id, message) = Shared.Models.Stateless.Methods.IProperty.Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension, _PropertyConfiguration.PopulatePropertyId);
|
||||
minimumDateTime = dateTimes.Min();
|
||||
if (minimumDateTime is null)
|
||||
break;
|
||||
|
32
Set-Created-Date/Models/AppSettings.cs
Normal file
32
Set-Created-Date/Models/AppSettings.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Set.Created.Date.Models;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
public string Company { init; get; }
|
||||
public string CopyTo { init; get; }
|
||||
public int MaxDegreeOfParallelism { init; get; }
|
||||
public string WorkingDirectoryName { init; get; }
|
||||
|
||||
[JsonConstructor]
|
||||
public AppSettings(string company,
|
||||
string copyTo,
|
||||
int maxDegreeOfParallelism,
|
||||
string workingDirectoryName)
|
||||
{
|
||||
Company = company;
|
||||
CopyTo = copyTo;
|
||||
MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
WorkingDirectoryName = workingDirectoryName;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
46
Set-Created-Date/Models/Binder/AppSettings.cs
Normal file
46
Set-Created-Date/Models/Binder/AppSettings.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Set.Created.Date.Models.Binder;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
#nullable disable
|
||||
|
||||
public string Company { get; set; }
|
||||
public int? MaxDegreeOfParallelism { get; set; }
|
||||
public string CopyTo { 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.CopyTo,
|
||||
appSettings.MaxDegreeOfParallelism.Value,
|
||||
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
Set-Created-Date/Models/Binder/Configuration.cs
Normal file
59
Set-Created-Date/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.Set.Created.Date.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
Set-Created-Date/Models/Configuration.cs
Normal file
38
Set-Created-Date/Models/Configuration.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Set.Created.Date.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
Set-Created-Date/Models/Stateless/SerilogExtensionMethods.cs
Normal file
10
Set-Created-Date/Models/Stateless/SerilogExtensionMethods.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Set.Created.Date.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);
|
||||
|
||||
}
|
71
Set-Created-Date/Program.cs
Normal file
71
Set-Created-Date/Program.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Phares.Shared;
|
||||
using Serilog;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using View_by_Distance.Set.Created.Date.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
namespace View_by_Distance.Set.Created.Date;
|
||||
|
||||
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)
|
||||
.AddUserSecrets<Program>();
|
||||
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 SetCreatedDate(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>());
|
||||
}
|
||||
|
||||
}
|
59
Set-Created-Date/Set-Created-Date.csproj
Normal file
59
Set-Created-Date/Set-Created-Date.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>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<UserSecretsId>b3bbcc69-1439-4e86-9bbf-75c8e8839cc0</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Set.Created.Date</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="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" />
|
||||
</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>
|
165
Set-Created-Date/SetCreatedDate.cs
Normal file
165
Set-Created-Date/SetCreatedDate.cs
Normal file
@ -0,0 +1,165 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Phares.Shared;
|
||||
using Serilog;
|
||||
using ShellProgressBar;
|
||||
using View_by_Distance.Set.Created.Date.Models;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Set.Created.Date;
|
||||
|
||||
public class SetCreatedDate
|
||||
{
|
||||
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly string _WorkingDirectory;
|
||||
private readonly Configuration _Configuration;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||
private readonly IReadOnlyDictionary<string, string[]> _FileGroups;
|
||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||
|
||||
public SetCreatedDate(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||
{
|
||||
if (isSilent)
|
||||
{ }
|
||||
if (console is null)
|
||||
{ }
|
||||
_AppSettings = appSettings;
|
||||
_IsEnvironment = isEnvironment;
|
||||
_WorkingDirectory = workingDirectory;
|
||||
_ConfigurationRoot = configurationRoot;
|
||||
ILogger? log = Log.ForContext<SetCreatedDate>();
|
||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||
string[] directories = new string[] { propertyConfiguration.ResultContent };
|
||||
_FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, appSettings.CopyTo, directories);
|
||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_Configuration = configuration;
|
||||
propertyConfiguration.Update();
|
||||
log.Information(propertyConfiguration.RootDirectory);
|
||||
Verify();
|
||||
List<string> lines = SetCreatedDateFilesInDirectories(log);
|
||||
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
||||
if (!lines.Any())
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
}
|
||||
|
||||
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 static (List<string>, List<string>) Get(List<string[]> filesCollection)
|
||||
{
|
||||
List<string> results = new();
|
||||
string? directory;
|
||||
List<string> directories = new();
|
||||
foreach (string[] files in filesCollection)
|
||||
{
|
||||
if (!files.Any())
|
||||
continue;
|
||||
directory = Path.GetDirectoryName(files.First());
|
||||
if (directory is null)
|
||||
continue;
|
||||
if (!directories.Contains(directory))
|
||||
directories.Add(directory);
|
||||
results.AddRange(files);
|
||||
}
|
||||
return (directories, results);
|
||||
}
|
||||
|
||||
private List<(FileHolder, DateTime)> GetToDoCollection(ProgressBar progressBar, FileHolder[] fileHolders)
|
||||
{
|
||||
List<(FileHolder, DateTime)> results = new();
|
||||
int? id;
|
||||
string? message;
|
||||
DateTime? dateTime;
|
||||
DateTime?[] dateTimes;
|
||||
bool isIgnoreExtension;
|
||||
DateTime? dateTimeOriginal;
|
||||
bool isValidImageFormatExtension;
|
||||
foreach (FileHolder fileHolder in fileHolders)
|
||||
{
|
||||
progressBar.Tick();
|
||||
if (fileHolder.ExtensionLowered == ".id" || fileHolder.ExtensionLowered == ".lsv" || fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
if (_PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered))
|
||||
continue;
|
||||
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
isIgnoreExtension = isValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
if (isIgnoreExtension || !isValidImageFormatExtension)
|
||||
continue;
|
||||
(dateTimeOriginal, dateTimes, id, message) = Shared.Models.Stateless.Methods.IProperty.Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension, _PropertyConfiguration.PopulatePropertyId);
|
||||
dateTime = dateTimeOriginal is not null ? dateTimeOriginal : dateTime = dateTimes.Min();
|
||||
if (dateTime is null)
|
||||
continue;
|
||||
if (dateTime.Value == fileHolder.CreationTime)
|
||||
continue;
|
||||
results.Add((fileHolder, dateTime.Value));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<string> SetCreatedDateForeach(ProgressBar progressBar, List<(FileHolder, DateTime)> toDoCollection)
|
||||
{
|
||||
List<string> results = new();
|
||||
foreach ((FileHolder fileHolder, DateTime dateTime) in toDoCollection)
|
||||
{
|
||||
progressBar.Tick();
|
||||
results.Add(fileHolder.NameWithoutExtension);
|
||||
try
|
||||
{ File.SetCreationTime(fileHolder.FullName, dateTime); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<string> SetCreatedDateFilesInDirectories(ILogger log)
|
||||
{
|
||||
List<string> results = new();
|
||||
ProgressBar progressBar;
|
||||
ConsoleKey? consoleKey = null;
|
||||
const string fileSearchFilter = "*";
|
||||
string message = nameof(SetCreatedDate);
|
||||
const string directorySearchFilter = "*";
|
||||
List<string[]> filesCollection = Shared.Models.Stateless.Methods.IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter);
|
||||
(_, List<string> allFiles) = Get(filesCollection);
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
progressBar = new(allFiles.Count, message, options);
|
||||
FileHolder[] fileHolders = (from l in allFiles select new FileHolder(l)).ToArray();
|
||||
List<(FileHolder, DateTime)> toDoCollection = GetToDoCollection(progressBar, fileHolders);
|
||||
progressBar.Dispose();
|
||||
log.Information($"Ready to set created date {toDoCollection.Count} file(s)?");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
log.Information("Press \"Y\" key to set created date file(s), \"N\" key to log file(s) or close console to not set created date files");
|
||||
consoleKey = System.Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||
break;
|
||||
}
|
||||
log.Information(". . .");
|
||||
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
||||
log.Information("Nothing set!");
|
||||
else
|
||||
{
|
||||
progressBar = new(allFiles.Count, message, options);
|
||||
results.AddRange(SetCreatedDateForeach(progressBar, toDoCollection));
|
||||
progressBar.Dispose();
|
||||
log.Information("Done setting created date");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
10
Set-Created-Date/appsettings.Development.json
Normal file
10
Set-Created-Date/appsettings.Development.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Log4netProvider": "Debug"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": "Debug"
|
||||
}
|
||||
}
|
128
Set-Created-Date/appsettings.json
Normal file
128
Set-Created-Date/appsettings.json
Normal file
@ -0,0 +1,128 @@
|
||||
{
|
||||
"ComparePathsFile": "",
|
||||
"Company": "Mike Phares",
|
||||
"CopyTo": "",
|
||||
"Linux": {},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Log4netProvider": "Debug",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"MaxDegreeOfParallelism": 6,
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"WorkingDirectoryName": "PharesApps",
|
||||
"Windows": {
|
||||
"Configuration": {
|
||||
"DateGroup": "1e85c0ba",
|
||||
"DiffPropertyDirectory": "",
|
||||
"FileNameDirectorySeparator": ".Z.",
|
||||
"ForcePropertyLastWriteTimeToCreationTime": false,
|
||||
"MaxImagesInDirectoryForTopLevelFirstPass": 10,
|
||||
"OutputExtension": ".jpg",
|
||||
"Pattern": "[^ABCDEFGHIJKLMNOPQRSTUVWXYZbcdfghjklmnpqrstvwxyz0-9]",
|
||||
"PersonBirthdayFormat": "yyyy-MM-dd_HH",
|
||||
"PopulatePropertyId": true,
|
||||
"PropertiesChangedForProperty": false,
|
||||
"ResultAllInOne": "_ _ _",
|
||||
"ResultAllInOneSubdirectoryLength": 2,
|
||||
"ResultCollection": "[]",
|
||||
"ResultContent": "()",
|
||||
"ResultSingleton": "{}",
|
||||
"RootDirectory": "D:/Images",
|
||||
"WriteBitmapDataBytes": false,
|
||||
"IgnoreExtensions": [
|
||||
".gif",
|
||||
".GIF",
|
||||
".nef",
|
||||
".NEF",
|
||||
".pdf",
|
||||
".PDF"
|
||||
],
|
||||
"ValidImageFormatExtensions": [
|
||||
".bmp",
|
||||
".BMP",
|
||||
".gif",
|
||||
".GIF",
|
||||
".jpeg",
|
||||
".JPEG",
|
||||
".jpg",
|
||||
".JPG",
|
||||
".png",
|
||||
".PNG",
|
||||
".tiff",
|
||||
".TIFF",
|
||||
".tif",
|
||||
".TIF"
|
||||
],
|
||||
"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",
|
||||
".tif",
|
||||
".TIF"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -46,10 +46,10 @@ public interface IProperty
|
||||
static (bool?, string[]) IsWrongYear(Models.FileHolder fileHolder, DateTime? dateTimeOriginal, List<DateTime> dateTimes) =>
|
||||
Property.IsWrongYear(fileHolder, dateTimeOriginal, dateTimes);
|
||||
|
||||
(DateTime?, DateTime?[], int?, string?) TestStatic_Get(Models.FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension) =>
|
||||
Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension);
|
||||
static (DateTime?, DateTime?[], int?, string?) Get(Models.FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension) =>
|
||||
Property.Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension);
|
||||
(DateTime?, DateTime?[], int?, string?) TestStatic_Get(Models.FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension, bool populateId) =>
|
||||
Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension, populateId);
|
||||
static (DateTime?, DateTime?[], int?, string?) Get(Models.FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension, bool populateId) =>
|
||||
Property.Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension, populateId);
|
||||
|
||||
DateTime? TestStatic_GetDateTimeFromName(Models.FileHolder fileHolder) =>
|
||||
GetDateTimeFromName(fileHolder);
|
||||
|
@ -390,7 +390,7 @@ internal abstract class Property
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
internal static (DateTime?, DateTime?[], int?, string?) Get(Models.FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension)
|
||||
internal static (DateTime?, DateTime?[], int?, string?) Get(Models.FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension, bool populateId)
|
||||
{
|
||||
int? id = null;
|
||||
string? message = null;
|
||||
@ -409,6 +409,10 @@ internal abstract class Property
|
||||
ASCIIEncoding asciiEncoding = new();
|
||||
string dateTimeFormat = IProperty.DateTimeFormat();
|
||||
using Image image = Image.FromFile(fileHolder.FullName);
|
||||
if (!populateId)
|
||||
id = null;
|
||||
else
|
||||
{
|
||||
using Bitmap bitmap = new(image);
|
||||
Rectangle rectangle = new(0, 0, image.Width, image.Height);
|
||||
BitmapData bitmapData = bitmap.LockBits(rectangle, ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
@ -419,6 +423,7 @@ internal abstract class Property
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
id = IProperty.GetDeterministicHashCode(bytes);
|
||||
bitmap.Dispose();
|
||||
}
|
||||
if (image.PropertyIdList.Contains((int)IExif.Tags.DateTime))
|
||||
{
|
||||
propertyItem = image.GetPropertyItem((int)IExif.Tags.DateTime);
|
||||
|
@ -51,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rename", "Rename\Rename.csp
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resize", "Resize\Resize.csproj", "{27D0D869-394D-4B07-83DF-2095B16026FC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Set-Created-Date", "Set-Created-Date\Set-Created-Date.csproj", "{B067643E-9F59-46A1-A001-ACF4661F059C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{B4FB6B43-36EC-404D-B934-5C695C6E32CC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsWithFaceRecognitionDotNet", "TestsWithFaceRecognitionDotNet\TestsWithFaceRecognitionDotNet.csproj", "{A67D73C7-A1A1-4443-B681-776339CFA08A}"
|
||||
@ -184,5 +186,9 @@ Global
|
||||
{E08CB662-FF25-48DF-A378-A770E1EFBA56}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E08CB662-FF25-48DF-A378-A770E1EFBA56}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E08CB662-FF25-48DF-A378-A770E1EFBA56}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B067643E-9F59-46A1-A001-ACF4661F059C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B067643E-9F59-46A1-A001-ACF4661F059C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B067643E-9F59-46A1-A001-ACF4661F059C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B067643E-9F59-46A1-A001-ACF4661F059C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
Loading…
x
Reference in New Issue
Block a user