mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 00:21:06 -04:00
Adding a library drawing to a nest has several outcomes that must be decided before anything changes, so the desktop can show warnings first and so every rule is tested on Linux. `LibraryDrawingInsert.Plan` returns a new exact copy carrying its library link, an added quantity on the copy already there, or a refusal that leaves the nest untouched. - Material, grade or thickness that differ from the nest still add the drawing but drop its cut pins, with one warning naming each difference (D3). Names compare by SharedListNames key and thickness at four decimals, matching the server's own filters. - Different units are refused: conversion is out of scope and a silent unit mismatch would scale the part. - The same revision from the same server only raises the quantity; a different revision of that drawing is refused in favour of Update Drawings (D2b). - Another drawing with the same name is refused naming both, because the name-keyed DrawingCollection would otherwise drop one silently. - A package whose hash or units disagree with its record is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
namespace OpenNest.Data;
|
|
|
|
/// <summary>Base-address validation shared by the nest server's HTTP clients.</summary>
|
|
internal static class ServerUrl
|
|
{
|
|
/// <summary>
|
|
/// The key that binds saved nests and library links to a server: the address trimmed,
|
|
/// without trailing slashes. Two settings that differ only that way name the same server.
|
|
/// </summary>
|
|
public static string Key(string? url) => (url ?? "").Trim().TrimEnd('/');
|
|
|
|
/// <summary>
|
|
/// Returns the absolute http(s) base address with exactly one trailing slash, so
|
|
/// relative combines replace no path segment. Throws for any other address.
|
|
/// </summary>
|
|
public static Uri ParseBase(string? baseUrl, string paramName)
|
|
{
|
|
var url = (baseUrl ?? "").Trim().TrimEnd('/');
|
|
if (!Uri.TryCreate(url, UriKind.Absolute, out var baseUri)
|
|
|| (baseUri.Scheme != Uri.UriSchemeHttp && baseUri.Scheme != Uri.UriSchemeHttps))
|
|
{
|
|
throw new ArgumentException($"Invalid nest server URL: '{baseUrl}'", paramName);
|
|
}
|
|
|
|
return new Uri(baseUri.AbsoluteUri.TrimEnd('/') + "/");
|
|
}
|
|
}
|