Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/dotnet2.2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@
## 1.13
Changes:
- Initial release

## Release TBD
Changes:
- Support for async methods. Example:

```csharp
public async Task<JObject> MainAsync(JObject args)
{
await Task.Delay(10); // Just do a delay to have an async/await process occur.
return (args);
}
```
7 changes: 5 additions & 2 deletions core/dotnet2.2/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Init
private Type Type { get; set; }
private MethodInfo Method { get; set; }
private ConstructorInfo Constructor { get; set; }
private bool AwaitableMethod { get; set; }

public Init()
{
Expand All @@ -51,7 +52,7 @@ public async Task<Run> HandleRequest(HttpContext httpContext)
{
await httpContext.Response.WriteError("Cannot initialize the action more than once.");
Console.Error.WriteLine("Cannot initialize the action more than once.");
return (new Run(Type, Method, Constructor));
return (new Run(Type, Method, Constructor, AwaitableMethod));
}

string body = await new StreamReader(httpContext.Request.Body).ReadToEndAsync();
Expand Down Expand Up @@ -156,7 +157,9 @@ await httpContext.Response.WriteError(ex.Message

await httpContext.Response.WriteResponse(200, "OK");

return (new Run(Type, Method, Constructor));
AwaitableMethod = (Method.ReturnType.GetMethod(nameof(Task.GetAwaiter)) != null);

return (new Run(Type, Method, Constructor, AwaitableMethod));
}
catch (Exception ex)
{
Expand Down
13 changes: 11 additions & 2 deletions core/dotnet2.2/proxy/Apache.OpenWhisk.Runtime.Common/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ public class Run
private readonly Type _type;
private readonly MethodInfo _method;
private readonly ConstructorInfo _constructor;
private readonly bool _awaitableMethod;

public Run(Type type, MethodInfo method, ConstructorInfo constructor)
public Run(Type type, MethodInfo method, ConstructorInfo constructor, bool awaitableMethod)
{
_type = type;
_method = method;
_constructor = constructor;
_awaitableMethod = awaitableMethod;
}

public async Task HandleRequest(HttpContext httpContext)
Expand Down Expand Up @@ -79,7 +81,14 @@ await Console.Error.WriteLineAsync(

try
{
JObject output = (JObject) _method.Invoke(owObject, new object[] {valObject});
JObject output;

if(_awaitableMethod) {
output = (JObject) await (dynamic) _method.Invoke(owObject, new object[] {valObject});
}
else {
output = (JObject) _method.Invoke(owObject, new object[] {valObject});
}

if (output == null)
{
Expand Down
11 changes: 10 additions & 1 deletion core/dotnet3.0/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
# .NET Core 3.0 OpenWhisk Runtime Container


## 1.14 (next Apache release)
## Release TBD
Changes:
- Initial release
- Support for async methods. Example:

```csharp
public async Task<JObject> MainAsync(JObject args)
{
await Task.Delay(10); // Just do a delay to have an async/await process occur.
return (args);
}
```
7 changes: 5 additions & 2 deletions core/dotnet3.0/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Init
private Type Type { get; set; }
private MethodInfo Method { get; set; }
private ConstructorInfo Constructor { get; set; }
private bool AwaitableMethod { get; set; }

public Init()
{
Expand All @@ -51,7 +52,7 @@ public async Task<Run> HandleRequest(HttpContext httpContext)
{
await httpContext.Response.WriteError("Cannot initialize the action more than once.");
Console.Error.WriteLine("Cannot initialize the action more than once.");
return (new Run(Type, Method, Constructor));
return (new Run(Type, Method, Constructor, AwaitableMethod));
}

string body = await new StreamReader(httpContext.Request.Body).ReadToEndAsync();
Expand Down Expand Up @@ -156,7 +157,9 @@ await httpContext.Response.WriteError(ex.Message

await httpContext.Response.WriteResponse(200, "OK");

return (new Run(Type, Method, Constructor));
AwaitableMethod = (Method.ReturnType.GetMethod(nameof(Task.GetAwaiter)) != null);

return (new Run(Type, Method, Constructor, AwaitableMethod));
}
catch (Exception ex)
{
Expand Down
13 changes: 11 additions & 2 deletions core/dotnet3.0/proxy/Apache.OpenWhisk.Runtime.Common/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ public class Run
private readonly Type _type;
private readonly MethodInfo _method;
private readonly ConstructorInfo _constructor;
private readonly bool _awaitableMethod;

public Run(Type type, MethodInfo method, ConstructorInfo constructor)
public Run(Type type, MethodInfo method, ConstructorInfo constructor, bool awaitableMethod)
{
_type = type;
_method = method;
_constructor = constructor;
_awaitableMethod = awaitableMethod;
}

public async Task HandleRequest(HttpContext httpContext)
Expand Down Expand Up @@ -79,7 +81,14 @@ await Console.Error.WriteLineAsync(

try
{
JObject output = (JObject) _method.Invoke(owObject, new object[] {valObject});
JObject output;

if(_awaitableMethod) {
output = (JObject) await (dynamic) _method.Invoke(owObject, new object[] {valObject});
}
else {
output = (JObject) _method.Invoke(owObject, new object[] {valObject});
}

if (output == null)
{
Expand Down
7 changes: 7 additions & 0 deletions tests/dotnetshared/Echo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using System;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;

namespace Apache.OpenWhisk.Tests.Dotnet
{
Expand All @@ -26,5 +27,11 @@ public JObject Main(JObject args)
{
return (args);
}

public async Task<JObject> MainAsync(JObject args)
{
await Task.Delay(10); // Just do a delay to have an async/await process occur.
return (args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DotNet2_2ActionContainerTests extends BasicActionRunnerTests with WskActor
}

val testEchoNoWrite = {
TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Echo::Main")
TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Echo::MainAsync")
}

override val testUnicode = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DotNet3_0ActionContainerTests extends BasicActionRunnerTests with WskActor
}

val testEchoNoWrite = {
TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Echo::Main")
TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Echo::MainAsync")
}

override val testUnicode = {
Expand Down