Created
March 12, 2018 03:26
-
-
Save jlattimer/e10103409bf6dd4c24bf70f7ff997767 to your computer and use it in GitHub Desktop.
Application Insights / Flow duration calculator #blog
This file contains hidden or 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
using System.Net; | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
log.Info("Starting Function"); | |
string start = req.GetQueryNameValuePairs() | |
.FirstOrDefault(q => string.Compare(q.Key, "start", true) == 0) | |
.Value; | |
if (start == null) | |
{ | |
dynamic data = await req.Content.ReadAsAsync<object>(); | |
start = data?.start; | |
} | |
log.Info("Start: " + start); | |
string end = req.GetQueryNameValuePairs() | |
.FirstOrDefault(q => string.Compare(q.Key, "end", true) == 0) | |
.Value; | |
if (end == null) | |
{ | |
dynamic data = await req.Content.ReadAsAsync<object>(); | |
end = data?.end; | |
} | |
log.Info("End: " + end); | |
if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end)) | |
return req.CreateResponse(HttpStatusCode.OK, "00:00:00.000"); | |
DateTime dStart = DateTime.Parse(start); | |
DateTime dEnd = DateTime.Parse(end); | |
TimeSpan duration = dEnd - dStart; | |
log.Info("Duration: " + duration); | |
return req.CreateResponse(HttpStatusCode.OK, duration); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment