123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
-
- using FisTools;
- using System;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading;
- namespace fis.Loader.Handlers
- {
- /// <summary>
- /// 命令处理器基类
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// 启动方式
- /// </summary>
- internal LaunchMethodEnum Method { get; private set; }
- /// <summary>
- /// 执行命令
- /// </summary>
- internal abstract void Execute();
- protected void KillApp()
- {
- ToolManager.Instance.LoaderCenter.KillProcessWithGivenName("fis");
- }
- }
- }
|