commit | 24995db0aea0c92b6ff6f56915205394e5c45771 | [log] [tgz] |
---|---|---|
author | ningyougang <415622920@qq.com> | Tue Aug 16 15:25:56 2022 +0800 |
committer | GitHub <noreply@github.com> | Tue Aug 16 15:25:56 2022 +0800 |
tree | 34b79a0b85785eb8b835e4b0bf0c53349f07a469 | |
parent | fdfe9c860b6d6e637fe09c915757fe88f9309c32 [diff] |
Support array result include sequence action (#65) * Support array result * Add test case * Add another test case * Add document for support array result
Create a C# project called Apache.OpenWhisk.Example.Dotnet:
dotnet new classlib -n Apache.OpenWhisk.Example.Dotnet -lang "C#" cd Apache.OpenWhisk.Example.Dotnet
Install the Newtonsoft.Json NuGet package as follows:
dotnet add package Newtonsoft.Json -v 12.0.1
Now create a file called Hello.cs
with the following content:
using System; using Newtonsoft.Json.Linq; namespace Apache.OpenWhisk.Example.Dotnet { public class Hello { public JObject Main(JObject args) { string name = "stranger"; if (args.ContainsKey("name")) { name = args["name"].ToString(); } JObject message = new JObject(); message.Add("greeting", new JValue($"Hello, {name}!")); return (message); } } }
Publish the project as follows:
dotnet publish -c Release -o out
Zip the published files as follows:
cd out zip -r -0 helloDotNet.zip *
Create the action
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --kind dotnet:2.2
For the return result, not only support dictionary
but also support array
So a very simple hello array
function would be:
using System; using Newtonsoft.Json.Linq; namespace Apache.OpenWhisk.Tests.Dotnet { public class HelloArray { public JArray Main(JObject args) { JArray jarray = new JArray(); jarray.Add("a"); jarray.Add("b"); return (jarray); } } }
And support array result for sequence action as well, the first action‘s array result can be used as next action’s input parameter.
So the function can be:
using System; using Newtonsoft.Json.Linq; namespace Apache.OpenWhisk.Tests.Dotnet { public class HelloPassArrayParam { public JArray Main(JArray args) { return (args); } } }