private async void FileTree_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node.Tag == null) { return; } if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = cancellationTokenSource.Token; if (e.Node.Tag.ToString() == "folder") { FolderViewList.Items.Clear(); JObject jobject = GetJsonFromEndpoint(String.Format("/folders({0})/items", e.Node.Name)); JArray items = jobject["value"] as JArray; await Task.Run(() => { foreach (JObject item in items) { var type = item.Property("type").Value.ToString(); // only display sample results if (type != "SampleResult") { continue; } if (cancellationToken.IsCancellationRequested) { break; } var name = item.Property("name").Value.ToString(); var id = item.Property("id").Value.ToString(); var created = item.Property("createdAt").Value.ToString(); var sampleResult = GetJsonFromEndpoint(String.Format("/sampleresults({0})", id)); var sample = sampleResult.Property("sample").Value as JObject; var replicate = sample.Property("replicateNumber").Value.ToString(); var wellPosition = sample.Property("wellPosition").Value.ToString(); var acquisitionStartTime = sample.Property("acquisitionStartTime").Value.ToString(); name = sample.Property("name").Value.ToString(); JObject analysis = (GetJsonFromEndpoint(String.Format("/sampleresults({0})/analyses", id))["value"] as JArray).FirstOrDefault() as JObject; string analysisName = "unknown"; if (analysis != null) { analysisName = analysis.Property("name").Value.ToString(); } if (cancellationToken.IsCancellationRequested) { break; } var updateView = new MethodInvoker(() => FolderViewList.Items.Add(new ListViewItem(new string[] { analysisName, wellPosition, replicate, name, acquisitionStartTime, created }, 2) { Tag = String.Format("/sampleresults({0})", id) })); FolderViewList.Invoke(updateView); } cancellationTokenSource = null; }); } FolderViewList.Sort(); }
private async void FileTree_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node.Tag == null) { return; } if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = cancellationTokenSource.Token; try { if (e.Node.Tag.ToString() == "folder") { FolderViewList.Items.Clear(); JObject jobject = await GetJsonFromEndpoint(String.Format("/folders({0})/items", e.Node.Name), cancellationToken); JArray items = jobject["value"] as JArray; foreach (JObject item in items) { var type = item.Property("type").Value.ToString(); // only display sample results if (type != "SampleResult") { continue; } var name = item.Property("name").Value.ToString(); var id = item.Property("id").Value.ToString(); var created = item.Property("createdAt").Value.ToString(); var sampleResult = await GetJsonFromEndpoint(String.Format("/sampleresults({0})", id), cancellationToken); var sample = sampleResult.Property("sample").Value as JObject; var replicate = sample.Property("replicateNumber").Value.ToString(); var wellPosition = sample.Property("wellPosition").Value.ToString(); var acquisitionStartTime = sample.Property("acquisitionStartTime").Value.ToString(); //name = sample.Property("name").Value.ToString(); var analyses = await GetJsonFromEndpoint(String.Format("/sampleresults({0})/analyses", id), cancellationToken); JObject analysis = (analyses["value"] as JArray).FirstOrDefault() as JObject; string analysisName = "unknown"; if (analysis != null) { analysisName = analysis.Property("name").Value.ToString(); } if (name.Length == 0) { name = analysisName; } var updateView = new MethodInvoker(() => { FolderViewList.Items.Add(new ListViewItem(new string[] { analysisName, wellPosition, replicate, name, acquisitionStartTime, created }, 2) { Tag = new UnifiSampleResult(serverLocationTextBox.Text, id, name, replicate, wellPosition) }); }); FolderViewList.Invoke(updateView); } cancellationTokenSource = null; } } catch (TaskCanceledException) { if (!cancellationToken.IsCancellationRequested) { Program.HandleException(new TimeoutException("UNIFI API call timed out")); } } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } Program.HandleException(ex); disconnect(); } FolderViewList.Sort(); }