Skip to content

Commit

Permalink
Merge pull request #253 from NoxOrg/feature/upper-case-plugin
Browse files Browse the repository at this point in the history
- added upper case plugin
  • Loading branch information
jan-schutte committed Jun 19, 2024
2 parents 4147154 + 97f11ae commit ac70646
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/Nox.Cli.Plugins/Nox.Cli.Plugin.Core/CoreToUpperCase_v1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Nox.Cli.Abstractions;
using Nox.Cli.Abstractions.Extensions;

namespace Nox.Cli.Plugin.Core;

public class CoreToUpperCase_v1: INoxCliAddin
{
public NoxActionMetaData Discover()
{
return new NoxActionMetaData
{
Name = "core/to-upper-case@v1",
Author = "Jan Schutte",
Description = "Convert a string to upper case.",

Inputs =
{
["source-string"] = new NoxActionInput {
Id = "source-string",
Description = "The source string which to convert to upper case",
Default = string.Empty,
IsRequired = true
}
},

Outputs =
{
["result"] = new NoxActionOutput
{
Id = "result",
Description = "The resulting upper case string."
},
}
};
}

private string? _source;

public Task BeginAsync(IDictionary<string, object> inputs)
{
_source = inputs.Value<string>("source-string");
return Task.CompletedTask;
}

public Task<IDictionary<string, object>> ProcessAsync(INoxWorkflowContext ctx)
{
var outputs = new Dictionary<string, object>();

ctx.SetState(ActionState.Error);

if (string.IsNullOrEmpty(_source))
{
ctx.SetErrorMessage("The Core to-upper-case action was not initialized");
}
else
{
try
{
outputs["result"] = _source.ToUpper();
ctx.SetState(ActionState.Success);
}
catch (Exception ex)
{
ctx.SetErrorMessage(ex.Message);
}
}

return Task.FromResult<IDictionary<string, object>>(outputs);
}

public Task EndAsync()
{
return Task.CompletedTask;
}
}

0 comments on commit ac70646

Please sign in to comment.