示例#1
0
		public FolderVM(Folder folder, IRecorder audioRecorder/*, IRecorder camera*/, AnimationStarter animationStarter)
		{
			_folder = folder;
			_audioRecorderView = audioRecorder;
			//_camera = camera;
			if (animationStarter == null) throw new ArgumentNullException("FolderVM ctor: animationStarter may not be null");
			_animationStarter = animationStarter;
		}
示例#2
0
		private void UnregisterFolderChanged(Folder fol)
		{
			fol.PropertyChanged -= OnFol_PropertyChanged;
			fol.Wallets.CollectionChanged -= OnFolWal_CollectionChanged;
			foreach (Wallet wal in fol.Wallets)
			{
				UnregisterWalletChanged(wal);
			}
		}
示例#3
0
		private async Task<bool> RemoveFolder2Async(Folder folder)
		{
			if (folder == null) return false;

			if (await _dbManager.DeleteFromFoldersAsync(folder))
			{
				if (folder.Id == _currentFolderId)
				{
					int previousFolderIndex = Math.Max(0, _folders.IndexOf(folder) - 1);
					CurrentFolderId = _folders.Count > previousFolderIndex ? _folders[previousFolderIndex].Id : DEFAULT_ID;
					await UpdateCurrentFolder2Async(false);
				}

				await RunInUiThreadAsync(delegate { _folders.Remove(folder); }).ConfigureAwait(false);

				await folder.OpenAsync().ConfigureAwait(false);
				await folder.RemoveWalletsAsync().ConfigureAwait(false);
				await folder.CloseAsync().ConfigureAwait(false);
				folder.Dispose();

				return true;
			}
			Debugger.Break(); // LOLLO this must never happen, check it
			await Logger.AddAsync("Attempting to remove folder, the db operation failed", Logger.FileErrorLogFilename).ConfigureAwait(false);

			return false;
		}
示例#4
0
		public Task<bool> RemoveFolderAsync(Folder folder)
		{
			return RunFunctionIfOpenAsyncTB(() => RemoveFolder2Async(folder));
		}
示例#5
0
		private async Task Import1FolderAsync(Folder fol, StorageFolder fromDirectory)
		{
			try
			{
				if (fol == null) return;
				var folder = fol;
				await folder.OpenAsync().ConfigureAwait(false);
				if (await _dbManager.InsertIntoFoldersAsync(folder).ConfigureAwait(false))
				{
					if (CancToken.IsCancellationRequested) return;
					await folder.SetDbManager(_dbManager).ConfigureAwait(false);

					await _dbManager.InsertIntoWalletsAsync(folder.Wallets).ConfigureAwait(false);
					foreach (var wal in folder.Wallets)
					{
						foreach (var doc in wal.Documents)
						{
							if (CancToken.IsCancellationRequested) return;
							var file = await StorageFile.GetFileFromPathAsync(doc.GetFullUri0(fromDirectory)).AsTask().ConfigureAwait(false);
							if (file != null)
							{
								// the file name might change to avoid name collisions
								var copiedFile = await file.CopyAsync(_directory, file.Name, NameCollisionOption.GenerateUniqueName).AsTask().ConfigureAwait(false);
								doc.SetUri0(copiedFile?.Name);
							}
						}
						await _dbManager.InsertIntoDocumentsAsync(wal.Documents).ConfigureAwait(false);
					}

					if (CancToken.IsCancellationRequested) return;
					await _dbManager.InsertIntoDynamicFieldsAsync(folder.DynamicFields).ConfigureAwait(false);
					await _dbManager.InsertIntoDynamicCategoriesAsync(folder.DynamicCategories).ConfigureAwait(false);

					if (CancToken.IsCancellationRequested) return;
					await RunInUiThreadAsync(() => _folders.Add(folder)).ConfigureAwait(false);
				}
			}
			catch (Exception ex)
			{
				Logger.Add_TPL(ex.ToString(), Logger.ForegroundLogFilename);
			}
		}
示例#6
0
		public async Task<Folder> AddFolderAsync()
		{
			Folder newFolder = null;

			bool isOk = await RunFunctionIfOpenAsyncTB(async delegate
			{
				newFolder = new Folder(_dbManager, RuntimeData.GetText("NewFolder"), DateTime.Now);
				// folder.ParentId = Id; // folders may not have ParentId because they can be exported or imported

				if (await _dbManager.InsertIntoFoldersAsync(newFolder))
				{
					// Add the same categories as the last folder, which was added. 
					// This is an automatism to streamline usage, it has no special reason to be.
					await newFolder.OpenAsync().ConfigureAwait(false);
					Folder lastAddedFolder = null;
					if (_folders.Any())
					{
						var maxCreateDate = _folders.Max(fol => fol.DateCreated);
						if (maxCreateDate != default(DateTime))
						{
							lastAddedFolder = _folders.FirstOrDefault(fol => fol.DateCreated == maxCreateDate);
						}
					}
					if (lastAddedFolder != null)
					{
						foreach (var cat in lastAddedFolder.DynamicCategories)
						{
							await newFolder.AddDynamicCategoryAsync(cat?.CategoryId).ConfigureAwait(false);
						}
					}

					await RunInUiThreadAsync(() => _folders.Add(newFolder)).ConfigureAwait(false);
					return true;
				}
				return false;
			});

			if (isOk) return newFolder; else return null;
		}
示例#7
0
		private async Task UpdateCurrentFolder2Async(bool openTheFolder)
		{
			if (_folders == null) return;

			_currentFolder = string.IsNullOrEmpty(_currentFolderId) ? null : _folders.FirstOrDefault(fo => fo.Id == _currentFolderId);
			if (_currentFolder != null && openTheFolder)
			{
				await _currentFolder.OpenAsync().ConfigureAwait(false);
			}
			RaisePropertyChanged_UI(nameof(CurrentFolder)); // notify the UI once the data has been loaded
		}
示例#8
0
		protected override void Dispose(bool isDisposing)
		{
			_folder = null; // do not dispose it, only briefcase may do so.
			base.Dispose(isDisposing);
		}
示例#9
0
		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;
		}