public async static Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("C# HTTP trigger function processed a dynatrace unbreakable gate."); // code to work around parsing issues TypeDescriptor.AddAttributes(typeof(IdentityDescriptor), new TypeConverterAttribute(typeof(IdentityDescriptorConverter).FullName)); TypeDescriptor.AddAttributes(typeof(SubjectDescriptor), new TypeConverterAttribute(typeof(SubjectDescriptorConverter).FullName)); AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; // read info from body of post var contentString = await req.Content.ReadAsStringAsync(); var input = JsonConvert.DeserializeObject <InputData>(contentString); var executionObject = new ExecuteObject( input.hubName, input.jobId, input.planId, input.timelineId, input.projectId, input.planUrl, input.taskInstanceId, input.authToken, input.monspecUrl, input.pipelineInfoUrl, input.compareWindow, input.dynatraceTennantUrl, input.dynatraceToken, input.proxyUrl, input.serviceToCompare, log); // async process gate var executionThread = new Thread(new ThreadStart(executionObject.Execute)); executionThread.Name = "Execution Thread"; executionThread.Start(); // return back return object return(HttpRequestProxy.CreateResponse(req, HttpStatusCode.OK, "processing monspec...", "application/json")); }
public async static Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("DynatraceUnbreakableGateFunction: Start"); // TODO - determine if/why these are here // code to work around parsing issues TypeDescriptor.AddAttributes(typeof(IdentityDescriptor), new TypeConverterAttribute(typeof(IdentityDescriptorConverter).FullName)); TypeDescriptor.AddAttributes(typeof(SubjectDescriptor), new TypeConverterAttribute(typeof(SubjectDescriptorConverter).FullName)); AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; // response is a JSON object with status and comment CompareResponse jsonResponse = new CompareResponse(); try { var contentString = await req.Content.ReadAsStringAsync(); var input = JsonConvert.DeserializeObject <InputData>(contentString); // TODO - remove all VSTS variables and arguments related to async if not going to use this approach log.Info("DynatraceUnbreakableGateFunction: Read info from body of post"); var executionObject = new ExecuteObject( input.hubName, input.jobId, input.planId, input.timelineId, input.projectId, input.planUrl, input.taskInstanceId, input.authToken, input.monspecUrl, input.pipelineInfoUrl, input.compareWindow, input.dynatraceTennantUrl, input.dynatraceToken, input.proxyUrl, input.serviceToCompare, input.compareShift, input.compareType, log); log.Info("DynatraceUnbreakableGateFunction: Parsed info from body of post and stored in executionObject"); var compareReturnString = executionObject.Compare(); if (compareReturnString == "") { jsonResponse.status = "success"; jsonResponse.comment = ""; } else { jsonResponse.status = "failure"; jsonResponse.comment = compareReturnString; } log.Info("DynatraceUnbreakableGateFunction: response: " + JsonConvert.SerializeObject(jsonResponse)); return(HttpRequestProxy.CreateResponse(req, HttpStatusCode.OK, JsonConvert.SerializeObject(jsonResponse), "application/json")); } catch (Exception e) { jsonResponse.status = "exception"; jsonResponse.comment = "Exception: " + e.Message; log.Error("DynatraceUnbreakableGateFunction: response: " + JsonConvert.SerializeObject(jsonResponse)); return(HttpRequestProxy.CreateResponse(req, HttpStatusCode.InternalServerError, JsonConvert.SerializeObject(jsonResponse), "application/json")); } }