Exemple #1
0
        private Task <bool> ImportContacts(string vCardContents)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

            Task.Run(() =>
            {
                bool processIsSuccessful = false;

                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    processIsSuccessful = Importer.Import(Manager, vCardContents);

                    if (processIsSuccessful)
                    {
                        if (WorkflowSuccessAction != null)
                        {
                            WorkflowSuccessAction.Invoke();
                        }
                    }
                    else
                    {
                        if (WorkflowFailureAction != null)
                        {
                            WorkflowFailureAction.Invoke();
                        }
                    }
                });

                tcs.SetResult(processIsSuccessful);
            }).ConfigureAwait(false);

            return(tcs.Task);
        }
Exemple #2
0
        private async Task <bool> LaunchFilePickerAndExportAsync()
        {
            bool processIsSuccessful = false;

            FileSavePicker savePicker = new FileSavePicker
            {
                SuggestedStartLocation = PickerLocationId.Downloads,
                SuggestedFileName      = "PhiliaContacts"
            };

            savePicker.FileTypeChoices.Add("Virtual Contact File", new List <string>()
            {
                ".vcf"
            });

            StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                try
                {
                    IsBusy = true;

                    CachedFileManager.DeferUpdates(file);

                    await FileIO.WriteTextAsync(file, Writer.Write(Manager));

                    Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);

                    processIsSuccessful = status == Windows.Storage.Provider.FileUpdateStatus.Complete;

                    if (processIsSuccessful)
                    {
                        if (WorkflowSuccessAction != null)
                        {
                            WorkflowSuccessAction.Invoke();
                        }
                    }
                    else
                    {
                        if (WorkflowFailureAction != null)
                        {
                            WorkflowFailureAction.Invoke();
                        }
                    }
                }
                finally
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        IsBusy = false;
                        ExportCommand.RaiseCanExecuteChanged();
                    });
                }
            }

            return(processIsSuccessful);
        }