Skip to content

Commit 0250b6b

Browse files
Merge branch 'master' into develop
2 parents 746d71e + 363a989 commit 0250b6b

File tree

151 files changed

+6908
-2263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+6908
-2263
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
# InEngine.NET 3
1+
# InEngine.NET
2+
3+
A plugin-based, distributed command queuing and scheduling server.
4+
5+
![InEngine Command List](https://raw.githubusercontent.com/InEngine-NET/InEngine.NET/master/docs-src/images/commands.png)
26

docs-src/commands.md

Lines changed: 102 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Commands
22

3-
Commands are the fundamental abstraction used to run custom logic.
3+
Commands can be C# classes, lambda expressions, or CLI programs.
4+
They can be queued, scheduled, or run from the command line.
45

56
## Create a Command
67

7-
The InEngine.Core package is required. Install it into your own Visual Studio project.
8+
The InEngine.Core package is required to create a C# class command.
9+
Install it in a Visual Studio project.
810

911
**Package Manager**
1012
```bash
@@ -26,26 +28,7 @@ dotnet add package InEngine.Core
2628
paket add InEngine.Core
2729
```
2830

29-
Adding a class that implements **InEngine.Core.ICommand** is the simplest way to create a command.
30-
31-
```c#
32-
using System;
33-
using InEngine.Core;
34-
35-
namespace MyCommandPlugin
36-
{
37-
public class MyCommand : ICommand
38-
{
39-
public void Run()
40-
{
41-
Console.WriteLine("Hello, world!");
42-
}
43-
}
44-
}
45-
```
46-
47-
A command that implements ICommand can be run directly or [queued](queuing), but it cannot be [scheduled](scheduling).
48-
Extending the **InEngine.Core.AbstractCommand** class adds extra functionality, like a progress bar, and the ability to schedule the command using the scheduler.
31+
To create a class command, extend the **InEngine.Core.AbstractCommand** class.
4932
Minimally, the Run method should be overridden.
5033

5134
```c#
@@ -66,10 +49,10 @@ namespace MyCommandPlugin
6649

6750
## Run a Command
6851

69-
Create a class that implements **InEngine.Core.IOptions** in the same assembly as the command class.
70-
Add a VerbOptions attribute, from the CommandLine namespace, that defines the name of the command.
71-
Optional help text can also be specified in the VerbOption attribute.
72-
The help text can be auto-generated from the attribute or manually specified in the GetUsage method if desired.
52+
Create a class that extends **InEngine.Core.AbstractPlugin** in the same assembly as the command class.
53+
Add a VerbOptions attribute, from the **CommandLine** namespace, that defines the name of the command.
54+
55+
This class registers a command in the MyPlugin assembly called "mycommand":
7356

7457
```c#
7558
using CommandLine;
@@ -78,135 +61,26 @@ using InEngine.Core;
7861

7962
namespace MyCommandPlugin
8063
{
81-
public class MyOptions : IOptions
64+
public class MyPlugin : AbstractPlugin
8265
{
83-
[VerbOption("my-command", HelpText="My example command.")]
66+
[VerbOption("mycommand", HelpText="My example command.")]
8467
public MyCommand MyCommand { get; set; }
85-
86-
[HelpVerbOption]
87-
public string GetUsage(string verb)
88-
{
89-
return HelpText.AutoBuild(this, verb);
90-
}
9168
}
9269
}
9370
```
9471

9572
Download the InEngine binary distribution, from the [GitHub Releases](https://github.com/InEngine-NET/InEngine.NET/releases) page, that matches the version of the InEngine.Core package you included.
9673

9774
Copy your project's DLLs into the Plugins subdirectory included in the binary distribution.
98-
Add your plugin to the ["Plugins" list in appsettings.config](configuration) at the root of the binary distribution.
75+
Add your plugin to the "Plugins" list in [appsettings.config](configuration) at the root of the binary distribution.
9976

10077
Run your command:
10178

10279
```bash
103-
inengine.exe -pMyCommandPlugin my-command
104-
```
105-
106-
### Executing Arbitrary Processes
107-
108-
It isn't necessary to create C# classes to utilize InEngine.NET.
109-
Arbitrary commands can be run, with an argument list by leveraging the InEngine.Core plugin's **proc** command.
110-
The command lists directory contents using "ls" with the "-lhp" switches:
111-
112-
```bash
113-
inengine.exe -pInEngine.Core proc -c"/bin/ls" -a"-lhp"
114-
```
115-
116-
## View Available Plugins
117-
118-
Run inengine.exe without any arguments to see a list of plugins:
119-
120-
```text
121-
___ _____ _ _ _ _____ _____
122-
|_ _|_ __ | ____|_ __ __ _(_)_ __ ___ | \ | | ____|_ _|
123-
| || '_ \| _| | '_ \ / _` | | '_ \ / _ \ | \| | _| | |
124-
| || | | | |___| | | | (_| | | | | | __/_| |\ | |___ | |
125-
|___|_| |_|_____|_| |_|\__, |_|_| |_|\___(_|_| \_|_____| |_|
126-
|___/
127-
128-
Usage:
129-
InEngine 3.x
130-
Copyright © 2017 Ethan Hann
131-
132-
p, plugin Plug-In to activate.
133-
134-
s, scheduler Run the scheduler.
135-
136-
c, configuration (Default: ./appsettings.json) The path to the
137-
configuration file.
138-
139-
140-
Plugins:
141-
InEngine.Core
142-
```
143-
144-
## View Commands in a Plugin
145-
146-
Run inengine.exe with only the plugin specified:
147-
148-
```bash
149-
inengine.exe -pInEngine.Core
150-
```
151-
152-
The **InEngine.Core** library is itself a plugin that contains queue-related and other commands.
153-
As an example, this is the help output for the core plugin.
154-
155-
```text
156-
___ _____ _ _ _ _____ _____
157-
|_ _|_ __ | ____|_ __ __ _(_)_ __ ___ | \ | | ____|_ _|
158-
| || '_ \| _| | '_ \ / _` | | '_ \ / _ \ | \| | _| | |
159-
| || | | | |___| | | | (_| | | | | | __/_| |\ | |___ | |
160-
|___|_| |_|_____|_| |_|\__, |_|_| |_|\___(_|_| \_|_____| |_|
161-
|___/
162-
163-
Plugin:
164-
Name: InEngine.Core
165-
Version: 3.x
166-
167-
168-
Commands:
169-
queue:publish Publish a command message to a queue.
170-
queue:consume Consume one or more command messages from the queue.
171-
queue:length Get the number of messages in the primary and secondary queues.
172-
queue:flush Clear the primary or secondary queues.
173-
queue:republish Republish failed messages to the queue.
174-
queue:peek Peek at messages in the primary or secondary queues.
175-
echo Echo some text to the console. Useful for end-to-end testing.
176-
proc Launch an arbitrary process.
177-
```
178-
179-
## Print Help Text for a Plugin's Commands
180-
181-
Run the command with the -h or --help arguments.
182-
183-
```bash
184-
inengine.exe -pInEngine.Core queue:publish -h
80+
inengine.exe mycommand
18581
```
18682

187-
The **InEngine.Core** plugin's command to clear the InEngine.NET queues produces this help message.
188-
189-
```text
190-
InEngine 3.x
191-
Copyright © 2017 Ethan Hann
192-
193-
--command-plugin Required. The name of a command plugin file, e.g.
194-
InEngine.Core.dll
195-
196-
--command-verb A plugin command verb, e.g. echo
197-
198-
--command-class A command class name, e.g.
199-
InEngine.Core.Commands.AlwaysSucceed. Takes precedence
200-
over --command-verb if both are specified.
201-
202-
--args An optional list of arguments to publish with the
203-
command.
204-
205-
--secondary (Default: False) Publish the command to the secondary
206-
queue.
207-
```
208-
209-
## Writing Output
83+
### Writing Output
21084

21185
The **InEngine.Core.AbstractCommand** class provides some helper functions to output text to the console, for example:
21286

@@ -254,27 +128,7 @@ InfoText("You have this many things: ")
254128
.NewLine(2);
255129
```
256130

257-
## Logging
258-
259-
Any exceptions thrown by a command will be logged provided NLog is configured to record errors.
260-
The [NLog configuration](https://github.com/NLog/NLog/wiki/Tutorial#configuration) file needs to be setup with something like this:
261-
262-
```xml
263-
<?xml version="1.0" encoding="utf-8" ?>
264-
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
265-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
266-
267-
<targets>
268-
<target name="logfile" xsi:type="File" fileName="inengine.log" />
269-
</targets>
270-
271-
<rules>
272-
<logger name="*" minlevel="Error" writeTo="logfile" />
273-
</rules>
274-
</nlog>
275-
```
276-
277-
## Progress Bar
131+
### Progress Bar
278132

279133
The **InEngine.Core.AbstractCommand** class provides a ProgressBar property to show command progress in a terminal.
280134
This is how it is used:
@@ -294,4 +148,90 @@ public override void Run()
294148
}
295149
}
296150
```
297-
151+
152+
### Running non-.NET Commands
153+
154+
It is not necessary to create C# classes to utilize InEngine.NET.
155+
Arbitrary external programs can be run, with an optional argument list, by leveraging the InEngine.Core plugin's **exec** command.
156+
157+
For example, create a python script called **helloworld.py**, make it executable, and add this to it:
158+
159+
```python
160+
#!/usr/bin/env python
161+
162+
print 'Hello, world!'
163+
```
164+
165+
Whitelist the helloworld.py script in the [appsettings.json](configuration) file:
166+
167+
```json
168+
{
169+
"InEngine": {
170+
// ...
171+
"ExecWhitelist": {
172+
"helloworld": "/path/to/helloworld.py"
173+
}
174+
// ...
175+
}
176+
}
177+
```
178+
179+
Now execute it with the **exec** command:
180+
181+
```bash
182+
inengine exec --executable="helloworld"
183+
```
184+
185+
If an external executable requires arguments, use the **--args** argument:
186+
187+
```bash
188+
inengine exec --executable="foo" --args="--version"
189+
```
190+
191+
## View Commands
192+
193+
Run inengine.exe with no arguments to see a list of commands:
194+
195+
```bash
196+
inengine.exe
197+
```
198+
199+
![InEngine Command List](images/commands.png)
200+
201+
202+
!!! note "InEngine.Core is a Plugin"
203+
The **InEngine.Core** library is itself a plugin that contains queueing, scheduling, and other commands.
204+
205+
206+
## View a Command's Help Text
207+
208+
Run the command with the -h or --help arguments to see help text.
209+
210+
This command prints the publish command's help text, from the core plugin:
211+
212+
```bash
213+
inengine.exe queue:publish -h
214+
```
215+
216+
The **InEngine.Core** plugin's command to clear the InEngine.NET queues produces this help message.
217+
218+
```text
219+
InEngine 3.x
220+
Copyright © 2017 Ethan Hann
221+
222+
--plugin Required. The name of a command plugin file, e.g.
223+
InEngine.Core
224+
225+
--command A command name, e.g. echo
226+
227+
--class A command class, e.g.
228+
InEngine.Core.Commands.AlwaysSucceed. Takes precedence
229+
over --command if both are specified.
230+
231+
--args An optional list of arguments to publish with the
232+
command.
233+
234+
--secondary (Default: False) Publish the command to the secondary
235+
queue.
236+
```
237+

0 commit comments

Comments
 (0)