Files
OpenNest/OpenNest.Data/NestRecordFactory.cs
T
ajandClaude Opus 5.5 bfdfefeb9e feat(data): store a nest's job number apart from the customer
Job numbers were going into Customer ("GM / 4980-88R"), which breaks
sorting, searching and grouping by customer. A nest now has its own
Job # field: one or several jobs separated by commas, normalized to
"a, b". It is saved in nest.json and the server (schema v21), edited
beside Customer in Edit Nest (WinForms and Avalonia), shown as a
sortable, searchable column in the Open list, and printed on the nest
report and in MCP output.

Deploy the server before the desktop: the open overlay takes the
server's job number, and an older server has none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 10:21:04 -05:00

69 lines
2.9 KiB
C#

using System.Linq;
namespace OpenNest.Data;
/// <summary>
/// Builds the shareable <see cref="NestRecord"/> metadata from a live <see cref="Nest"/>.
/// Counts are computed here (not carried on <see cref="Nest"/> itself) so every caller
/// that saves to the nest server gets the same definition of "plate" and "part" counts.
/// </summary>
public static class NestRecordFactory
{
/// <summary>Overlays authoritative current metadata on an archived nest before editing.</summary>
public static void ApplyMetadata(Nest nest, NestRecord record)
{
ArgumentNullException.ThrowIfNull(nest);
ArgumentNullException.ThrowIfNull(record);
nest.Name = record.Name;
nest.Customer = record.Customer;
nest.JobNumber = record.JobNumber;
nest.Notes = record.Comments;
nest.Status = record.Status;
nest.MadeBy = record.MadeBy;
nest.DateLastModified = record.DateModified;
nest.DateCreated = record.DateCreated;
nest.Material = NestMaterialSelection.ApplyRecorded(nest.Material, record.Material, record.MaterialGrade);
nest.Thickness = record.Thickness;
nest.ThicknessName = record.ThicknessName;
}
/// <summary>
/// Builds a record for uploading <paramref name="nest"/>. <paramref name="id"/> is the
/// client-tracked id: <see cref="System.Guid.Empty"/> for a first save (the server
/// assigns one), or the previously returned id to update an existing record.
/// <paramref name="fileSize"/> is the size of the serialized .nest archive being
/// uploaded alongside this record; the server also recomputes it independently.
/// </summary>
public static NestRecord FromNest(Nest nest, System.Guid id, long fileSize)
{
ArgumentNullException.ThrowIfNull(nest);
return new NestRecord
{
Id = id,
Name = nest.Name ?? "",
Customer = nest.Customer ?? "",
JobNumber = nest.JobNumber ?? "",
DateCreated = nest.DateCreated,
DateModified = nest.DateLastModified,
Material = nest.Material?.Name ?? "",
MaterialGrade = nest.Material?.Grade ?? "",
Thickness = nest.Thickness,
ThicknessName = nest.ThicknessName ?? "",
Units = nest.Units,
Status = nest.Status,
// The trailing empty plate is the editor's new-plate slot, not a plate of the nest.
PlateCount = PlateDisplayNumbering.DisplayedPlateCount(nest.Plates),
PartCount = nest.Plates.Sum(CountNonCutoffParts),
// Nest has no separate "comments" field; Notes is the closest analog
// shown in the nest info dialog, so it round-trips as Comments here.
Comments = nest.Notes ?? "",
MadeBy = nest.MadeBy ?? "",
FileSize = fileSize,
};
}
private static int CountNonCutoffParts(Plate plate) =>
plate.Parts.Count(part => !part.BaseDrawing.IsCutOff);
}