wip(processing): analysis and render job handlers, render node client (interrupted)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
30 files changed
+2262
-21
No files matched your search
@@ -189,16 +189,23 @@ public sealed class LeaseFile : IDisposable
|
||||
|
||||
private static bool TryCreate(string path, LeaseRecord record)
|
||||
{
|
||||
try
|
||||
for (var attempt = 1; ; attempt++)
|
||||
{
|
||||
using var fs = new FileStream(path, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
|
||||
fs.Write(JsonSerializer.SerializeToUtf8Bytes(record, ArchiveJson.Default.LeaseRecord));
|
||||
fs.Flush(flushToDisk: true);
|
||||
return true;
|
||||
}
|
||||
catch (IOException) when (File.Exists(path))
|
||||
{
|
||||
return false;
|
||||
try
|
||||
{
|
||||
using var fs = new FileStream(path, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
|
||||
fs.Write(JsonSerializer.SerializeToUtf8Bytes(record, ArchiveJson.Default.LeaseRecord));
|
||||
fs.Flush(flushToDisk: true);
|
||||
return true;
|
||||
}
|
||||
catch (IOException) when (File.Exists(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (IOException) when (attempt < 3)
|
||||
{
|
||||
// The holder released the lease between the failed create and the check: the name is free again.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Titano.Core.Project;
|
||||
@@ -181,13 +182,40 @@ public sealed record ProjectSettings
|
||||
|
||||
public string ToJson() => JsonSerializer.Serialize(this, ProjectJson.Default.ProjectSettings);
|
||||
|
||||
/// <summary>
|
||||
/// Reads a project; members missing from <paramref name="json"/> (an API client's partial settings, an older file)
|
||||
/// keep their defaults. The JSON is laid over the default project first, because generated deserialisation leaves
|
||||
/// missing init-only members null or false rather than at their initial values.
|
||||
/// </summary>
|
||||
/// <exception cref="JsonException">The text is not a JSON object.</exception>
|
||||
/// <exception cref="InvalidDataException">The project was written by a newer Titano.</exception>
|
||||
public static ProjectSettings FromJson(string json)
|
||||
{
|
||||
var settings = JsonSerializer.Deserialize(json, ProjectJson.Default.ProjectSettings) ?? new ProjectSettings();
|
||||
var options = new JsonNodeOptions { PropertyNameCaseInsensitive = true };
|
||||
var merged = JsonNode.Parse(new ProjectSettings().ToJson(), options)!.AsObject();
|
||||
switch (JsonNode.Parse(json, options))
|
||||
{
|
||||
case JsonObject given:
|
||||
Overlay(merged, given);
|
||||
break;
|
||||
case not null:
|
||||
throw new JsonException("A project must be a JSON object.");
|
||||
}
|
||||
var settings = JsonSerializer.Deserialize(merged, ProjectJson.Default.ProjectSettings) ?? new ProjectSettings();
|
||||
if (settings.Version > CurrentVersion)
|
||||
throw new InvalidDataException($"project.json version {settings.Version} is newer than this Titano ({CurrentVersion}).");
|
||||
return settings;
|
||||
}
|
||||
|
||||
/// <summary>Copies <paramref name="source"/> into <paramref name="target"/>, merging nested objects; a null never replaces an object.</summary>
|
||||
private static void Overlay(JsonObject target, JsonObject source)
|
||||
{
|
||||
foreach (var (name, value) in source)
|
||||
{
|
||||
if (value is JsonObject child && target[name] is JsonObject existing) Overlay(existing, child);
|
||||
else if (value is not null || target[name] is not JsonObject) target[name] = value?.DeepClone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(
|
||||
|
||||
Reference in new issue
Block a user