private static Dictionary <string, object> LookupJob(Mujin.ControllerClient controllerClient, Options options, string jobPrimaryKey) { Dictionary <string, object> jobs = controllerClient.GetJobs(); foreach (Dictionary <string, object> job in (List <object>)jobs["objects"]) { if (job["pk"].ToString() == jobPrimaryKey) { return(job); } } return(null); }
private static void CancelPreviousJobs(Mujin.ControllerClient controllerClient, Options options) { Dictionary <string, object> jobs = controllerClient.GetJobs(); foreach (Dictionary <string, object> job in (List <object>)jobs["objects"]) { if (job["description"].ToString().Contains("/registration-")) { controllerClient.DeleteJob(job["pk"].ToString()); Console.WriteLine("Canceled previous job: {0}", job["pk"].ToString()); } } }
private async Task Progress(string scenepk, string taskpk, string jobpk) { string controllerurl = controllerurl_input.Text; string controllerusername = username_input.Text; string controllerpassword = password_input.Text; // initialize mujincontrollerclient Mujin.ControllerClient c = new Mujin.ControllerClient(controllerusername, controllerpassword, controllerurl); int progress = 0; bool jobSeen = false; DateTime startTime = DateTime.Now; while (true) { await Task.Delay(200); Dictionary <string, object> job = null; Dictionary <string, object> jobs = c.GetJobs(); foreach (Dictionary <string, object> j in (List <object>)jobs["objects"]) { if (j["pk"].ToString() == jobpk) { job = j; break; } } if (job == null) { // job has been seen before, so must be done now if (jobSeen) { break; } // perhaps job finished too quickly if (DateTime.Now - startTime > TimeSpan.FromSeconds(2)) { break; } // wait a bit more continue; } jobSeen = true; richTextBox1.Text = job["status_text"].ToString(); double progressRaw = double.Parse(job["progress"].ToString()); progress = Math.Min(100, Math.Max(progress, (int)Math.Round(progressRaw * 100))); progressBar1.Invoke(new Action(() => { progressBar1.Value = progress; })); } int objectCount = 0; Dictionary <string, object> task = c.GetSceneTask(scenepk, taskpk); List <object> resultsInfoList = (List <object>)task["binpickingresults"]; if (resultsInfoList.Count > 0) { Dictionary <string, object> resultInfo = (Dictionary <string, object>)resultsInfoList[0]; Dictionary <string, object> result = c.GetJsonMessage(Mujin.HttpMethod.GET, (string)resultInfo["uri"]); Console.WriteLine("{0}", JSON.ToNiceJSON(result)); if (result.ContainsKey("output")) { Dictionary <string, object> output = (Dictionary <string, object>)result["output"]; if (output.ContainsKey("objects")) { List <object> objects = (List <object>)output["objects"]; objectCount = objects.Count; } } } richTextBox1.Text = String.Format("Backed up {0} objects.", objectCount); progressBar1.Invoke(new Action(() => { progressBar1.Value = 100; })); }