using FisTools; using System; using System.Diagnostics; using System.Linq; using System.Threading; namespace fis.Loader.Handlers { /// /// 命令处理器基类 /// internal abstract class BaseHandler { private int _currentProcessId; internal BaseHandler(LaunchMethodEnum method) { Method = method; } protected int CurrentProcessId { get { if (_currentProcessId == 0) { var currentProcess = Process.GetCurrentProcess(); _currentProcessId = currentProcess.Id; } return _currentProcessId; } } protected void KillDamon() { ToolManager.Instance.LoaderCenter.KillProcessWithGivenName("loader", false); } protected void StartDamon(string fileName,string fisFileDir) { try { if (IsCartSystemVersion) { while (true) { var process = Process.GetProcessesByName("fis").FirstOrDefault(); var loaderCount = Process.GetProcessesByName("loader").Length; if (process == null && loaderCount==1) { ToolManager.Instance.LoaderCenter.StartProcessWithWorkingDirectory(fileName, fisFileDir); } Thread.Sleep(3000); } } } catch (Exception ex) { Logger.WriteLine($"Error happened while start damon {ex}"); } } protected bool IsCartSystemVersion { get { var cartSystem = Environment.GetEnvironmentVariable("CartSystem"); if (!string.IsNullOrWhiteSpace(cartSystem)) { return true; } return false; } } /// /// 启动方式 /// internal LaunchMethodEnum Method { get; private set; } /// /// 执行命令 /// internal abstract void Execute(); protected void KillApp() { ToolManager.Instance.LoaderCenter.KillProcessWithGivenName("fis"); } } }