public async Task RecordAudioAsync(Wallet wallet) { if (!_isAudioRecorderOverlayOpen && RuntimeData.Instance?.IsMicrophoneAvailable == true) { await RunFunctionIfOpenAsyncT(async delegate { if (!_isAudioRecorderOverlayOpen && RuntimeData.Instance?.IsMicrophoneAvailable == true) { var folder = _folder; var file = await CreateAudioPhotoFileAsync(ConstantData.DEFAULT_AUDIO_FILE_NAME); if (folder != null && file != null) { try { IsAudioRecorderOverlayOpen = true; await _audioRecorderView.OpenAsync(); bool hasRecorded = await _audioRecorderView.RecordAsync(file, CancToken); // this locks until explicitly unlocked await _audioRecorderView.CloseAsync(); IsAudioRecorderOverlayOpen = false; if (hasRecorded) { if (wallet == null) { bool mediaImportedOk = await folder.ImportMediaFileIntoNewWalletAsync(file).ConfigureAwait(false); Debug.WriteLine("RecordAudioAsync(): mediaImportedOk = " + mediaImportedOk); } else { bool mediaImportedOk = await wallet.ImportFileAsync(file).ConfigureAwait(false); Debug.WriteLine("RecordAudioAsync(): mediaImportedOk = " + mediaImportedOk); } } else { await file.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask().ConfigureAwait(false); Debug.WriteLine("RecordAudioAsync(): recording interrupted"); } } catch (Exception ex) { Logger.Add_TPL(ex.ToString(), Logger.ForegroundLogFilename); } } } }).ConfigureAwait(false); } }
public async Task<bool> OcrDocumentAsync(Wallet wallet, Document doc) { if (wallet == null || doc == null) return false; var textLines = await doc.GetTextFromPictureAsync().ConfigureAwait(false); if (textLines == null || !textLines.Any()) return false; var directory = wallet.DBManager?.Directory; if (directory == null) return false; var newFile = await directory.CreateFileAsync(Guid.NewGuid().ToString() + DocumentExtensions.TXT_EXTENSION).AsTask().ConfigureAwait(false); if (newFile == null) return false; var sb = new StringBuilder(); foreach (var textLine in textLines) { sb.AppendLine(textLine); } await DocumentExtensions.WriteTextIntoFileAsync(sb.ToString(), newFile).ConfigureAwait(false); return await wallet.ImportFileAsync(newFile).ConfigureAwait(false); }
private async Task ContinueAfterFilePickAsync(IStorageFile file, IStorageFolder directory, Folder folder, Wallet parentWallet, bool deleteFile = false) { bool isImported = false; try { if (directory != null && file != null && await file.GetFileSizeAsync().ConfigureAwait(false) <= ConstantData.MAX_IMPORTABLE_MEDIA_FILE_SIZE) { _animationStarter.StartAnimation(AnimationStarter.Animations.Updating); StorageFile newFile = await file.CopyAsync(directory, file.Name, NameCollisionOption.GenerateUniqueName).AsTask().ConfigureAwait(false); if (parentWallet == null) { isImported = await folder.ImportMediaFileIntoNewWalletAsync(newFile).ConfigureAwait(false); } else { isImported = await parentWallet.ImportFileAsync(newFile).ConfigureAwait(false); } if (!isImported) { // delete the copied file if something went wrong if (newFile != null) await newFile.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask().ConfigureAwait(false); Logger.Add_TPL("isImported = false", Logger.AppEventsLogFilename, Logger.Severity.Info); } // delete the original file if it was a photo taken with CameraCaptureUI if (deleteFile) await file.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask().ConfigureAwait(false); } } catch (Exception ex) { await Logger.AddAsync(ex.ToString(), Logger.AppEventsLogFilename).ConfigureAwait(false); } _animationStarter.EndAllAnimations(); _animationStarter.StartAnimation(isImported ? AnimationStarter.Animations.Success : AnimationStarter.Animations.Failure); IsImportingMedia = false; }
public Task<bool> ImportMediaFileIntoNewWalletAsync(StorageFile file) { return RunFunctionIfOpenAsyncTB(async delegate { if (DBManager != null && file != null) { var newWallet = new Wallet(DBManager, Id); await newWallet.OpenAsync().ConfigureAwait(false); // open the wallet or the following won't run bool isOk = await newWallet.ImportFileAsync(file).ConfigureAwait(false) && await AddWallet2Async(newWallet).ConfigureAwait(false); if (isOk) { return true; } else { await RemoveWallet2Async(newWallet).ConfigureAwait(false); } } return false; }); }