From e5a968f5813a9c48383a31ea92928f4826ff9232 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Thu, 4 Mar 2021 04:57:05 +0800 Subject: [PATCH] Update Guard --- Netch/Controllers/Guard.cs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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)