32 lines
1.4 KiB
C#
32 lines
1.4 KiB
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace GerbilManagerWebAPI.Import.Rpro3
|
|
{
|
|
/// <summary>
|
|
/// Deterministische GUIDs aus stabilen RPRO3-Schlüsseln (analog zum Python `generate_guid`-Muster).
|
|
/// Gleicher Schlüssel → gleiche GUID über Re-Imports hinweg → idempotent.
|
|
/// MD5-basiert (Namespace-Präfix vermeidet Kollisionen mit anderen Entitätstypen).
|
|
/// </summary>
|
|
public static class Rpro3Guid
|
|
{
|
|
public const string ImportSource = "RennmausPro III";
|
|
|
|
public static Guid For(string @namespace, string key)
|
|
{
|
|
var bytes = MD5.HashData(Encoding.UTF8.GetBytes($"rpro3:{@namespace}:{key}"));
|
|
return new Guid(bytes);
|
|
}
|
|
|
|
public static Guid Gerbil(string clusterRootRid) => For("gerbil", clusterRootRid);
|
|
public static Guid Litter(int wurfId) => For("litter", wurfId.ToString());
|
|
public static Guid Contact(string ns, int id) => For("contact", $"{ns}:{id}");
|
|
public static Guid Health(string tid, string disc, int seq) => For("health", $"{tid}:{seq}:{disc}");
|
|
public static Guid Weight(string tid, int seq) => For("weight", $"{tid}:{seq}");
|
|
|
|
/// <summary>Stabiler ExternalRef-Wert (Gerbil/Litter Idempotenzschlüssel, UNIQUE-Spalte).</summary>
|
|
public static string GerbilRef(string rootRid) => $"rpro3:{rootRid}";
|
|
public static string LitterRef(int wurfId) => $"rpro3-wurf:{wurfId}";
|
|
}
|
|
}
|