Skip to content

Commit

Permalink
重新归类CommandHandler目录
Browse files Browse the repository at this point in the history
  • Loading branch information
andywu188 committed May 20, 2024
1 parent cb4d34f commit 08d5a65
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using NewLife.Model;
using NewLife.Agent.Command;
using NewLife.Model;

namespace NewLife.Agent.Command;
namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 安装服务命令处理类
/// </summary>
public class InstallCommandHandler : BaseCommandHandler
public class Install : BaseCommandHandler
{
/// <summary>
/// 安装服务构造函数
/// </summary>
/// <param name="service"></param>
public InstallCommandHandler(ServiceBase service) : base(service)
public Install(ServiceBase service) : base(service)
{
}

Expand All @@ -32,18 +33,10 @@ public override Boolean IsShowMenu()

/// <inheritdoc/>
public override void Process(String[] args)
{
Install();
// 稍微等一下,以便后续状态刷新
Thread.Sleep(500);
}

private void Install()
{
var exe = GetExeName();

// 兼容dotnet
var args = Environment.GetCommandLineArgs();
if (args.Length >= 1)
{
var fileName = Path.GetFileName(exe);
Expand All @@ -67,18 +60,19 @@ private void Install()
// 跳过系统内置参数
var list = new List<String>();
for (var i = 2; i < args.Length; i++)
{
if (args[i].EqualIgnoreCase("-server", "-user", "-group"))
i++;
else if (args[i].Contains(' '))
list.Add($"\"{args[i]}\"");
else
list.Add(args[i]);
}
if (list.Count > 0) arg += " " + list.Join(" ");
}

Service.Host.Install(Service.ServiceName, Service.DisplayName, exe, arg, Description);

// 稍微等一下,以便后续状态刷新
Thread.Sleep(500);
}

/// <summary>Exe程序名</summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using NewLife.Log;
using NewLife.Agent.Command;
using NewLife.Log;

namespace NewLife.Agent.Command;
namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 安装并启动服务命令处理类
/// </summary>
public class InstallAndStartCommandHandler : BaseCommandHandler
public class InstallAndStart : BaseCommandHandler
{
/// <summary>
/// 安装并启动服务构造函数
/// </summary>
/// <param name="service"></param>
public InstallAndStartCommandHandler(ServiceBase service) : base(service)
public InstallAndStart(ServiceBase service) : base(service)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using System.Xml.Linq;
using NewLife.Agent.Command;
using NewLife.Log;
using NewLife.Model;

namespace NewLife.Agent.Command;
namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 重新安装服务命令处理类
/// </summary>
public class ReinstallCommandHandler : BaseCommandHandler
public class Reinstall : BaseCommandHandler
{
/// <summary>
/// 重新安装服务构造函数
/// </summary>
/// <param name="service"></param>
public ReinstallCommandHandler(ServiceBase service) : base(service)
public Reinstall(ServiceBase service) : base(service)
{
}

Expand All @@ -28,13 +29,6 @@ public ReinstallCommandHandler(ServiceBase service) : base(service)

/// <inheritdoc/>
public override void Process(String[] args)
{
Reinstall(args);

// 稍微等一下,以便后续状态刷新
Thread.Sleep(500);
}
private void Reinstall(String[] args)
{
try
{
Expand All @@ -55,5 +49,8 @@ private void Reinstall(String[] args)
Thread.Sleep(100);
}
Service.Host.Start(Service.ServiceName);

// 稍微等一下,以便后续状态刷新
Thread.Sleep(500);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
namespace NewLife.Agent.Command;
using NewLife.Agent.Command;

namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 卸载服务命令处理类
/// </summary>
public class RemoveCommandHandler : BaseCommandHandler
public class Remove : BaseCommandHandler
{
/// <summary>
/// 卸载服务构造函数
/// </summary>
/// <param name="service"></param>
public RemoveCommandHandler(ServiceBase service) : base(service)
public Remove(ServiceBase service) : base(service)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
namespace NewLife.Agent.Command;
using NewLife.Agent.Command;

namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 重启服务命令处理类
/// </summary>
public class RestartCommandHandler : BaseCommandHandler
public class Restart : BaseCommandHandler
{
/// <summary>
/// 重启服务构造函数
/// </summary>
/// <param name="service"></param>
public RestartCommandHandler(ServiceBase service) : base(service)
public Restart(ServiceBase service) : base(service)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
namespace NewLife.Agent.Command;
using NewLife.Agent.Command;

namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 执行服务命令处理类
/// </summary>
public class RunServiceCommandHandler : BaseCommandHandler
public class RunService : BaseCommandHandler
{
/// <summary>
/// 执行服务构造函数
/// </summary>
/// <param name="service"></param>
public RunServiceCommandHandler(ServiceBase service) : base(service)
public RunService(ServiceBase service) : base(service)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System.Xml.Linq;
using NewLife.Agent.Command;

namespace NewLife.Agent.Command;
namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 模拟运行命令处理类
/// </summary>
public class RunSimulationCommandHandler : BaseCommandHandler
public class RunSimulation : BaseCommandHandler
{
/// <summary>
/// 模拟运行构造函数
/// </summary>
/// <param name="service"></param>
public RunSimulationCommandHandler(ServiceBase service) : base(service)
public RunSimulation(ServiceBase service) : base(service)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using NewLife.Log;
using NewLife.Agent.Command;
using NewLife.Log;
using NewLife.Reflection;
using System.Reflection;

namespace NewLife.Agent.Command;
namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 显示状态命令处理类
/// </summary>
public class ShowStatusCommandHandler : BaseCommandHandler
public class ShowStatus : BaseCommandHandler
{
/// <summary>
/// 显示状态构造函数
/// </summary>
/// <param name="service"></param>
public ShowStatusCommandHandler(ServiceBase service) : base(service)
public ShowStatus(ServiceBase service) : base(service)
{
}

Expand Down Expand Up @@ -56,7 +57,6 @@ public override void Process(String[] args)

// 执行文件路径
if (installed)
{
try
{
var cfg = Service.Host.QueryConfig(name);
Expand All @@ -66,7 +66,6 @@ public override void Process(String[] args)
{
if (XTrace.Log.Level <= LogLevel.Debug) XTrace.Log.Debug("", ex);
}
}

var asm = AssemblyX.Create(Assembly.GetExecutingAssembly());
Console.WriteLine();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
namespace NewLife.Agent.Command;
using NewLife.Agent.Command;

namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 启动服务命令处理类
/// </summary>
public class StartCommandHandler : BaseCommandHandler
public class Start : BaseCommandHandler
{
/// <summary>
/// 启动服务构造函数
/// </summary>
/// <param name="service"></param>
public StartCommandHandler(ServiceBase service) : base(service)
public Start(ServiceBase service) : base(service)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
namespace NewLife.Agent.Command;
using NewLife.Agent.Command;

namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 停止服务命令处理类
/// </summary>
public class StopCommandHandler : BaseCommandHandler
public class Stop : BaseCommandHandler
{
/// <summary>
/// 停止服务构造函数
/// </summary>
/// <param name="service"></param>
public StopCommandHandler(ServiceBase service) : base(service)
public Stop(ServiceBase service) : base(service)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using NewLife.Log;
using NewLife.Agent.Command;
using NewLife.Log;

namespace NewLife.Agent.Command;
namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 停止并卸载服务命令处理类
/// </summary>
public class UninstallCommandHandler : BaseCommandHandler
public class Uninstall : BaseCommandHandler
{
/// <summary>
/// 停止并卸载服务构造函数
/// </summary>
/// <param name="service"></param>
public UninstallCommandHandler(ServiceBase service) : base(service)
public Uninstall(ServiceBase service) : base(service)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using NewLife.Log;
using NewLife.Agent.Command;
using NewLife.Log;
using NewLife.Model;

namespace NewLife.Agent.Command;
namespace NewLife.Agent.CommandHandler;

/// <summary>
/// 看门狗命令处理类
/// </summary>
public class WatchDogCommandHandler : BaseCommandHandler
public class WatchDog : BaseCommandHandler
{
/// <summary>
/// 看门狗构造函数
/// </summary>
/// <param name="service"></param>
public WatchDogCommandHandler(ServiceBase service) : base(service)
public WatchDog(ServiceBase service) : base(service)
{
}

Expand All @@ -38,7 +39,7 @@ public override Boolean IsShowMenu()
public override void Process(String[] args)
{
CheckWatchDog();

}

/// <summary>检查看门狗。</summary>
Expand All @@ -49,7 +50,6 @@ public override void Process(String[] args)
public virtual void CheckWatchDog()
{
foreach (var item in WatchDogs)
{
// 已安装未运行
if (!Service.Host.IsInstalled(item))
XTrace.WriteLine("未发现服务{0},是否已安装?", item);
Expand All @@ -59,6 +59,5 @@ public virtual void CheckWatchDog()

Service.Host.Start(item);
}
}
}
}

0 comments on commit 08d5a65

Please sign in to comment.