Exemplo n.º 1
0
		public async Task OpenDocument(Document doc)
		{
			if (doc == null) return;
			try
			{
				string uri = doc?.GetFullUri0();
				if (string.IsNullOrWhiteSpace(uri)) return;
				var file = await StorageFile.GetFileFromPathAsync(uri).AsTask(); //.ConfigureAwait(false);
				if (file == null) return;

				bool isOk = false;

				var fs = await Launcher.QueryFileSupportAsync(file);
				if (fs != LaunchQuerySupportStatus.Available)
				{
					if (Path.GetExtension(uri) == DocumentExtensions.TXT_EXTENSION)
					{
						// open a big TextBlock popup to see text files if no app is found, which can read txt files
						string text = await DocumentExtensions.GetTextFromFileAsync(uri);
						await UserConfirmationPopup.GetInstance().ShowTextAsync(text, CancToken);
						return;
					}
				}
				isOk = await Launcher.LaunchFileAsync(file, new LauncherOptions() { DisplayApplicationPicker = true }).AsTask().ConfigureAwait(false);
				//isOk = await Launcher.LaunchFileAsync(file).AsTask().ConfigureAwait(false);
			}
			catch (Exception ex)
			{
				Debugger.Break();
				await Logger.AddAsync(ex.ToString(), Logger.ForegroundLogFilename).ConfigureAwait(false);
			}
		}
Exemplo n.º 2
0
			public DocumentClickedArgs(Wallet wallet, Document document)
			{
				_wallet = wallet;
				_document = document;
			}
Exemplo n.º 3
0
		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);
		}
Exemplo n.º 4
0
		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;
			});
		}
Exemplo n.º 5
0
		public Task<bool> ImportFileAsync(StorageFile file)
		{
			return RunFunctionIfOpenAsyncTB(async delegate
			{
				if (DBManager != null && file != null && await file.GetFileSizeAsync() > 0)
				{
					var newDoc = new Document(DBManager, Id);
					newDoc.SetUri0(Path.GetFileName(file.Path));

					return await AddDocument2Async(newDoc).ConfigureAwait(false);
				}
				return false;
			});
		}
Exemplo n.º 6
0
		public Task<bool> RemoveDocumentAsync(Document doc)
		{
			return RunFunctionIfOpenAsyncTB(async () => await RemoveDocument2Async(doc).ConfigureAwait(false));
		}
Exemplo n.º 7
0
		private async Task<bool> RemoveDocument2Async(Document doc)
		{
			if (doc != null && doc.ParentId == Id)
			{
				await DBManager.DeleteFromDocumentsAsync(doc);

				int countBefore = _documents.Count;
				await RunInUiThreadAsync(delegate { _documents.Remove(doc); }).ConfigureAwait(false);

				await doc.OpenAsync().ConfigureAwait(false);
				await doc.RemoveContentAsync().ConfigureAwait(false);
				await doc.CloseAsync().ConfigureAwait(false);
				doc.Dispose();

				return _documents.Count < countBefore || _documents.Count == 0;
			}
			return false;
		}
Exemplo n.º 8
0
		public async Task<Document> AddDocumentAsync()
		{
			Document newDoc = null;
			if (await RunFunctionIfOpenAsyncTB(delegate
			{
				newDoc = new Document(DBManager, Id);
				return AddDocument2Async(newDoc);
			}).ConfigureAwait(false))
			{
				return newDoc;
			}
			else
			{
				return null;
			}
		}
Exemplo n.º 9
0
		private async Task<bool> AddDocument2Async(Document doc)
		{
			if (doc != null)
			{
				if (Document.Check(doc))
				{
					var dbM = DBManager;
					if (dbM != null && await dbM.InsertIntoDocumentsAsync(doc))
					{
						await RunInUiThreadAsync(delegate { _documents.Add(doc); }).ConfigureAwait(false);
						await doc.OpenAsync().ConfigureAwait(false);
						return true;
					}
				}
			}
			return false;
		}