using System.Text.Json; namespace XFEEDToolBox.Core.Execution; /// A bounded read-only maintenance quote wait; it is never permission to replay a monetary order. public sealed class NativeServiceSnapshotUnavailableException(int attempts,string diagnosticPath,Exception? inner=null) :IOException("原生站内服务只读报价尚未就绪;本次读取未提交维护或交易,已确认订单不会重发。",inner) { public int Attempts{get;}=attempts; public string DiagnosticPath{get;}=diagnosticPath; public const int MaximumAttempts=8; public static readonly TimeSpan ReadinessBudget=TimeSpan.FromSeconds(15); public static bool IsUnsubmittedReadFailure(JsonElement queued,JsonElement result,long market) { static bool Number(JsonElement row,string field,long expected)=>row.TryGetProperty(field,out var value)&&value.ValueKind==JsonValueKind.Number&&value.TryGetInt64(out var actual)&&actual==expected; static bool False(JsonElement row,string field)=>row.TryGetProperty(field,out var value)&&value.ValueKind==JsonValueKind.False; return NativeMarketSnapshotUnavailableException.IsFreshnessRejection(result) &&queued.TryGetProperty("generation",out var generation)&&generation.TryGetUInt64(out var id)&&id>0 &&result.TryGetProperty("generation",out var receiptGeneration)&&receiptGeneration.TryGetUInt64(out var receiptId)&&receiptId==id &&Number(queued,"mutationsSent",0)&&Number(result,"serviceKind",3)&&Number(result,"marketId",market) &&Number(result,"quantityDelta",0)&&False(result,"reconciliationRequired")&&False(result,"clientApplied")&&False(result,"serverConfirmed"); } }