|
| 1 | +# executor-php |
| 2 | +Script Task Executor Engine with Mono Runtime to support C# |
| 3 | + |
| 4 | +This docker image provides a sandboxed protected environment to run custom C# "scripts" that are written in ProcessMaker BPM. |
| 5 | +User created script tasks should be isolated however have utilities available to them in order to get most common tasks done. This |
| 6 | +.net core environment has a C# Solution Skeleton that includes the following libraries: |
| 7 | + |
| 8 | +- Newtonsoft.Json 12.0.2 |
| 9 | +- TODO : Identify most common libraries used for existing script tasks |
| 10 | + |
| 11 | +## How to use |
| 12 | +The execution requires a data.json, config.json and an output.json file be present on the host system. The data.json represents the |
| 13 | +Request instance data. The config.json represents configuration specific for this Script Task. And the output.json should be a blank |
| 14 | +file that will be populated by the successful output of the script task. The script task is represented by a Script.cs file. |
| 15 | +It is the responsibility of the caller to have these files prepared before executing the engine via command line (or docker API). |
| 16 | + |
| 17 | +## Script Task design |
| 18 | +When writing a Script Task, three variables are available. They are: |
| 19 | + |
| 20 | +- data - A dynamic object that represents the current Request data |
| 21 | +- config - A dynamic object that represents the current Script Task configuration |
| 22 | +- output - A dynamic object you can populate with your desired JSON changes. See: https://www.newtonsoft.com/json/help/html/CreateJsonDynamic.htm |
| 23 | + |
| 24 | +Your script must extend the BaseScript class. The method signature is: |
| 25 | +```csharp |
| 26 | +public abstract void Execute(dynamic data, dynamic config, dynamic output) |
| 27 | +``` |
| 28 | +Your script can read JSON properties from data aond config. Then it can populate the dynamic output object with whatever JSON data you wish to output. |
| 29 | + Once the script is complete, the final output to console will be used and converted to JSON which |
| 30 | +will be stored in the output.json file. Once the docker execution is complete, you should evaluate the return code of the docker execution. |
| 31 | +If the code is 0, then the script task executed successfully and you can read output.json for the valid output. If it is non-zero, |
| 32 | +then you should review STDERR to see the error that was displayed during execution. |
| 33 | + |
| 34 | +### Example data.json |
| 35 | +```json |
| 36 | +{ |
| 37 | + "firstname": "Taylor" |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +### Example Script Task |
| 42 | +```csharp |
| 43 | +public class Script : BaseScript |
| 44 | +{ |
| 45 | + public override void Execute(dynamic data, dynamic config, dynamic output) |
| 46 | + { |
| 47 | + output.firstname = ((string)data.firstname).ToUpper(); |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +### Example output.json |
| 53 | +```json |
| 54 | +{"firstname":"TAYLOR"} |
| 55 | +``` |
| 56 | + |
| 57 | +## Command Line Usage |
| 58 | +```bash |
| 59 | +$ docker run -v <path to local data.json>:/opt/executor/data.json \ |
| 60 | + -v <path to local config.json>:/opt/executor/config.json \ |
| 61 | + -v <path to local Script.cs>:/opt/executor/Script.cs \ |
| 62 | + -v <path to local output.json>:/opt/executor/output.json \ |
| 63 | + processmaker/executor:csharp \ |
| 64 | + "dotnet run" |
| 65 | +``` |
0 commit comments