Skip to content

Instantly share code, notes, and snippets.

@slamb2k
Created March 15, 2017 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slamb2k/44b1600264e9b892958539ccce5cc47d to your computer and use it in GitHub Desktop.
Save slamb2k/44b1600264e9b892958539ccce5cc47d to your computer and use it in GitHub Desktop.
ServiceBusCleanup.csx
#r "Newtonsoft.Json"
using System;
using System.Net;
using Newtonsoft.Json;
public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
{
// Grab the JSON that stream analytics has thrown on the queue
// It will look something like the example below and we need to clean
// it up so we can load the JSON payload inside it.
//{
// "ContentBag": "@\u0006string\b3http://schemas.microsoft.com/2003/10/Serialization/�\u001b{\"avg\":0.48083300419999553}"
//}
log.Verbose($"Webhook was triggered!");
string jsonContent = await req.Content.ReadAsStringAsync();
log.Verbose($"json content: {jsonContent}");
dynamic data = JsonConvert.DeserializeObject(jsonContent);
string msgBody = data.ContentBag;
log.Verbose($"Message Received: {msgBody}");
int length = msgBody.Length;
log.Verbose($"Message Length: {length.ToString()}");
// Grab the payload inside the ContentBag value between the curly braces and dump
// the other rubbish.
int start = msgBody.IndexOf("{");
int end = msgBody.LastIndexOf("}");
string result = msgBody.Substring(start, end - start + 1);
log.Verbose($"Result: {result}");
// Deserialize the value inside and pass it back for processing in the logic app
return req.CreateResponse(HttpStatusCode.OK, JsonConvert.DeserializeObject(result));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment