private async void ExecuteOpen(object param) { ObservableModelPrediction.Clear(); AvailableClasses.Clear(); FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { try { IsRunning = true; (var OldImages, var NewImages) = await client.PostOld(fbd.SelectedPath, cts); OldImages.ForEach(delegate(PredictionResponse prs) { AddPrecomputedPrediction(new ModelPrediction(prs.ClassName, prs.Proba, prs.FilePath, Convert.FromBase64String(prs.Image))); }); var NewImagesResults = await client.GetNew(NewImages, cts); NewImagesResults.ForEach(delegate(PredictionResult pr) { AddPrediction(pr); }); IsRunning = false; } catch (TaskCanceledException tce) { MessageBox.Show("Tasks were cancelled"); } catch (Exception e) { MessageBox.Show("Prediction failed!"); } } }
private void ExecuteClear(object param) { ObservableModelPrediction.Clear(); AvailableClasses.Clear(); try { client.Delete(); } catch (Exception e) { MessageBox.Show("Clearing DataBase failed!"); } }
private void AddPrediction(PredictionResult pr) { dispatcher.BeginInvoke(new Action(() => { ObservableModelPrediction.Add(new ModelPrediction(pr)); var buf = AvailableClasses.Where(x => x.Item1 == pr.ClassName).FirstOrDefault(); if (buf != null) { AvailableClasses[AvailableClasses.IndexOf(buf)] = new Tuple <string, int>(buf.Item1, buf.Item2 + 1); } else { AvailableClasses.Add(new Tuple <string, int>(pr.ClassName, 1)); } })); }