Dignus.Commands
1.0.6
dotnet add package Dignus.Commands --version 1.0.6
NuGet\Install-Package Dignus.Commands -Version 1.0.6
<PackageReference Include="Dignus.Commands" Version="1.0.6" />
<PackageVersion Include="Dignus.Commands" Version="1.0.6" />
<PackageReference Include="Dignus.Commands" />
paket add Dignus.Commands --version 1.0.6
#r "nuget: Dignus.Commands, 1.0.6"
#:package Dignus.Commands@1.0.6
#addin nuget:?package=Dignus.Commands&version=1.0.6
#tool nuget:?package=Dignus.Commands&version=1.0.6
Dignus.Commands
Lightweight command execution system for local console and telnet remote control.
간단한 로컬 콘솔 명령 실행과 텔넷 기반 원격 명령 실행을 지원하는 커맨드 시스템입니다.
Features / 특징
English
- Attribute based command registration
- Delegate based command registration
- Async command execution
CancellationTokenbased cancellation- Middleware pipeline support
- Local console command runner
- Telnet remote command runner
Korean
- Attribute 기반 커맨드 등록
- Delegate 기반 커맨드 등록
- 비동기 커맨드 실행
CancellationToken기반 취소 지원- 미들웨어 파이프라인 지원
- 로컬 콘솔 실행 지원
- 텔넷 기반 원격 명령 실행
Quick Start
using Dignus.Commands;
var module = new LocalCommandRunner();
module.AddCommand<Close>();
module.Build();
module.Run();
Local Command Runner
Run commands directly from the local console.
로컬 콘솔에서 직접 명령을 입력받아 실행합니다.
using Dignus.Commands;
var module = new LocalCommandRunner();
module.AddCommand<Close>();
module.Build();
module.Run();
Telnet Command Runner
Start a telnet server and execute commands remotely.
텔넷 서버를 열고 외부 텔넷 클라이언트에서 접속하여 명령을 실행합니다.
using Dignus.Commands;
var module = new TelnetCommandRunner(port: 50000);
module.AddCommand<Close>();
module.Build();
module.Run();
Connect via telnet:
telnet 127.0.0.1 50000
Note
There is no dedicated telnet client module.
You connect using any telnet client.
Command Class
Create a command by implementing ICommand.
using Dignus.Commands.Attributes;
using Dignus.Commands.Interfaces;
using Dignus.Actor.Core;
using System.Diagnostics;
[Command("close")]
internal class Close : ICommand
{
public Task InvokeAsync(string[] args, IActorRef sender, CancellationToken cancellationToken)
{
Process.GetCurrentProcess().Close();
return Task.CompletedTask;
}
public string Print()
{
return "close process";
}
}
Register the command
module.AddCommand<Close>();
Delegate Command
Commands can also be registered using delegates.
module.AddCommand("loop", "loop example", TestAsync);
async Task TestAsync(string[] args, IActorRef sender, CancellationToken cancellationToken)
{
var count = 0;
while (cancellationToken.IsCancellationRequested == false)
{
sender.Post(new CommandResponseMessage()
{
Content = $"sleep : {count++}"
});
await Task.Delay(2000, cancellationToken);
}
sender.Post(new CommandResponseMessage()
{
Content = $"end sleep : {count++}"
});
}
Middleware
You can add middleware to the command execution pipeline.
module.AddMiddleware((ref CommandPipelineContext context, ref AsyncPipelineNext<CommandPipelineContext> next) =>
{
var auth = context.Command.GetType().GetCustomAttribute<AuthAttribute>();
if (auth.Execute(context) == false)
{
context.SenderActorRef.Post(new CommandResponseMessage()
{
Content = "invalid auth"
});
return Task.CompletedTask;
}
return next.InvokeAsync(ref context);
});
Command Execution Flow
User Input
│
▼
Command Parser
│
▼
Middleware Pipeline
│
▼
Command Execution
│
▼
CommandResponseMessage
Cancellation
Long running commands should support cancellation.
while (cancellationToken.IsCancellationRequested == false)
{
await Task.Delay(1000, cancellationToken);
}
If a telnet connection closes, a CancelCommandMessage will be sent.
Output Message
Send output using CommandResponseMessage.
sender.Post(new CommandResponseMessage()
{
Content = "hello"
});
Default Commands
| Command | Description |
|---|---|
? |
show command list |
Ctrl + C |
cancel running command |
Module Lifecycle
var module = new LocalCommandRunner();
module.AddCommand<Close>();
module.Build();
module.Run();
Execution order
- Create module
- Register commands
- Register middleware
Build()Run()
Run() must be called after Build().
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Dignus.ActorServer (>= 1.2.3)
-
net8.0
- Dignus.ActorServer (>= 1.2.3)
-
net9.0
- Dignus.ActorServer (>= 1.2.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.