|
@@ -1,5 +1,9 @@
|
|
|
|
|
|
using FisTools;
|
|
|
+using System;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.Linq;
|
|
|
+using System.Threading;
|
|
|
|
|
|
namespace fis.Loader.Handlers
|
|
|
{
|
|
@@ -8,11 +12,65 @@ namespace fis.Loader.Handlers
|
|
|
/// </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>
|