commit | 7db90f85364144eb86833d7be2be265e0b5346ab | [log] [tgz] |
---|---|---|
author | Luke-Roy-IBM <83647952+Luke-Roy-IBM@users.noreply.github.com> | Mon Oct 10 15:48:50 2022 +0200 |
committer | GitHub <noreply@github.com> | Mon Oct 10 09:48:50 2022 -0400 |
tree | f2c5e1b276f31da65c062f2b9ad88faab0c5cba1 | |
parent | 24995db0aea0c92b6ff6f56915205394e5c45771 [diff] |
Update travis build vm dist form xenial to focal This bings the machines to the build VM to a more up to date Ubuntu version which should also reduce the risk of loosing support for the version and use openjdk11 (#67)
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); } } }