-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHandler.cs
86 lines (73 loc) · 2.42 KB
/
Handler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using Newtonsoft.Json;
// AWS
#if PROVIDER_AWS
using Amazon.Lambda.Core;
[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
#endif
// Azure
#if PROVIDER_AZURE
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
#endif
namespace AgnosticHello
{
// Define expected parameters
public class Request
{
public string Name { get; set; }
}
// Function logic
public class AgnosticRequest
{
public string Process(Request request)
{
return "Hello from any damn platform " + request.Name;
}
}
#if PROVIDER_AWS
public class Handler
{
public Response Hello(Request request)
{
AgnosticRequest ar = new AgnosticRequest();
Response response = new Response();
response.statusCode = 200;
response.body = ar.Process(request);
return response;
}
public class Response {
public int statusCode { get; set; }
public string body { get; set; }
}
}
#endif
#if PROVIDER_AZURE
public static class Handler
{
[FunctionName("Hello")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, ILogger log)
{
//log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
// TODO: copy all data attributes to Request object
Request request = new Request();
request.Name = name;
/*return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");*/
AgnosticRequest ar = new AgnosticRequest();
return new OkObjectResult(ar.Process(request));
}
}
#endif
}