Ejemplo n.º 1
0
        private async void ImportSetFromFileAction()
        {
            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add(".xlsx");
            openPicker.FileTypeFilter.Add(".xls");
            openPicker.FileTypeFilter.Add(".docx");
            openPicker.FileTypeFilter.Add(".doc");

            StorageFile file = await openPicker.PickSingleFileAsync();

            if (file != null)
            {
                try {
                    CancellationTokenSource    cancelSource      = new CancellationTokenSource();
                    Task <ContentDialogResult> loadingScreenTask = new LoadingDialog().ShowAsync().AsTask(cancelSource.Token);
                    Task <CardSetModel>        importingTask     = ImportFlashcardService.ImportAddToExistingSet(file, cancelSource.Token, FlashCardSet.Clone());

                    Task firstToFinish = await Task.WhenAny(loadingScreenTask, importingTask);

                    cancelSource.Cancel();
                    if (firstToFinish == importingTask)
                    {
                        CardSetModel updatedCardSetModel = await importingTask;
                        prNavigationService.NavigateTo("EditSetPage");
                        Messenger.Default.Send(new Tuple <CardSetModel, CardSetModel>(FlashCardSet, updatedCardSetModel), "EditSetView");
                    }
                } catch (Exception ex) {
                    await new MessageDialog(ex.Message).ShowAsync();
                }
            }
        }