private async Task TrainAndSaveNewScenarioAsync(VisualAlertModelData data) { Project project = null; VisualAlertScenarioData scenario = null; try { this.newAlertProgressBar.IsIndeterminate = true; UpdateScenarioListPanel(BuilderMode.Processing); await UpdateStatus(string.Empty); // create new custom vision project UpdateProcessingStatus(data.Name, AlertCreateProcessingStatus.Creating); project = await customVisionServiceWrapper.CreateVisualAlertProjectAsync(data.Name, data.PositiveImages, data.NegativeImages); // train project UpdateProcessingStatus(data.Name, AlertCreateProcessingStatus.Training); Iteration iteration = await customVisionServiceWrapper.TrainProjectAsync(project.Id); // export project UpdateProcessingStatus(data.Name, AlertCreateProcessingStatus.Exporting); scenario = await customVisionServiceWrapper.ExportOnnxProject(project); // store project await VisualAlertDataLoader.StoreScenarioAsync(scenario); // update scenario collection await LoadScenariosAsync(); } catch (Exception ex) { await Util.GenericApiCallExceptionHandler(ex, "Failure creating alert"); } finally { if (project != null) { await customVisionServiceWrapper.DeleteProjectAsync(project); } this.newAlertProgressBar.IsIndeterminate = false; UpdateScenarioListPanel(BuilderMode.ScenarioList, scenario); } }
private async void OnBuilderWizardControlCompleted(object sender, VisualAlertModelData data) { await TrainAndSaveNewScenarioAsync(data); }