private async void RemoteSystemWatcher_RemoteSystemRemoved(RemoteSystemWatcher sender, RemoteSystemRemovedEventArgs args) { await DispatcherEx.RunOnCoreDispatcherIfPossible(() => { var remoteSystem = _remoteSystems.Where(s => s.Id == args.RemoteSystemId).FirstOrDefault(); if (remoteSystem != null) { _remoteSystems.Remove(remoteSystem); } }); }
private async void RemoteSystemWatcher_RemoteSystemAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args) { var remoteSystem = args.RemoteSystem; await DispatcherEx.RunOnCoreDispatcherIfPossible(() => { var existingRs = _remoteSystems.FirstOrDefault(x => x.Id == remoteSystem.Id); if (existingRs != null) { _remoteSystems.Remove(existingRs); } AddToRemoteSystemsList(args.RemoteSystem); }); }
private async void RemoteSystemWatcher_RemoteSystemUpdated(RemoteSystemWatcher sender, RemoteSystemUpdatedEventArgs args) { RemoteSystem remoteSystem = null; await DispatcherEx.RunOnCoreDispatcherIfPossible(() => { remoteSystem = _remoteSystems.Where(s => s.Id == args.RemoteSystem.Id).FirstOrDefault(); }); await DispatcherEx.RunOnCoreDispatcherIfPossible(() => { if (remoteSystem != null) { _remoteSystems.Remove(remoteSystem); } AddToRemoteSystemsList(args.RemoteSystem); }); }
private async void OnNotificationAppServiceRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) { AppServiceDeferral messageDeferral = args.GetDeferral(); try { ValueSet message = args.Request.Message; if (message["Type"].ToString() == "FileTransferProgress") { await DispatcherEx.RunOnCoreDispatcherIfPossible(async() => { await NotificationHandler.HandleAsync(JsonConvert.DeserializeObject <FileTransfer2ProgressEventArgs>(message["Data"] as string)); }); } else if (message["Type"].ToString() == "TextReceive") { await DispatcherEx.RunOnCoreDispatcherIfPossible(async() => { await NotificationHandler.HandleAsync(JsonConvert.DeserializeObject <TextReceiveEventArgs>(message["Data"] as string)); }); } ValueSet returnMessage = new ValueSet(); returnMessage.Add("Status", "OK"); await args.Request.SendResponseAsync(returnMessage); } catch (Exception ex) { Debug.WriteLine("Unhandled exception in OnAppServiceRequestReceived():"); Debug.WriteLine(ex.ToString()); await(new MessageDialog(ex.ToString(), "Unhandled exception in OnAppServiceRequestReceived()")).ShowAsync(); } finally { messageDeferral.Complete(); } }
private async Task <FileTransferResult> SendFile(object rs, IRomePackageManager packageManager, string deviceName, bool preserveFolderStructure) { string sendingText = ((SendDataTemporaryStorage.Files.Count == 1) && (SendDataTemporaryStorage.Files[0] is StorageFile)) ? "Sending file..." : "Sending files..."; string message = ""; FileTransferResult result = FileTransferResult.Successful; if (await DownloadNecessaryFiles() == false) { return(FileTransferResult.Cancelled); } sendingFile = true; ViewModel.SendStatus = "Preparing..."; using (FileSender2 fs = new FileSender2(rs, new QuickShare.UWP.WebServerGenerator(), packageManager, FindMyIPAddresses(), deviceName)) { ViewModel.ProgressMaximum = 1; fs.FileTransferProgress += async(ss, ee) => { if (ee.State == FileTransferState.Error) { result = FileTransferResult.FailedOnSend; message = result.ToString(); // TODO } else if (ee.State == FileTransferState.Reconnecting) { ViewModel.SendStatus = "Reconnecting..."; ViewModel.ProgressIsIndeterminate = true; } else if (ee.State == FileTransferState.Reconnected) { ViewModel.SendStatus = "Waiting for response..."; } else { await DispatcherEx.RunOnCoreDispatcherIfPossible(() => { ViewModel.SendStatus = sendingText; ViewModel.ProgressMaximum = 1.0; ViewModel.ProgressValue = ee.Progress; ViewModel.ProgressIsIndeterminate = false; if (ee.TotalTransferredBytes > 0) { ViewModel.ProgressCaption = StringFunctions.GetSizeString(ee.TotalTransferredBytes); } }, false); } }; if (SendDataTemporaryStorage.Files.Count == 0) { ViewModel.SendStatus = "No files."; ViewModel.ProgressIsIndeterminate = false; return(FileTransferResult.NoFiles); } await Task.Run(async() => { result = await fs.Send(preserveFolderStructure ? await GetFiles(SendDataTemporaryStorage.Files) : await GetFilesWithoutFolderStructure(SendDataTemporaryStorage.Files), sendFileCancellationTokenSource.Token); }); ViewModel.ProgressValue = ViewModel.ProgressMaximum; } sendingFile = false; if (result != FileTransferResult.Successful) { HideEverything(); if (result != FileTransferResult.Cancelled) { string title = "Send failed."; string text = message; if (result == FileTransferResult.FailedOnHandshake) { title = "Couldn't reach remote device."; text = "Make sure both devices are connected to the same Wi-Fi or LAN network."; } Frame.Navigate(typeof(MainSendFailed), JsonConvert.SerializeObject(new SendFailedViewModel { ErrorTitle = title, ErrorDescription = text, })); } } else { await SendFinishService(packageManager); ViewModel.SendStatus = "Done."; } return(result); }
private async Task <FileTransferResult> SendFile(object rs, IRomePackageManager packageManager, string deviceName) { string sendingText = ((SendDataTemporaryStorage.Files.Count == 1) && (SendDataTemporaryStorage.Files[0] is StorageFile)) ? "Sending file..." : "Sending files..."; ViewModel.SendStatus = "Preparing..."; string message = ""; FileTransferResult result = FileTransferResult.Successful; sendingFile = true; using (FileSender fs = new FileSender(rs, new QuickShare.UWP.WebServerGenerator(), packageManager, FindMyIPAddresses(), deviceName)) { ViewModel.ProgressMaximum = 1; fs.FileTransferProgress += async(ss, ee) => { if (ee.State == FileTransferState.Error) { result = FileTransferResult.FailedOnSend; message = ee.Message; } else { await DispatcherEx.RunOnCoreDispatcherIfPossible(() => { ViewModel.SendStatus = sendingText; ViewModel.ProgressMaximum = (int)ee.Total + 1; ViewModel.ProgressValue = (int)ee.CurrentPart; ViewModel.ProgressIsIndeterminate = false; }, false); } }; if (SendDataTemporaryStorage.Files.Count == 0) { ViewModel.SendStatus = "No files."; ViewModel.ProgressIsIndeterminate = false; return(FileTransferResult.NoFiles); } else if ((SendDataTemporaryStorage.Files.Count == 1) && (SendDataTemporaryStorage.Files[0] is StorageFile)) { await Task.Run(async() => { result = await fs.SendFile(sendFileCancellationTokenSource.Token, new PCLStorage.WinRTFile(SendDataTemporaryStorage.Files[0] as StorageFile)); }); } else if ((SendDataTemporaryStorage.Files.Count == 1) && (SendDataTemporaryStorage.Files[0] is StorageFolder)) { var folder = SendDataTemporaryStorage.Files[0] as StorageFolder; await Task.Run(async() => { result = await fs.SendQueue(sendFileCancellationTokenSource.Token, await GetFilesOfFolder(folder), folder.DisplayName); }); } else { await Task.Run(async() => { result = await fs.SendFiles(sendFileCancellationTokenSource.Token, from x in SendDataTemporaryStorage.Files where x is StorageFile select new PCLStorage.WinRTFile(x as StorageFile), DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "\\"); }); } ViewModel.ProgressValue = ViewModel.ProgressMaximum; } sendingFile = false; if (result != FileTransferResult.Successful) { HideEverything(); if (result != FileTransferResult.Cancelled) { string title = "Send failed."; string text = message; if (result == FileTransferResult.FailedOnHandshake) { title = "Couldn't reach remote device."; text = "Make sure both devices are connected to the same Wi-Fi or LAN network."; } var dlg = new MessageDialog(text, title); await dlg.ShowAsync(); } } else { await SendFinishService(packageManager); ViewModel.SendStatus = "Finished."; } return(result); }