Drag-Drop-Set-Property-Item
This commit is contained in:
parent
d23398db7a
commit
662ddfc44d
43
.vscode/launch.json
vendored
43
.vscode/launch.json
vendored
@ -157,6 +157,23 @@
|
||||
"stopAtEntry": false,
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": "Drag-Drop-Set-Property-Item",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Drag-Drop-Set-Property-Item/bin/Debug/net7.0-windows/win-x64/Drag-Drop-Set-Property-Item.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "integratedTerminal",
|
||||
"stopAtEntry": false,
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": "Instance",
|
||||
"type": "coreclr",
|
||||
@ -505,4 +522,28 @@
|
||||
// _ Import of Partial info
|
||||
// ` Want to find
|
||||
// ~ Approxomite age
|
||||
// + Approxomite age and have at least one image
|
||||
// + Approxomite age and have at least one image
|
||||
// XPAuthor = 40093 | [3-1] ("Picasa") <Verified in Windows>
|
||||
// Artist = 315 | [182-3] ("Picasa", "unknown", " ")
|
||||
// Kristy, Mike, Tracy, Mackenzie, Julie, Patrick, ...
|
||||
// XPKeywords = 40094 | Vulgar !9, Blurry !4, Duplicate !3, Irrelevant !2, Review !1, Slideshow [0]
|
||||
// XPSubject = 40095 | Family Pictures, Scanned [2-1] (" ")
|
||||
// XPComment = 40092 | [9-2] ("\uFFFD", " ")
|
||||
// Rating = 18246 | [52-1] ("0")
|
||||
// UserComment = 37510 | [3570-^^^]
|
||||
// XPTitle = 40091 | [24-24] ("Logan and his Doggie", ...) <Verified in Windows>
|
||||
// ImageDescription = 270 | [2135-5^] 4+37+82+1354+647+11 ("Camera 360", "OLYMPUS DIGITAL CAMERA ", "SAMSUNG ", " ", " ")
|
||||
// int artist = (int)IExif.Tags.Artist;
|
||||
// int fileSource = (int)IExif.Tags.FileSource;
|
||||
// int userComment = (int)IExif.Tags.UserComment;
|
||||
// 0x9c9b XPTitle int8u IFD0 (tags 0x9c9b-0x9c9f are used by Windows Explorer; special characters in these values are converted to UTF-8 by default, or Windows Latin1 with the -L option. XPTitle is ignored by Windows Explorer if ImageDescription exists)
|
||||
// 0x9c9c XPComment int8u IFD0
|
||||
// 0x9c9d XPAuthor int8u IFD0 (ignored by Windows Explorer if Artist exists)
|
||||
// 0x9c9e XPKeywords int8u IFD0
|
||||
// 0x9c9f XPSubject int8u IFD0
|
||||
// 0xa300 FileSource undef ExifIFD 1 = Film Scanner
|
||||
// 2 = Reflection Print Scanner
|
||||
// 3 = Digital Camera
|
||||
// "\x03\x00\x00\x00" = Sigma Digital Camera
|
||||
// 0x9286 UserComment undef ExifIFD
|
||||
// 0x013b Artist string IFD0 (becomes a list-type tag when the MWG module is loaded)
|
||||
|
4
Drag-Drop-Move/DragDropMove.Designer.cs
generated
4
Drag-Drop-Move/DragDropMove.Designer.cs
generated
@ -1,4 +1,4 @@
|
||||
namespace View_by_Distance.Drag_Drop_Explorer;
|
||||
namespace View_by_Distance.Drag.Drop.Move;
|
||||
|
||||
partial class DragDropMove
|
||||
{
|
||||
@ -32,7 +32,7 @@ partial class DragDropMove
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(640, 100);
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
this.Text = "Drag Drop Explorer";
|
||||
this.Text = "Drag Drop Move";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -4,11 +4,11 @@ using Serilog;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Drag_Drop_Explorer.Models;
|
||||
using View_by_Distance.Drag.Drop.Move.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
using WindowsShortcutFactory;
|
||||
|
||||
namespace View_by_Distance.Drag_Drop_Explorer;
|
||||
namespace View_by_Distance.Drag.Drop.Move;
|
||||
|
||||
public partial class DragDropMove : Form
|
||||
{
|
||||
|
@ -1,23 +1,12 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Drag_Drop_Explorer.Models;
|
||||
namespace View_by_Distance.Drag.Drop.Move.Models;
|
||||
|
||||
public class AppSettings
|
||||
public record AppSettings(string Company,
|
||||
int MaxDegreeOfParallelism,
|
||||
string WorkingDirectoryName)
|
||||
{
|
||||
|
||||
public string Company { init; get; }
|
||||
public int MaxDegreeOfParallelism { init; get; }
|
||||
public string WorkingDirectoryName { init; get; }
|
||||
|
||||
[JsonConstructor]
|
||||
public AppSettings(string company, int maxDegreeOfParallelism, string workingDirectoryName)
|
||||
{
|
||||
Company = company;
|
||||
MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
WorkingDirectoryName = workingDirectoryName;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
|
@ -1,18 +1,14 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Drag_Drop_Explorer.Models.Binder;
|
||||
namespace View_by_Distance.Drag.Drop.Move.Models.Binder;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
#nullable disable
|
||||
|
||||
public string Company { get; set; }
|
||||
public string? Company { get; set; }
|
||||
public int? MaxDegreeOfParallelism { get; set; }
|
||||
public string WorkingDirectoryName { get; set; }
|
||||
|
||||
#nullable restore
|
||||
public string? WorkingDirectoryName { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
@ -23,8 +19,12 @@ public class AppSettings
|
||||
private static Models.AppSettings Get(AppSettings? appSettings)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
if (appSettings?.Company is null)
|
||||
throw new NullReferenceException(nameof(appSettings.Company));
|
||||
if (appSettings?.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
if (appSettings?.WorkingDirectoryName is null)
|
||||
throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
|
||||
result = new(
|
||||
appSettings.Company,
|
||||
appSettings.MaxDegreeOfParallelism.Value,
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace View_by_Distance.Drag_Drop_Explorer;
|
||||
namespace View_by_Distance.Drag.Drop.Move;
|
||||
|
||||
public class Program
|
||||
{
|
||||
|
26
Drag-Drop-Set-Property-Item/.vscode/launch.json
vendored
Normal file
26
Drag-Drop-Set-Property-Item/.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-windows/win-x64/Drag-Drop-Explorer.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
Drag-Drop-Set-Property-Item/.vscode/tasks.json
vendored
Normal file
41
Drag-Drop-Set-Property-Item/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/Drag-Drop-Explorer.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/Drag-Drop-Explorer.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"--project",
|
||||
"${workspaceFolder}/Drag-Drop-Explorer.csproj"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<UserSecretsId>c64a15ed-0ba3-4378-8f80-0c19d0531747</UserSecretsId>
|
||||
</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>
|
39
Drag-Drop-Set-Property-Item/DragDropSetPropertyItem.Designer.cs
generated
Normal file
39
Drag-Drop-Set-Property-Item/DragDropSetPropertyItem.Designer.cs
generated
Normal file
@ -0,0 +1,39 @@
|
||||
namespace View_by_Distance.Drag.Drop.Set.Item;
|
||||
|
||||
partial class DragDropSetPropertyItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(640, 100);
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
this.Text = "Drag Drop Set Property Item";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
228
Drag-Drop-Set-Property-Item/DragDropSetPropertyItem.cs
Normal file
228
Drag-Drop-Set-Property-Item/DragDropSetPropertyItem.cs
Normal file
@ -0,0 +1,228 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Phares.Shared;
|
||||
using Serilog;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Drag.Drop.Set.Item.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
namespace View_by_Distance.Drag.Drop.Set.Item;
|
||||
|
||||
public partial class DragDropSetPropertyItem : Form
|
||||
{
|
||||
|
||||
private readonly ILogger _Logger;
|
||||
private readonly TextBox _PathTextBox;
|
||||
private readonly TextBox _JsonTextBox;
|
||||
private readonly TextBox _FirstTextBox;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly ProgressBar _ProgressBar;
|
||||
private readonly string _WorkingDirectory;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
|
||||
public DragDropSetPropertyItem()
|
||||
{
|
||||
InitializeComponent();
|
||||
ILogger logger;
|
||||
AppSettings appSettings;
|
||||
string workingDirectory;
|
||||
IsEnvironment isEnvironment;
|
||||
IConfigurationRoot configurationRoot;
|
||||
LoggerConfiguration loggerConfiguration = new();
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||
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>();
|
||||
configurationRoot = configurationBuilder.Build();
|
||||
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
throw new Exception("Working path name must have parentDirectory setTo!");
|
||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
||||
Log.Logger = loggerConfiguration.CreateLogger();
|
||||
logger = Log.ForContext<DragDropSetPropertyItem>();
|
||||
logger.Information("Complete");
|
||||
_Logger = logger;
|
||||
_AppSettings = appSettings;
|
||||
_IsEnvironment = isEnvironment;
|
||||
_WorkingDirectory = workingDirectory;
|
||||
_ProgressBar = new() { TabIndex = 4, Location = new(5, 5), Dock = DockStyle.Top, Visible = false };
|
||||
string json = JsonSerializer.Serialize(_AppSettings, new JsonSerializerOptions { WriteIndented = true });
|
||||
_FirstTextBox = new() { TabIndex = 1, Text = _IsEnvironment.Profile, Location = new(5, 5), Dock = DockStyle.Top };
|
||||
_PathTextBox = new() { TabIndex = 2, Text = _AppSettings.WorkingDirectoryName, Location = new(5, 5), Dock = DockStyle.Top };
|
||||
_JsonTextBox = new() { TabIndex = 3, Text = json, Multiline = true, MinimumSize = new(1, 80), Location = new(5, 5), Dock = DockStyle.Top };
|
||||
Load += new EventHandler(Form1_Load);
|
||||
Controls.Add(_ProgressBar);
|
||||
Controls.Add(_JsonTextBox);
|
||||
Controls.Add(_PathTextBox);
|
||||
Controls.Add(_FirstTextBox);
|
||||
}
|
||||
|
||||
private void Form1_Load(object? sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
AllowDrop = true;
|
||||
DragDrop += new DragEventHandler(Form1_DragDrop);
|
||||
DragEnter += new DragEventHandler(Form1_DragEnter);
|
||||
if (_WorkingDirectory is null)
|
||||
{ }
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void Form1_DragEnter(object? sender, DragEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e.Data is not null && e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetMessage(string message)
|
||||
{
|
||||
_Logger.Information(message);
|
||||
_JsonTextBox.Text = message;
|
||||
}
|
||||
|
||||
private static List<(string, int, DateTime?, short?, string?)> GetCollection(ASCIIEncoding asciiEncoding, int tagId, List<string> files)
|
||||
{
|
||||
List<(string, int, DateTime?, short?, string?)> results = new();
|
||||
string? value;
|
||||
PropertyItem? propertyItem;
|
||||
Shared.Models.Property property;
|
||||
foreach (string file in files)
|
||||
{
|
||||
property = Property.Models.A_Property.GetImageProperty(file);
|
||||
if (property.Id is null)
|
||||
continue;
|
||||
using Image image = Image.FromFile(file);
|
||||
if (!image.PropertyIdList.Contains(tagId))
|
||||
(propertyItem, value) = (null, null);
|
||||
else
|
||||
{
|
||||
propertyItem = image.GetPropertyItem(tagId);
|
||||
if (propertyItem?.Value is null)
|
||||
value = null;
|
||||
else
|
||||
{
|
||||
if (propertyItem.Type == 2)
|
||||
value = asciiEncoding.GetString(propertyItem.Value).Trim('\0', ' ');
|
||||
else if (propertyItem.Type == 1)
|
||||
value = Encoding.Unicode.GetString(propertyItem.Value).Trim('\0', ' ');
|
||||
else
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
results.Add((file, property.Id.Value, property.DateTimeOriginal, propertyItem?.Type, value));
|
||||
}
|
||||
if (files.Count != results.Count)
|
||||
throw new NotSupportedException();
|
||||
return results;
|
||||
}
|
||||
|
||||
private void SetPropertyItem(string setTo, int tagId, short type, ConstructorInfo constructorInfo, List<(string, int, DateTime?, short?, string?)> collection)
|
||||
{
|
||||
Bitmap bitmap;
|
||||
string checkFile;
|
||||
PropertyItem? propertyItem;
|
||||
Shared.Models.Property property;
|
||||
foreach ((string file, int id, DateTime? dateTimeOriginal, short? propertyItemType, string? value) in collection)
|
||||
{
|
||||
if (propertyItemType is not null && propertyItemType.Value != type)
|
||||
throw new NotSupportedException();
|
||||
if ((dateTimeOriginal is null || !string.IsNullOrEmpty(value) || value == setTo) && !_AppSettings.IgnoreRulesKeyWords.Contains(setTo))
|
||||
continue;
|
||||
checkFile = $"{file}.exif";
|
||||
propertyItem = IProperty.GetPropertyItem(constructorInfo, tagId, type, setTo);
|
||||
bitmap = new(file);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
bitmap.Save(checkFile);
|
||||
bitmap.Dispose();
|
||||
property = Property.Models.A_Property.GetImageProperty(checkFile);
|
||||
if (property.Id is null || property.Id.Value != id)
|
||||
throw new NotSupportedException();
|
||||
File.Delete(file);
|
||||
File.Move(checkFile, file);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetPropertyItem(string setTo, List<string> files)
|
||||
{
|
||||
short type = 1;
|
||||
ASCIIEncoding asciiEncoding = new();
|
||||
int xpKeywords = (int)IExif.Tags.XPKeywords;
|
||||
ConstructorInfo? constructorInfo = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, Array.Empty<Type>(), null) ?? throw new Exception();
|
||||
List<(string, int, DateTime?, short?, string?)> collection = GetCollection(asciiEncoding, xpKeywords, files);
|
||||
if (!collection.Any())
|
||||
SetMessage("No data");
|
||||
else
|
||||
SetPropertyItem(setTo, xpKeywords, type, constructorInfo, collection);
|
||||
}
|
||||
|
||||
private void SetPropertyItem(string[] paths, string setTo)
|
||||
{
|
||||
FileInfo fileInfo;
|
||||
List<string> files = new();
|
||||
foreach (string path in paths.OrderBy(l => l))
|
||||
{
|
||||
fileInfo = new(path);
|
||||
if (fileInfo.Exists)
|
||||
files.Add(path);
|
||||
else
|
||||
{
|
||||
if (paths.Length != 1)
|
||||
break;
|
||||
files.AddRange(Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly));
|
||||
}
|
||||
}
|
||||
if (!files.Any())
|
||||
SetMessage("No data");
|
||||
else
|
||||
SetPropertyItem(setTo, files);
|
||||
}
|
||||
|
||||
private void SetPropertyItem(string[] paths)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_FirstTextBox.Text) || !_AppSettings.ValidKeyWords.Contains(_FirstTextBox.Text))
|
||||
SetMessage($"[{_FirstTextBox.Text}] is not valid!");
|
||||
else
|
||||
SetPropertyItem(paths, _FirstTextBox.Text);
|
||||
}
|
||||
|
||||
private void Form1_DragDrop(object? sender, DragEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e.Data is not null && e.Data.GetData(DataFormats.FileDrop) is string[] paths && paths.Any())
|
||||
SetPropertyItem(paths);
|
||||
else
|
||||
{
|
||||
_PathTextBox.Text = string.Empty;
|
||||
SetMessage("No data");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
18
Drag-Drop-Set-Property-Item/Models/AppSettings.cs
Normal file
18
Drag-Drop-Set-Property-Item/Models/AppSettings.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Drag.Drop.Set.Item.Models;
|
||||
|
||||
public record AppSettings(string Company,
|
||||
string[] IgnoreRulesKeyWords,
|
||||
int MaxDegreeOfParallelism,
|
||||
string[] ValidKeyWords,
|
||||
string WorkingDirectoryName)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
52
Drag-Drop-Set-Property-Item/Models/Binder/AppSettings.cs
Normal file
52
Drag-Drop-Set-Property-Item/Models/Binder/AppSettings.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Drag.Drop.Set.Item.Models.Binder;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
|
||||
public string? Company { get; set; }
|
||||
public string[]? IgnoreRulesKeyWords { get; set; }
|
||||
public int? MaxDegreeOfParallelism { get; set; }
|
||||
public string[]? ValidKeyWords { get; set; }
|
||||
public string? WorkingDirectoryName { get; set; }
|
||||
|
||||
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?.Company is null)
|
||||
throw new NullReferenceException(nameof(appSettings.Company));
|
||||
if (appSettings?.IgnoreRulesKeyWords is null)
|
||||
throw new NullReferenceException(nameof(appSettings.IgnoreRulesKeyWords));
|
||||
if (appSettings?.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
if (appSettings?.ValidKeyWords is null)
|
||||
throw new NullReferenceException(nameof(appSettings.ValidKeyWords));
|
||||
if (appSettings?.WorkingDirectoryName is null)
|
||||
throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
|
||||
result = new(
|
||||
appSettings.Company,
|
||||
appSettings.IgnoreRulesKeyWords,
|
||||
appSettings.MaxDegreeOfParallelism.Value,
|
||||
appSettings.ValidKeyWords,
|
||||
appSettings.WorkingDirectoryName
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
|
||||
result = Get(appSettings);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
15
Drag-Drop-Set-Property-Item/Program.cs
Normal file
15
Drag-Drop-Set-Property-Item/Program.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace View_by_Distance.Drag.Drop.Set.Item;
|
||||
|
||||
public class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new DragDropSetPropertyItem());
|
||||
}
|
||||
|
||||
}
|
11
Drag-Drop-Set-Property-Item/appsettings.Development.json
Normal file
11
Drag-Drop-Set-Property-Item/appsettings.Development.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Log4netProvider": "Debug"
|
||||
}
|
||||
},
|
||||
"MaxDegreeOfParallelism": 6,
|
||||
"Serilog": {
|
||||
"MinimumLevel": "Debug"
|
||||
}
|
||||
}
|
54
Drag-Drop-Set-Property-Item/appsettings.json
Normal file
54
Drag-Drop-Set-Property-Item/appsettings.json
Normal file
@ -0,0 +1,54 @@
|
||||
{
|
||||
"Company": "Mike Phares",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Log4netProvider": "Debug",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"IgnoreRulesKeyWords": [],
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"ValidKeyWords": [
|
||||
"Review"
|
||||
],
|
||||
"WorkingDirectoryName": "PharesApps"
|
||||
}
|
@ -152,22 +152,12 @@ public class D_Face
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
private PropertyItem GetPropertyItem(int id, string value)
|
||||
{
|
||||
PropertyItem result = (PropertyItem)_ConstructorInfo.Invoke(null);
|
||||
byte[] bytes = C_Resize.GetBytes(value);
|
||||
result.Id = id;
|
||||
result.Len = value.Length + 1;
|
||||
result.Type = 2;
|
||||
result.Value = bytes;
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SaveFaces(FileHolder resizedFileHolder, List<(Shared.Models.Face, FileInfo?, string, bool)> collection)
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
Bitmap bitmap;
|
||||
short type = 2;
|
||||
Graphics graphics;
|
||||
Location? location;
|
||||
Rectangle rectangle;
|
||||
@ -200,11 +190,11 @@ public class D_Face
|
||||
{
|
||||
using (graphics = Graphics.FromImage(bitmap))
|
||||
graphics.DrawImage(source, new Rectangle(0, 0, width, height), rectangle, GraphicsUnit.Pixel);
|
||||
propertyItem = GetPropertyItem(fileSource, locationJson);
|
||||
propertyItem = Shared.Models.Stateless.Methods.IProperty.GetPropertyItem(_ConstructorInfo, fileSource, type, locationJson);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
propertyItem = GetPropertyItem(artist, outputResolutionJson);
|
||||
propertyItem = Shared.Models.Stateless.Methods.IProperty.GetPropertyItem(_ConstructorInfo, artist, type, outputResolutionJson);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
propertyItem = GetPropertyItem(userComment, faceEncodingJson);
|
||||
propertyItem = Shared.Models.Stateless.Methods.IProperty.GetPropertyItem(_ConstructorInfo, userComment, type, faceEncodingJson);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
bitmap.Save(fileInfo.FullName, _ImageCodecInfo, _EncoderParameters);
|
||||
}
|
||||
|
@ -60,30 +60,6 @@ public class OffsetDateTimeOriginal
|
||||
{ }
|
||||
}
|
||||
|
||||
private static byte[] GetBytes(string value)
|
||||
{
|
||||
byte[] results = new byte[value.Length + 1];
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
results[i] = (byte)value[i];
|
||||
results[value.Length] = 0x00;
|
||||
return results;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
private static PropertyItem GetPropertyItem(ConstructorInfo constructorInfo, int id, string value)
|
||||
{
|
||||
PropertyItem result = (PropertyItem)constructorInfo.Invoke(null);
|
||||
byte[] bytes = GetBytes(value);
|
||||
result.Id = id;
|
||||
result.Len = value.Length + 1;
|
||||
result.Type = 2;
|
||||
result.Value = bytes;
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
||||
private static List<(string, int, DateTime)> GetCollection(string checkDirectory, DateTime minimumDateTime, DateTime maximumDateTime, long ticks)
|
||||
{
|
||||
List<(string, int, DateTime)> results = new();
|
||||
@ -112,6 +88,7 @@ public class OffsetDateTimeOriginal
|
||||
private static void DateFix(string sourceDirectory, string checkDirectory, DateTime minimumDateTime, DateTime maximumDateTime, long ticks)
|
||||
{
|
||||
Bitmap bitmap;
|
||||
short type = 2;
|
||||
string checkFile;
|
||||
PropertyItem? propertyItem;
|
||||
string? ticksDirectory = null;
|
||||
@ -126,7 +103,6 @@ public class OffsetDateTimeOriginal
|
||||
break;
|
||||
}
|
||||
ticks++;
|
||||
|
||||
}
|
||||
List<(string, int, DateTime)> collection = GetCollection(checkDirectory, minimumDateTime, maximumDateTime, ticks);
|
||||
ConstructorInfo? constructorInfo = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, Array.Empty<Type>(), null) ?? throw new Exception();
|
||||
@ -141,7 +117,7 @@ public class OffsetDateTimeOriginal
|
||||
checkFile = Path.Combine(ticksDirectory, Path.GetFileName(file));
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
propertyItem = GetPropertyItem(constructorInfo, dateTimeOriginal, dateTime.ToString("yyyy:MM:dd HH:mm:ss"));
|
||||
propertyItem = Shared.Models.Stateless.Methods.IProperty.GetPropertyItem(constructorInfo, dateTimeOriginal, type, dateTime.ToString("yyyy:MM:dd HH:mm:ss"));
|
||||
bitmap = new(file);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
bitmap.Save(checkFile);
|
||||
|
@ -488,13 +488,4 @@ public class C_Resize
|
||||
return results;
|
||||
}
|
||||
|
||||
public static byte[] GetBytes(string value)
|
||||
{
|
||||
byte[] results = new byte[value.Length + 1];
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
results[i] = (byte)value[i];
|
||||
results[value.Length] = 0x00;
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
using System.Drawing.Imaging;
|
||||
using System.Reflection;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IProperty
|
||||
@ -101,4 +104,14 @@ public interface IProperty
|
||||
static List<DateTime> GetDateTimes(DateTime creationTime, DateTime lastWriteTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeFromName, DateTime? dateTimeOriginal, DateTime? gpsDateStamp) =>
|
||||
Property.GetDateTimes(creationTime, lastWriteTime, dateTime, dateTimeDigitized, dateTimeFromName, dateTimeOriginal, gpsDateStamp);
|
||||
|
||||
byte[] TestStatic_GetBytes(string value) =>
|
||||
GetBytes(value);
|
||||
static byte[] GetBytes(string value) =>
|
||||
Property.GetBytes(value);
|
||||
|
||||
PropertyItem TestStatic_GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value) =>
|
||||
GetPropertyItem(constructorInfo, id, type, value);
|
||||
static PropertyItem GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value) =>
|
||||
Property.GetPropertyItem(constructorInfo, id, type, value);
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
@ -491,6 +492,30 @@ internal abstract class Property
|
||||
return new(dateTimeOriginal, dateTimes, id, message);
|
||||
}
|
||||
|
||||
internal static PropertyItem GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value)
|
||||
{
|
||||
PropertyItem result = (PropertyItem)constructorInfo.Invoke(null);
|
||||
int length;
|
||||
byte[] bytes;
|
||||
if (type == 2)
|
||||
{
|
||||
bytes = GetBytes(value);
|
||||
length = value.Length + 1;
|
||||
}
|
||||
else if (type == 1)
|
||||
{
|
||||
bytes = Encoding.Unicode.GetBytes($"{value}\0");
|
||||
length = bytes.Length;
|
||||
}
|
||||
else
|
||||
throw new NotSupportedException();
|
||||
result.Id = id;
|
||||
result.Len = length;
|
||||
result.Type = type;
|
||||
result.Value = bytes;
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
||||
internal static DateTime? GetDateTime(string dateTimeFormat, string? value)
|
||||
@ -508,4 +533,13 @@ internal abstract class Property
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static byte[] GetBytes(string value)
|
||||
{
|
||||
byte[] results = new byte[value.Length + 1];
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
results[i] = (byte)value[i];
|
||||
results[value.Length] = 0x00;
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Drag-Drop-Move", "Drag-Drop
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Drag-Drop-Search", "Drag-Drop-Search\Drag-Drop-Search.csproj", "{87EB76BC-32A9-4FD0-922A-BD7E9B6E7D8B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Drag-Drop-Set-Property-Item", "Drag-Drop-Set-Property-Item\Drag-Drop-Set-Property-Item.csproj", "{BFF75D8C-48E6-4B84-B480-3E5A4F9B2DD8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Duplicate-Search", "Duplicate-Search\Duplicate-Search.csproj", "{48E87D9B-B802-467A-BDC7-E86F7FD01D5C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Face", "Face\Face.csproj", "{A12E19E5-59C0-40D4-B807-DF1334D4906D}"
|
||||
@ -206,5 +208,9 @@ Global
|
||||
{6B68758E-1AF1-401F-844A-C1199A0B6303}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6B68758E-1AF1-401F-844A-C1199A0B6303}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6B68758E-1AF1-401F-844A-C1199A0B6303}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BFF75D8C-48E6-4B84-B480-3E5A4F9B2DD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BFF75D8C-48E6-4B84-B480-3E5A4F9B2DD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BFF75D8C-48E6-4B84-B480-3E5A4F9B2DD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BFF75D8C-48E6-4B84-B480-3E5A4F9B2DD8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
Loading…
x
Reference in New Issue
Block a user