Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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