Example #1
0
        private void OnEditScenarioListButtonClicked(object sender, RoutedEventArgs e)
        {
            switch (this.scenarioListView.SelectionMode)
            {
            case ListViewSelectionMode.Single:
                this.customVisionONNXModel = null;
                prevScenario = this.scenarioListView.SelectedItem as VisualAlertScenarioData;
                this.deleteButton.Visibility        = Visibility.Visible;
                this.scenarioListView.SelectionMode = ListViewSelectionMode.Multiple;
                break;

            case ListViewSelectionMode.Multiple:
            default:
                this.scenarioListView.SelectionMode = ListViewSelectionMode.Single;
                this.deleteButton.Visibility        = Visibility.Collapsed;
                if (prevScenario != null)
                {
                    this.scenarioListView.SelectedItem = prevScenario;
                }
                else
                {
                    this.scenarioListView.SelectedIndex = 0;
                }
                break;
            }
        }
Example #2
0
        private void UpdateScenarioListPanel(BuilderMode mode, VisualAlertScenarioData defaultScenario = null)
        {
            bool isAnyScenario = this.scenarioListView.Items.Any();

            switch (mode)
            {
            case BuilderMode.ScenarioList:
                this.scenarioListView.SelectionMode = ListViewSelectionMode.Single;
                if (isAnyScenario)
                {
                    var selectedScenario = ScenarioCollection.FirstOrDefault(x => x.Id == defaultScenario?.Id);
                    if (selectedScenario != null)
                    {
                        this.scenarioListView.SelectedItem = selectedScenario;
                    }
                    else
                    {
                        this.scenarioListView.SelectedIndex = 0;
                    }
                }

                this.newAlertGrid.Visibility = isAnyScenario ? Visibility.Collapsed : Visibility.Visible;
                this.visualAlertBuilderWizardControl.Visibility = isAnyScenario ? Visibility.Collapsed : Visibility.Visible;

                this.scenarioListPanel.Visibility = isAnyScenario ? Visibility.Visible : Visibility.Collapsed;
                this.deleteButton.Visibility      = Visibility.Collapsed;

                this.newAlertStatusGrid.Visibility = Visibility.Collapsed;
                this.newAlertButton.IsEnabled      = true;
                break;

            case BuilderMode.NewAlert:
                this.newAlertGrid.Visibility = Visibility.Visible;
                this.visualAlertBuilderWizardControl.Visibility = Visibility.Visible;

                this.scenarioListPanel.Visibility = Visibility.Collapsed;
                break;

            case BuilderMode.Processing:
                this.newAlertGrid.Visibility = Visibility.Collapsed;
                this.visualAlertBuilderWizardControl.Visibility = Visibility.Collapsed;

                this.scenarioListPanel.Visibility  = Visibility.Visible;
                this.newAlertStatusGrid.Visibility = Visibility.Visible;
                this.newAlertButton.IsEnabled      = false;
                break;
            }

            if (mode == BuilderMode.NewAlert || !isAnyScenario)
            {
                this.scenarioListView.SelectedItem = null;

                this.lifecycleControl.ResetState(clearAll: true);
                LifecycleStepCollection.First().State = LifecycleStepState.Active;
                this.visualAlertBuilderWizardControl.StartWizard();
            }
        }
Example #3
0
        private async Task LoadCurrentScenarioAsync(VisualAlertScenarioData scenario)
        {
            try
            {
                StorageFolder onnxProjectDataFolder = await VisualAlertDataLoader.GetOnnxModelStorageFolderAsync();

                StorageFile scenarioFile = await onnxProjectDataFolder.GetFileAsync(scenario.FileName);

                this.customVisionONNXModel = await CustomVisionModel.CreateONNXModel(scenarioFile);
            }
            catch (Exception ex)
            {
                await Util.GenericApiCallExceptionHandler(ex, "Failure loading current project");
            }
        }
Example #4
0
        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);
            }
        }
Example #5
0
        public static async Task StoreScenarioAsync(VisualAlertScenarioData scenario)
        {
            List <VisualAlertScenarioData> scenarioList = await GetScenarioCollectionAsync();

            VisualAlertScenarioData scenarioWithSameName = scenarioList.FirstOrDefault(x => string.Equals(x.Name, scenario.Name));

            if (scenarioWithSameName != null)
            {
                string titleMessage = $"There is already a “{scenarioWithSameName.Name}” model in this device. Select “Replace” if you would like to replace it, or “Keep Both” if you would like to keep both.";
                await Util.ConfirmActionAndExecute(titleMessage,
                                                   async() =>
                {
                    // if user select Yes, we replace the model with the same name
                    bool modelEntryRemovedFromFile      = scenarioList.Remove(scenarioWithSameName);
                    StorageFolder onnxProjectDataFolder = await GetOnnxModelStorageFolderAsync();
                    StorageFile modelFileToRemove       = await onnxProjectDataFolder.GetFileAsync(scenarioWithSameName.FileName);
                    if (modelEntryRemovedFromFile && modelFileToRemove != null)
                    {
                        await modelFileToRemove.DeleteAsync();
                    }
                    await SaveOrUpdateCustomVisionModelAsync(scenarioList, scenario);
                },

                                                   cancelAction : async() =>
                {
                    int maxNumberOfModelWithSameName = scenarioList
                                                       .Where(x => x.Name != null && x.Name.StartsWith(scenario.Name, StringComparison.OrdinalIgnoreCase))
                                                       .Select(x =>
                    {
                        string modelNumberInString = x.Name.Split('_').LastOrDefault();
                        int.TryParse(modelNumberInString, out int number);
                        return(number);
                    })
                                                       .Max();

                    // if user select Cancel we just save the new model with the same name
                    scenario.Name = $"{scenario.Name}_{maxNumberOfModelWithSameName + 1}";
                    await SaveOrUpdateCustomVisionModelAsync(scenarioList, scenario);
                },