Skip to content

Commit

Permalink
Update Guard
Browse files Browse the repository at this point in the history
  • Loading branch information
chsbuffer committed Mar 3, 2021
1 parent dc7c537 commit e5a968f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Netch/Controllers/Guard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class Guard
/// <summary>
/// 日志文件(重定向输出文件)
/// </summary>
private string LogPath => Path.Combine(Global.NetchDir, $"logging\\{Name}.log");
protected string LogPath => Path.Combine(Global.NetchDir, $"logging\\{Name}.log");

/// <summary>
/// 成功启动关键词
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e5a968f

Please sign in to comment.