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 08d5a65 commit 72b6197
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
using NewLife.Agent;
using NewLife.Agent.Command;

namespace Zero.Agent
namespace Zero.Agent.CommandHandler
{
public class TestCommandHandler : BaseCommandHandler
public class Test : BaseCommandHandler
{
public override String Cmd { get; set; } = "-test";
public override String Description { get; set; } = "测试自定义菜单";
public override Char? ShortcutKey { get; set; } = 't';

public TestCommandHandler(ServiceBase service) : base(service)
public Test(ServiceBase service) : base(service)
{
//本功能主要是用于演示如何定义自己的命令处理器,所有命令处理器必需指定Cmd和Description,
//ShortcutKey用于定义快捷键,如果不需要快捷键,可以不指定,将不会显示在菜单中
Expand All @@ -35,17 +35,13 @@ public override void Process(String[] args)
for (var i = 1; i <= 9; i++)
{
for (var j = 1; j <= i; j++)
{
Console.Write($"{j}x{i}={i * j}\t");
}
Console.WriteLine();
Thread.Sleep(200);
}

if (args.Contains("-showme"))
{
Console.WriteLine("这是[测试自定义菜单]处理程序,显示了自定义参数 -showme");
}
}
}
}
37 changes: 37 additions & 0 deletions Zero.Agent/CommandHandler/TransferCall.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Linq;
using System.Threading;
using NewLife.Agent;
using NewLife.Agent.Command;

namespace Zero.Agent.CommandHandler
{
public class TransferCall : BaseCommandHandler
{
public override String Cmd { get; set; } = "-TransferCall";
public override String Description { get; set; } = "测试转调用其他命令";
public override Char? ShortcutKey { get; set; } = 'w';

public TransferCall(ServiceBase service) : base(service)
{
//本功能主要是用于演示如何转调用其他命令处理器,并且可以传入自定义参数
}

public override Boolean IsShowMenu()
{
return true;
}

public override void Process(String[] args)
{
Console.WriteLine("这是[测试转调用其他命令]处理程序");
Thread.Sleep(1000);
Console.WriteLine("以下开始转调用 [测试自定义菜单],还可以传入自定义参数");
Service.Command.Handle("-test", args.Concat(new[] { "-showme" }).ToArray());
Thread.Sleep(1000);
Console.WriteLine("以下开始转调用 [显示状态]");
Service.Command.Handle(CommandConst.ShowStatus, args);
Console.WriteLine("转调用 [测试自定义菜单] 已执行完毕。");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using System;
using System.Threading;
using NewLife.Agent;
using NewLife.Agent.Command;
using NewLife.Agent.CommandHandler;

namespace Zero.Agent
namespace Zero.Agent.CommandHandler
{
/// <summary>
/// WEB服务看门狗命令处理器
/// </summary>
public class WebWatchDogCommandHandler : WatchDogCommandHandler
public class WebWatchDog : WatchDog
{
public override String Description { get; set; } = "WEB看门狗保护服务";

public WebWatchDogCommandHandler(ServiceBase service) : base(service)
public WebWatchDog(ServiceBase service) : base(service)
{
//本功能主要是用于演示如何覆盖默认的看门狗保护服务,实现自己的看门狗逻辑,其他需要覆盖基础命令处理器也可以参照这个类实现
}

public override void Process(String[] args)
{
Console.WriteLine("这是[WEB看门狗保护服务]处理程序,开始检查WEB服务是否可以正常访问");
this.CheckWatchDog();
CheckWatchDog();
}

public override void CheckWatchDog()
Expand Down

0 comments on commit 72b6197

Please sign in to comment.