Last active
August 10, 2020 17:01
-
-
Save sandervandevelde/88ee8b2523a948c80c647170c26789d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "Newtonsoft.Json" | |
using System.Net; | |
using Microsoft.AspNetCore.Mvc; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
public static async Task<IActionResult> Run(HttpRequest req, ILogger log) | |
{ | |
log.LogInformation("DPS processed a request. "); | |
string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); | |
//log.LogInformation(requestBody); | |
dynamic data = JsonConvert.DeserializeObject(requestBody); | |
log.LogInformation("Linked Hub:"); | |
foreach(var item in data.linkedHubs) | |
{ | |
log.LogInformation((string) item); | |
} | |
var response = new Response("prov-west-ih.azure-devices.net"); | |
response.initialTwin.tags = new JObject(); | |
response.initialTwin.tags.tagOne = "one"; | |
response.initialTwin.properties.desired = new JObject(); | |
response.initialTwin.properties.desired.propOne = "ONE"; | |
response.initialTwin.properties.desired.propTwo = new JObject(); | |
response.initialTwin.properties.desired.propTwo.attribOne = "attrib one"; | |
return (ActionResult) new OkObjectResult(response); | |
} | |
public class Response | |
{ | |
public Response(string hostName) | |
{ | |
iotHubHostName = hostName; | |
initialTwin = new ResponseTwin(); | |
} | |
public string iotHubHostName {get; set;} | |
public ResponseTwin initialTwin {get; set;} | |
} | |
public class ResponseTwin | |
{ | |
public ResponseTwin() | |
{ | |
properties = new ResponseProperties(); | |
} | |
public dynamic tags {get; set;} | |
public ResponseProperties properties {get; set;} // contains desired properties | |
} | |
public class ResponseProperties | |
{ | |
public dynamic desired {get; set;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment