public NFController() { Name = "Redirector"; MainFile = "Redirector.exe"; StartedKeywords.Add("Started"); StoppedKeywords.AddRange(new[] { "Failed", "Unable" }); }
public SSRController() { Name = "ShadowsocksR"; MainFile = "ShadowsocksR.exe"; StartedKeywords.Add("listening at"); StoppedKeywords.AddRange(new[] { "Invalid config path", "usage" }); }
public TUNTAPController() { Name = "tun2socks"; MainFile = "tun2socks.exe"; StartedKeywords.Add("Running"); StoppedKeywords.AddRange(new[] { "failed", "invalid vconfig file" }); }
public SSController() { Name = "Shadowsocks"; MainFile = "Shadowsocks.exe"; StartedKeywords.Add("listening at"); StoppedKeywords.AddRange(new[] { "Invalid config path", "usage", "plugin service exit unexpectedly" }); }
public VMessController() { Name = "V2Ray"; MainFile = "v2ray.exe"; StartedKeywords.Add("started"); StoppedKeywords.AddRange(new[] {"config file not readable", "failed to"}); }
private void ReadOutput(TextReader reader) { string?line; while ((line = reader.ReadLine()) != null) { _logStreamWriter !.WriteLine(line); OnReadNewLine(line); if (State == State.Starting) { if (StartedKeywords.Any(s => line.Contains(s))) { State = State.Started; } else if (FailedKeywords.Any(s => line.Contains(s))) { OnStartFailed(); State = State.Stopped; } } } State = State.Stopped; }
public TrojanController() { Name = "Trojan"; MainFile = "Trojan.exe"; StartedKeywords.Add("started"); StoppedKeywords.Add("exiting"); }
protected async Task StartGuardAsync(string argument, ProcessPriorityClass priority = ProcessPriorityClass.Normal) { State = State.Starting; _logFileStream = new FileStream(LogPath, FileMode.Create, FileAccess.Write, FileShare.Read, 4096, true); _logStreamWriter = new StreamWriter(_logFileStream) { AutoFlush = true }; Instance.StartInfo.Arguments = argument; Instance.Start(); Global.Job.AddProcess(Instance); if (priority != ProcessPriorityClass.Normal) { Instance.PriorityClass = priority; } if (RedirectOutput) { ReadOutputAsync(Instance.StandardOutput).Forget(); ReadOutputAsync(Instance.StandardError).Forget(); if (!StartedKeywords.Any()) { // Skip, No started keyword State = State.Started; return; } // wait ReadOutput change State for (var i = 0; i < 1000; i++) { await Task.Delay(50); switch (State) { case State.Started: OnStarted(); return; case State.Stopped: await StopGuardAsync(); OnStartFailed(); throw new MessageException($"{Name} 控制器启动失败"); } } await StopGuardAsync(); throw new MessageException($"{Name} 控制器启动超时"); } }
public TrojanController() { StartedKeywords.Add("started"); StoppedKeywords.Add("exiting"); }
public VMessController() { StartedKeywords.Add("started"); StoppedKeywords.AddRange(new[] { "config file not readable", "failed to" }); }
public TUNTAPController() { StartedKeywords.Add("Running"); StoppedKeywords.AddRange(new[] { "failed", "invalid vconfig file" }); }