// Post a Run public static async Task <Uri> CreateRunAsync(RunAPI run) { HttpResponseMessage response = await client.PostAsJsonAsync( "runs/", run); response.EnsureSuccessStatusCode(); // return URI of created resource return(response.Headers.Location); }
// Write Runlog to API private async Task <bool> writeVariablesToAPI(RunLog rlg) { DateTime runEndTime = rlg.RunTime.AddSeconds(rlg.RunSequence.SequenceDuration); JArray listBoundVariables = new JArray(); JObject parametersJson = new JObject(); foreach (Variable var in rlg.RunSequence.Variables) { parametersJson[var.VariableName] = var.VariableValue; if (var.ListDriven) { listBoundVariables.Add(var.VariableName); } } parametersJson["ListBoundVariables"] = listBoundVariables; parametersJson["SequenceDuration"] = rlg.RunSequence.SequenceDuration; parametersJson["SequenceModeName"] = rlg.RunSequence.CurrentMode.ModeName; // create the new run RunAPI newrun = new RunAPI() { runtime = runEndTime.ToString("yyyy-MM-ddTHH:mm:ssZ"), parameters = parametersJson, lab = LabURLs[BreadboardSettings["LabName"]] }; try // to create a run object in the API { var url = await CreateRunAsync(newrun); addEventLogText($"Run created at {url.Segments[1]}{url.Segments[2]}"); return(true); } catch (Exception x) { addEventLogText("API Error: " + x.Message); return(false); } }