XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text.Json;

namespace XFEEDToolBox.Core.Execution;

/// <summary>A bounded read-only maintenance quote wait; it is never permission to replay a monetary order.</summary>
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");
    }
}