private void UnregisterWalletChanged(Wallet wal) { wal.Documents.CollectionChanged -= OnFolWalDoc_CollectionChanged; foreach (Document doc in wal.Documents) { UnregisterDocumentChanged(doc); } }
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 DocumentClickedArgs(Wallet wallet, Document document) { _wallet = wallet; _document = document; }
public async void StartShoot(Wallet parentWallet) { if (!IsOpen) return; var folder = _folder; var directory = folder?.DBManager?.Directory; if (folder != null && directory != null && RuntimeData.Instance?.IsCameraAvailable == true && TrySetIsImportingMedia(true)) { try { RegistryAccess.TrySetValue(ConstantData.REG_IMPORT_MEDIA_FOLDERID, folder.Id); RegistryAccess.TrySetValue(ConstantData.REG_IMPORT_MEDIA_PARENTWALLETID, parentWallet == null ? string.Empty : parentWallet.Id); RegistryAccess.TrySetValue(ConstantData.REG_IMPORT_MEDIA_IS_SHOOTING, true.ToString()); var captureUI = new CameraCaptureUI(); captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; captureUI.PhotoSettings.MaxResolution = Briefcase.GetCurrentInstance().CameraCaptureResolution; captureUI.PhotoSettings.AllowCropping = false; var file = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo).AsTask(); Pickers.SetLastPickedOpenFile(file); // little race here, hard to avoid and apparently harmless // LOLLO NOTE at this point, OnResuming() has just started, if the app was suspended. We cannot even know if we are open. // To avoid surprises, we try the following here under _isOpenSemaphore. If it does not run through, IsImportingMedia will stay true. // In OpenMayOverrideAsync, we check IsImportingMedia and, if true, we try again. // ContinueAfterFilePickAsync sets IsImportingMedia to false, so there won't be redundant attempts. await RunFunctionIfOpenThreeStateAsyncT(() => ContinueAfterFilePickAsync(file, directory, folder, parentWallet)).ConfigureAwait(false); } catch (Exception ex) { Logger.Add_TPL(ex.ToString(), Logger.AppEventsLogFilename); _animationStarter.EndAllAnimations(); _animationStarter.StartAnimation(AnimationStarter.Animations.Failure); } } else { _animationStarter.EndAllAnimations(); _animationStarter.StartAnimation(AnimationStarter.Animations.Failure); } }
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> RemoveDocumentFromWalletAsync(Wallet wallet, Document doc) { return RunFunctionIfOpenAsyncTB(async delegate { bool isOk = false; if (wallet != null) { await wallet.OpenAsync(); isOk = await wallet.RemoveDocumentAsync(doc); if (wallet.Documents.Count < 1) // if there are no more documents in the wallet, delete the wallet, too { var folder = _folder; if (folder != null) { isOk = isOk & await folder.RemoveWalletAsync(wallet).ConfigureAwait(false); } else { isOk = false; } } } return isOk; }); }
public async void StartLoadMediaFile(Wallet parentWallet) { if (!IsOpen) return; var folder = _folder; var directory = folder?.DBManager?.Directory; if (folder != null && directory != null && TrySetIsImportingMedia(true)) { RegistryAccess.TrySetValue(ConstantData.REG_IMPORT_MEDIA_FOLDERID, folder.Id); RegistryAccess.TrySetValue(ConstantData.REG_IMPORT_MEDIA_PARENTWALLETID, parentWallet == null ? string.Empty : parentWallet.Id); RegistryAccess.TrySetValue(ConstantData.REG_IMPORT_MEDIA_IS_SHOOTING, false.ToString()); var file = await DocumentExtensions.PickMediaFileAsync().ConfigureAwait(false); // LOLLO NOTE at this point, OnResuming() has just started, if the app was suspended. We cannot even know if we are open. // To avoid surprises, we try the following here under _isOpenSemaphore. If it does not run through, IsImportingMedia will stay true. // In OpenMayOverrideAsync, we check IsImportingMedia and, if true, we try again. // ContinueAfterFilePickAsync sets IsImportingMedia to false, so there won't be redundant attempts. await RunFunctionIfOpenThreeStateAsyncT(() => ContinueAfterFilePickAsync(file, directory, folder, parentWallet)).ConfigureAwait(false); } else { _animationStarter.EndAllAnimations(); _animationStarter.StartAnimation(AnimationStarter.Animations.Failure); } }
public Task<bool> RemoveWalletFromFolderAsync(Wallet wallet) { return RunFunctionIfOpenAsyncTB(() => _folder?.RemoveWalletAsync(wallet)); }
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); }
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; }); }
private async Task<bool> RemoveWallet2Async(Wallet wallet) { if (wallet != null && wallet.ParentId == Id) { await DBManager.DeleteFromWalletsAsync(wallet); await RunInUiThreadAsync(delegate { _wallets.Remove(wallet); }).ConfigureAwait(false); await wallet.OpenAsync().ConfigureAwait(false); await wallet.RemoveDocumentsAsync().ConfigureAwait(false); await wallet.CloseAsync().ConfigureAwait(false); wallet.Dispose(); return true; } return false; }
public Task<bool> RemoveWalletAsync(Wallet wallet) { return RunFunctionIfOpenAsyncTB(async () => await RemoveWallet2Async(wallet).ConfigureAwait(false)); }
private async Task<bool> AddWallet2Async(Wallet wallet) { if (wallet != null) { if (Wallet.Check(wallet)) { var dbM = DBManager; if (dbM != null && await dbM.InsertIntoWalletsAsync(wallet)) { await RunInUiThreadAsync(delegate { _wallets.Add(wallet); }).ConfigureAwait(false); await wallet.OpenAsync().ConfigureAwait(false); return true; } } else { Logger.Add_TPL("ERROR in Folder.AddWalletAsync(): new wallet did not stand Wallet.CheckAllowedValues()", Logger.ForegroundLogFilename); } } return false; }
public Task<bool> AddWalletAsync() { return RunFunctionIfOpenAsyncTB(async delegate { var wallet = new Wallet(DBManager, Id); return await AddWallet2Async(wallet).ConfigureAwait(false); }); }