diff --git a/Netch/Controllers/Guard.cs b/Netch/Controllers/Guard.cs index 691e174ecd..06cdf93b08 100644 --- a/Netch/Controllers/Guard.cs +++ b/Netch/Controllers/Guard.cs @@ -24,7 +24,7 @@ public abstract class Guard /// /// 日志文件(重定向输出文件) /// - private string LogPath => Path.Combine(Global.NetchDir, $"logging\\{Name}.log"); + protected string LogPath => Path.Combine(Global.NetchDir, $"logging\\{Name}.log"); /// /// 成功启动关键词 @@ -164,24 +164,40 @@ protected void StartInstanceAuto(string argument, ProcessPriorityClass priority switch (State) { case State.Started: + OnKeywordStarted(); return; case State.Stopped: Stop(); - Utils.Utils.Open(LogPath); + OnKeywordStopped(); throw new MessageException($"{Name} 控制器启动失败"); } } Stop(); + OnKeywordTimeout(); throw new MessageException($"{Name} 控制器启动超时"); } + protected virtual void OnKeywordStarted() + { + } + + protected virtual void OnKeywordTimeout() + { + } + + protected virtual void OnKeywordStopped() + { + Utils.Utils.Open(LogPath); + throw new MessageException($"{Name} 控制器启动失败"); + } + private void OnExited(object sender, EventArgs e) { State = State.Stopped; } - protected void ReadOutput(TextReader reader) + protected virtual void ReadOutput(TextReader reader) { string? line; while ((line = reader.ReadLine()) != null)