private async static void FileReceiver_FileTransferProgress(FileTransfer.FileTransfer2ProgressEventArgs e) { Activity?.Invoke(); if (e.State == FileTransfer.FileTransferState.Error) { await progressNotifier?.FinishProgress("Receive failed.", ""); } else if (e.State == FileTransfer.FileTransferState.Finished) { var intent = new Intent(context, typeof(HistoryListActivity)); //typeof(NotificationLaunchActivity)); intent.PutExtra("itemGuid", e.Guid.ToString()); if (e.TotalFiles == 1) { await progressNotifier?.FinishProgress($"Received a file from {e.SenderName}", "Tap to view", intent, context); } else { await progressNotifier?.FinishProgress($"Received {e.TotalFiles} files from {e.SenderName}", $"Tap to view", intent, context); } progressNotifier = null; Finish?.Invoke(); } else if (e.State == FileTransfer.FileTransferState.DataTransfer) { progressNotifier?.SetProgressValue(1000, (int)(1000.0 * e.Progress), "Receiving..."); } }
private void ShowFileTransferProgressToast(FileTransfer.FileTransfer2ProgressEventArgs e) { if (e.State == FileTransferState.Finished) { Toaster.ShowFileReceiveFinishedNotification(e.TotalFiles, e.SenderName, e.Guid); } else if (e.State == FileTransferState.Error) { Toaster.ShowFileReceiveFailedNotification(e.Guid, e.Exception); } else { Toaster.ShowFileReceiveProgressNotification(e.SenderName, e.Progress, e.TotalTransferredBytes, e.Guid); } }
private async void FileReceiver_FileTransferProgress(FileTransfer.FileTransfer2ProgressEventArgs 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(); }