Skip to content

Instantly share code, notes, and snippets.

@sandervandevelde
Last active August 10, 2020 17:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandervandevelde/88ee8b2523a948c80c647170c26789d3 to your computer and use it in GitHub Desktop.
Save sandervandevelde/88ee8b2523a948c80c647170c26789d3 to your computer and use it in GitHub Desktop.
#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