|
@@ -14,10 +14,13 @@ namespace IvfTl.ControlHost.Debug
|
|
|
private readonly Func<DateTime> _clock;
|
|
private readonly Func<DateTime> _clock;
|
|
|
private readonly int _ttlMs;
|
|
private readonly int _ttlMs;
|
|
|
private readonly Action<string> _log;
|
|
private readonly Action<string> _log;
|
|
|
|
|
+ private readonly Func<int, (bool cultivating, int embryoCount)> _cultivationOf;
|
|
|
private readonly ConcurrentDictionary<string, DebugSession> _sessions = new ConcurrentDictionary<string, DebugSession>();
|
|
private readonly ConcurrentDictionary<string, DebugSession> _sessions = new ConcurrentDictionary<string, DebugSession>();
|
|
|
- public DebugSessionManager(Func<int, IHouseGate> gateOf, Func<DateTime> clock, int ttlMs, Action<string> log)
|
|
|
|
|
|
|
+ public DebugSessionManager(Func<int, IHouseGate> gateOf, Func<DateTime> clock, int ttlMs, Action<string> log,
|
|
|
|
|
+ Func<int, (bool, int)> cultivationOf = null)
|
|
|
{
|
|
{
|
|
|
_gateOf = gateOf; _clock = clock; _ttlMs = ttlMs; _log = log ?? (_ => { });
|
|
_gateOf = gateOf; _clock = clock; _ttlMs = ttlMs; _log = log ?? (_ => { });
|
|
|
|
|
+ _cultivationOf = cultivationOf;
|
|
|
}
|
|
}
|
|
|
public DebugCommandResult Acquire(int houseSn)
|
|
public DebugCommandResult Acquire(int houseSn)
|
|
|
{
|
|
{
|
|
@@ -27,8 +30,14 @@ namespace IvfTl.ControlHost.Debug
|
|
|
if (lease == null) return DebugCommandResult.Fail("BUSY", $"舱{houseSn}被占用,借用超时");
|
|
if (lease == null) return DebugCommandResult.Fail("BUSY", $"舱{houseSn}被占用,借用超时");
|
|
|
string sid = Guid.NewGuid().ToString("N");
|
|
string sid = Guid.NewGuid().ToString("N");
|
|
|
_sessions[sid] = new DebugSession(sid, houseSn, lease, _clock());
|
|
_sessions[sid] = new DebugSession(sid, houseSn, lease, _clock());
|
|
|
|
|
+ var res = DebugCommandResult.Okay(sid);
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ if (_cultivationOf != null) { var c = _cultivationOf(houseSn); res.Cultivating = c.Item1; res.EmbryoCount = c.Item2; }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex) { _log($"[debug] 取培养态异常 舱{houseSn}: {ex.Message}"); }
|
|
|
_log($"[debug] acquire 舱{houseSn} sid={sid}");
|
|
_log($"[debug] acquire 舱{houseSn} sid={sid}");
|
|
|
- return DebugCommandResult.Okay(sid);
|
|
|
|
|
|
|
+ return res;
|
|
|
}
|
|
}
|
|
|
public DebugCommandResult Heartbeat(string sid)
|
|
public DebugCommandResult Heartbeat(string sid)
|
|
|
{
|
|
{
|