Plain classes behind the Import and Archive screens: plan totals, session rows and the Show plan listing; duplicate and title choices without a new scan; folder and server destinations with the protocol client's chunked, hash-verified uploads; the after-import gate that allows deleting or formatting a card only after a verified archive import and a dry run; the archive tree, chart aggregation, mass rename/retag and maintenance reports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
77 lines
3.0 KiB
C#
77 lines
3.0 KiB
C#
using System.IO;
|
|
using Titano.Core.Codecs.Jpeg;
|
|
using Titano.Core.Imaging;
|
|
using Titano.Core.Import;
|
|
using Titano.Core.Metadata;
|
|
|
|
namespace Titano.App.Tests.Import;
|
|
|
|
/// <summary>Synthetic cards (small JPEGs with Exif) and hand-made plans for the Import tests.</summary>
|
|
internal static class ImportTestData
|
|
{
|
|
public static readonly DateTime Start = new(2026, 9, 28, 18, 2, 11);
|
|
|
|
/// <summary>A real JPEG with Exif make, model, body serial and capture time; each seed gives distinct bytes.</summary>
|
|
public static byte[] Jpeg(DateTime captured, int seed)
|
|
{
|
|
using var image = new ImageBuffer(32, 24);
|
|
var random = new Random(seed);
|
|
for (var c = 0; c < 3; c++)
|
|
{
|
|
var plane = image.Plane(c);
|
|
var level = (float)random.NextDouble();
|
|
for (var i = 0; i < plane.Length; i++) plane[i] = level * (0.5f + 0.5f * (i % 32) / 32f);
|
|
}
|
|
var exif = ExifWriter.BuildJpegApp1(new FrameMetadata { Make = "Canon", Model = "Canon EOS R5", BodySerial = "0431", CapturedAt = captured, Iso = 100 });
|
|
return JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 80, App1Segments = [exif[4..]] });
|
|
}
|
|
|
|
/// <summary>A card folder with <c>DCIM/100CANON</c>: one series per start time, <paramref name="perSession"/> photos 2 s apart.</summary>
|
|
public static string Card(string root, int perSession, params DateTime[] starts)
|
|
{
|
|
var folder = Path.Combine(root, "DCIM", "100CANON");
|
|
Directory.CreateDirectory(folder);
|
|
var n = 1;
|
|
foreach (var start in starts)
|
|
{
|
|
for (var i = 0; i < perSession; i++, n++)
|
|
File.WriteAllBytes(Path.Combine(folder, $"IMG_{n:0000}.JPG"), Jpeg(start.AddSeconds(2 * i), n));
|
|
}
|
|
return root;
|
|
}
|
|
|
|
public static PlannedItem Item(int n, DateTime captured, long size = 24_000_000, ImportAction action = ImportAction.Copy, Guid? existing = null) => new()
|
|
{
|
|
SourcePath = $"DCIM/100CANON/IMG_{n:0000}.CR2",
|
|
Size = size,
|
|
ModifiedUtc = captured,
|
|
CapturedAt = captured,
|
|
FileName = $"{captured:yyyy-MM-dd_HH-mm-ss}_{n:0000}.CR2",
|
|
Action = action,
|
|
ExistingFrameId = existing,
|
|
};
|
|
|
|
public static PlannedSession Session(int number, string folder, params PlannedItem[] items) => new()
|
|
{
|
|
Number = number,
|
|
SessionKey = $"card-0000000{number}-key",
|
|
CameraMake = "Canon",
|
|
CameraModel = "Canon EOS R5",
|
|
Format = ImageFileFormat.Cr2,
|
|
Start = items[0].CapturedAt,
|
|
End = items[^1].CapturedAt,
|
|
Folder = folder,
|
|
Items = items,
|
|
};
|
|
|
|
public static ImportPlan Plan(long? available, IReadOnlyList<ImportProblem>? problems = null, params PlannedSession[] sessions) => new()
|
|
{
|
|
Id = Guid.CreateVersion7(),
|
|
SourceRoot = "/card",
|
|
DestinationRoot = "/archive",
|
|
Sessions = sessions,
|
|
Problems = problems ?? [],
|
|
AvailableBytes = available,
|
|
};
|
|
}
|