private async void ReturnResult(Messages.TransformSeries msg) { HttpClient client = null; var json = JsonConvert.SerializeObject(msg); _log.Debug($"Returning result to vmstatsGUI. Message received is: {json}"); try { // Contact the vmstatsgui webserver and send it the details or the completed transform pipeline client = new HttpClient(); client.BaseAddress = new Uri(guiWebserverUrl); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); // Create a new ProcessCommand with the supplied data // TODO plumb the vmname and date throughout the chain so it gets back to the client bool isRaw = (msg.GroupID == Guid.Empty) ? true : false; var result = new Messages.Result(msg.ConnectionId, msg.Measurements.Values.Keys.ToArray(), msg.Measurements.Values.Values.ToArray(), isRaw, msg.VmName, msg.VmDate, msg.Measurements.Name); string postBody = JsonConvert.SerializeObject(result); _log.Debug($"Returning result to vmstatsGUI. Result is: {postBody}"); // Send the results to the vmstatsGUI HttpResponseMessage response = await client.PostAsync(guiWebserverUrl, new StringContent(postBody, Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { _log.Info("Successfully returned the result of a transform seriues to the vmstatsGUI."); } else { _log.Error($"Failed to ReturnResult to vmstatsGUI. Reason: {response.ReasonPhrase}"); } } catch (HttpRequestException hre) { _log.Error($"ERROR Calling vmstatsgui webserver. Error is: {hre.Message}. The URI used is {guiWebserverUrl}"); } catch (TaskCanceledException tce) { _log.Error($"ERROR Calling vmstatsgui webserver. Error is: {tce.Message}. The URI used is {guiWebserverUrl}"); } catch (Exception ex) { _log.Error($"ERROR Calling vmstatsgui webserver. Error is: {ex.Message}. The URI used is {guiWebserverUrl}"); } finally { if (client != null) { client.Dispose(); client = null; } } }
/// <summary> /// This method receives the metrics produced by the vmstats component, from the data it holds and the DSL passed to it from the client. This method /// formats the correct response and then calls the client code in the browser using SignalR. /// </summary> public async Task ReturnResultToClient([FromBody] Messages.Result msg) { Console.WriteLine("Received TransformSeries"); var jsonRequest = JsonConvert.SerializeObject(msg); Console.WriteLine($"Received ReturnResultToClient. Message is: {jsonRequest}"); // Convert the time to strings only showing hour and minute string[] times = new string[msg.Xdata.Length]; for (int i = 0; i < msg.Xdata.Length; i++) { DateTime newDate = new DateTime(msg.Xdata[i]); times[i] = newDate.ToString("HH:mm"); } // Add the day of week to the date DateTime dowDate = Convert.ToDateTime(msg.Date); string dow = dowDate.ToString("ddd"); // Send the correct information back to the client to display the graph await context.Clients.Client(msg.ConnectionId).SendAsync("DisplayGraph", msg.IsRaw, times, msg.Ydata, msg.VmName, msg.Date + "-" + dow, msg.MetricName); }