Beispiel #1
0
        private async Task DeleteModelAsync()
        {
            try
            {
                if (CurrentFormModel?.Id != null && !CurrentFormModel.IsPrebuiltModel)
                {
                    Guid modelId = CurrentFormModel.Id;

                    // delete Form Recognizer model
                    await this.formRecognizerService.DeleteCustomModelAsync(modelId);

                    // update local file with custom models
                    this.Models.Remove(CurrentFormModel);
                    await FormRecognizerDataLoader.SaveCustomModelsToFileAsync(this.Models.Where(x => !x.IsPrebuiltModel));

                    await FormRecognizerDataLoader.DeleteModelStorageFolderAsync(modelId);

                    // re-select the first item from collection
                    CurrentFormModel = this.Models.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                await Util.GenericApiCallExceptionHandler(ex, "Failure deleting model");
            }
        }
Beispiel #2
0
        private async Task LoadModelsAsync()
        {
            try
            {
                this.Models.Clear();
                this.Models.AddRange(FormRecognizerDataLoader.GetBuiltInModels());

                // get all model Ids by custom Form Recognizer API Key
                IList <Guid> allModelIdsBySubKey = (await this.formRecognizerService.GetCustomModelsAsync())?.ModelList.Select(x => x.ModelId).ToList() ?? new List <Guid>();

                // get stored models from local file by your custom Form Recognizer API Key
                List <FormRecognizerViewModel> allCustomModels = await FormRecognizerDataLoader.GetCustomModelsAsync();

                List <FormRecognizerViewModel> customModels = allCustomModels?.Where(x => allModelIdsBySubKey.Contains(x.Id)).ToList();

                if (customModels != null && customModels.Any())
                {
                    this.Models.AddRange(customModels);
                }
            }
            catch (Exception ex)
            {
                await Util.GenericApiCallExceptionHandler(ex, "Failure loading models");
            }
        }
Beispiel #3
0
        private async void OnNewModelCreated(object sender, FormRecognizerViewModel e)
        {
            try
            {
                this.Models.Add(e);
                CurrentFormModel = this.Models.FirstOrDefault(m => m.Id == e.Id);

                // update local file with custom models
                await FormRecognizerDataLoader.SaveCustomModelsToFileAsync(this.Models.Where(x => !x.IsPrebuiltModel));
            }
            catch (Exception ex)
            {
                await Util.GenericApiCallExceptionHandler(ex, "Failure creating model");
            }
        }
        private async void OnCreateScenarioButtonClicked(object sender, RoutedEventArgs e)
        {
            Guid modelId = await CreateNewScenarioAsync();

            if (modelId != Guid.Empty)
            {
                var suggestionFiles = new List <Tuple <string, Uri> >();
                foreach (StorageFile file in LocalFileCollection.Take(MinFilesCount))
                {
                    StorageFile copyFile = await FormRecognizerDataLoader.CopyFileToLocalModelFolderAsync(file, modelId);

                    suggestionFiles.Add(new Tuple <string, Uri>(copyFile.Name, new Uri(copyFile.Path)));
                }

                this.ModelCreated?.Invoke(this, new FormRecognizerViewModel()
                {
                    Id                = modelId,
                    Name              = this.scenarioNameTextBox.Text,
                    IsPrebuiltModel   = false,
                    SuggestionSamples = suggestionFiles
                });
            }
        }