private void ShowFileTransferProgressToast(FileTransfer.FileTransferProgressEventArgs e) { if (e.State == FileTransferState.Finished) { Toaster.ShowFileReceiveFinishedNotification(e.TotalFiles, e.SenderName, e.Guid); } else { double percent = ((double)e.CurrentPart) / ((double)e.Total); Toaster.ShowFileReceiveProgressNotification(e.SenderName, e.Total == 0 ? -1.0 : percent, e.Guid); } }
private async void FileReceiver_FileTransferProgress(FileTransfer.FileTransferProgressEventArgs e) { ShowFileTransferProgressToast(e); await notificationSemaphoreSlim.WaitAsync(); waitingNumSemaphore++; #if NOTIFICATIONHANDLER_DEBUGINFO System.Diagnostics.Debug.WriteLine("Progress " + e.CurrentPart + "/" + e.Total + " : " + e.State); #endif if (!await ConnectToNotificationService()) { waitingNumSemaphore--; notificationSemaphoreSlim.Release(); return; } try { // Call the service. var message = new ValueSet(); message.Add("Type", "FileTransferProgress"); message.Add("Data", JsonConvert.SerializeObject(e)); AppServiceResponse response = await this.notificationService.SendMessageAsync(message); if (response.Status != AppServiceResponseStatus.Success) { Debug.WriteLine("Failed to send message to notification service: " + response.Status); notificationService = null; } } catch (Exception ex) { Debug.WriteLine("Failed to send message to notification service (an exception was thrown): " + ex.ToString()); notificationService = null; } waitingNumSemaphore--; notificationSemaphoreSlim.Release(); }
private async static void FileReceiver_FileTransferProgress(FileTransfer.FileTransferProgressEventArgs e) { Activity?.Invoke(); if (e.State == FileTransfer.FileTransferState.Error) { await progressNotifier?.FinishProgress("Receive failed.", ""); } else if (e.State == FileTransfer.FileTransferState.Finished) { if (e.TotalFiles == 1) { var intent = new Intent(context, typeof(NotificationLaunchActivity)); intent.PutExtra("action", "openFile"); intent.PutExtra("guid", e.Guid.ToString()); await progressNotifier?.FinishProgress($"Received a file from {e.SenderName}", "Tap to open", intent, context); } else { await DataStorageProviders.HistoryManager.OpenAsync(); var hr = DataStorageProviders.HistoryManager.GetItem(e.Guid); DataStorageProviders.HistoryManager.Close(); var rootPath = (hr.Data as ReceivedFileCollection).StoreRootPath; await progressNotifier?.FinishProgress($"Received {e.TotalFiles} files from {e.SenderName}", $"They're located at {rootPath}"); } progressNotifier = null; Finish?.Invoke(); } else if (e.State == FileTransfer.FileTransferState.DataTransfer) { progressNotifier?.SetProgressValue((int)e.Total, (int)e.CurrentPart, "Receiving..."); } }