< Summary

Information
Class: Lattice.ECS.Session.SessionRunnerFailureInfo
Assembly: Lattice
File(s): /home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Session/SessionRunnerLifecycle.cs
Line coverage
80%
Covered lines: 8
Uncovered lines: 2
Coverable lines: 10
Total lines: 189
Line coverage: 80%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%4485.71%
get_Kind()100%11100%
get_OperationName()100%11100%
get_Exception()100%210%

File(s)

/home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Session/SessionRunnerLifecycle.cs

#LineLine coverage
 1using System;
 2
 3namespace Lattice.ECS.Session
 4{
 5    /// <summary>
 6    /// SessionRunner 的停止原因。
 7    /// 用于把宿主主动停止、重置停止和失败停止区分为正式生命周期语义。
 8    /// </summary>
 9    public enum SessionRunnerShutdownCause
 10    {
 11        /// <summary>
 12        /// 尚未发生正式停止。
 13        /// </summary>
 14        None = 0,
 15
 16        /// <summary>
 17        /// 宿主显式调用 Stop()。
 18        /// </summary>
 19        HostStopRequested = 1,
 20
 21        /// <summary>
 22        /// 因重建 runtime 而停止旧实例。
 23        /// </summary>
 24        RuntimeReset = 2,
 25
 26        /// <summary>
 27        /// 因释放 runner 而停止。
 28        /// </summary>
 29        RunnerDisposed = 3,
 30
 31        /// <summary>
 32        /// 启动阶段失败后进入关闭收敛。
 33        /// </summary>
 34        StartupFailure = 4,
 35
 36        /// <summary>
 37        /// 固定帧推进失败后进入关闭收敛。
 38        /// </summary>
 39        StepFailure = 5
 40    }
 41
 42    /// <summary>
 43    /// SessionRunner 的 runtime 重建原因。
 44    /// </summary>
 45    public enum SessionRunnerResetReason
 46    {
 47        /// <summary>
 48        /// 尚未发生正式重建。
 49        /// </summary>
 50        None = 0,
 51
 52        /// <summary>
 53        /// 宿主显式调用 ResetRuntime()。
 54        /// </summary>
 55        HostRequested = 1
 56    }
 57
 58    /// <summary>
 59    /// SessionRunner 的失败类别。
 60    /// </summary>
 61    public enum SessionRunnerFailureKind
 62    {
 63        /// <summary>
 64        /// 启动阶段失败。
 65        /// </summary>
 66        Start = 0,
 67
 68        /// <summary>
 69        /// 固定帧推进失败。
 70        /// </summary>
 71        Step = 1,
 72
 73        /// <summary>
 74        /// 停止阶段失败。
 75        /// </summary>
 76        Stop = 2,
 77
 78        /// <summary>
 79        /// 重建阶段失败。
 80        /// </summary>
 81        Reset = 3,
 82
 83        /// <summary>
 84        /// 生命周期钩子失败。
 85        /// </summary>
 86        LifecycleHook = 4,
 87
 88        /// <summary>
 89        /// 释放阶段失败。
 90        /// </summary>
 91        Dispose = 5
 92    }
 93
 94    /// <summary>
 95    /// SessionRunner 的最后一次失败快照。
 96    /// </summary>
 97    public sealed class SessionRunnerFailureInfo
 98    {
 399        public SessionRunnerFailureInfo(SessionRunnerFailureKind kind, string operationName, Exception exception)
 100        {
 3101            if (string.IsNullOrWhiteSpace(operationName))
 102            {
 0103                throw new ArgumentException("Operation name cannot be null or whitespace.", nameof(operationName));
 104            }
 105
 3106            Kind = kind;
 3107            OperationName = operationName;
 3108            Exception = exception ?? throw new ArgumentNullException(nameof(exception));
 3109        }
 110
 111        /// <summary>
 112        /// 失败类别。
 113        /// </summary>
 3114        public SessionRunnerFailureKind Kind { get; }
 115
 116        /// <summary>
 117        /// 失败所在操作名。
 118        /// </summary>
 3119        public string OperationName { get; }
 120
 121        /// <summary>
 122        /// 原始异常。
 123        /// </summary>
 0124        public Exception Exception { get; }
 125    }
 126
 127    /// <summary>
 128    /// SessionRunner 的宿主生命周期钩子集合。
 129    /// 仅用于补齐纯 C# 宿主边界,不引入额外异步或平台外壳。
 130    /// </summary>
 131    public sealed class SessionRunnerLifecycleHooks
 132    {
 133        /// <summary>
 134        /// 新 runtime 创建完成后调用。
 135        /// 此时 Context configurator 与系统装配已完成,适合挂接宿主级共享服务。
 136        /// </summary>
 137        public Action<SessionRunner, SessionRuntime>? RuntimeCreated { get; set; }
 138
 139        /// <summary>
 140        /// 启动前调用。
 141        /// </summary>
 142        public Action<SessionRunner>? BeforeStart { get; set; }
 143
 144        /// <summary>
 145        /// 启动成功后调用。
 146        /// </summary>
 147        public Action<SessionRunner>? AfterStart { get; set; }
 148
 149        /// <summary>
 150        /// 停止前调用。
 151        /// </summary>
 152        public Action<SessionRunner, SessionRunnerShutdownCause>? BeforeStop { get; set; }
 153
 154        /// <summary>
 155        /// 停止成功后调用。
 156        /// </summary>
 157        public Action<SessionRunner, SessionRunnerShutdownCause>? AfterStop { get; set; }
 158
 159        /// <summary>
 160        /// 重建前调用。
 161        /// </summary>
 162        public Action<SessionRunner, SessionRunnerResetReason>? BeforeReset { get; set; }
 163
 164        /// <summary>
 165        /// 重建成功后调用。
 166        /// </summary>
 167        public Action<SessionRunner, SessionRunnerResetReason>? AfterReset { get; set; }
 168
 169        /// <summary>
 170        /// 生命周期失败后调用。
 171        /// </summary>
 172        public Action<SessionRunner, SessionRunnerFailureInfo>? Failure { get; set; }
 173
 174        internal SessionRunnerLifecycleHooks Clone()
 175        {
 176            return new SessionRunnerLifecycleHooks
 177            {
 178                RuntimeCreated = RuntimeCreated,
 179                BeforeStart = BeforeStart,
 180                AfterStart = AfterStart,
 181                BeforeStop = BeforeStop,
 182                AfterStop = AfterStop,
 183                BeforeReset = BeforeReset,
 184                AfterReset = AfterReset,
 185                Failure = Failure
 186            };
 187        }
 188    }
 189}