private void StartNextFile(BbRemoteServer server) { SendFile next = m_liSendFiles.Find(x => x.Status == SendFile.EStatus.WAITING); if (next != null) { next.Status = SendFile.EStatus.REQUESTED; server.SendFileStart(next.FileName, next.FileType, next.FileID, (ulong)next.FileSize); Log.s(TAG, $"Waiting for remote client to accept file: {next.FileName}"); } }
public void OnConnectionEvent(object sender, ConnectionEventArgs eventArgs) { if (eventArgs.NewState == ConnectionEventArgs.EState.DISCONNECTED) { StopCapture(false, true); m_captureServer = null; m_bDidCaptureDuringConnection = false; } else if (eventArgs.NewState == ConnectionEventArgs.EState.CONNECTED) { m_captureServer = sender as BbRemoteServer; } PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CanCapture")); }
private async Task <bool> ConnectToServerAsync(IPAddress address, UInt16 nPort, int nServerGUID, BbRemoteServerHistory reconnect) { if (CurrentServer != null) { if (CurrentServer.Attached && CurrentServer.ServerGUID == nServerGUID && CurrentServer.ServerIP.Equals(address) && CurrentServer.Port == nPort) { return(true); } await CurrentServer.CloseAsync(); } if (reconnect == null) { Log.i(TAG, "Trying to connect to " + address.ToString() + ":" + nPort, true); } CurrentServer = reconnect != null ? new BbRemoteServer(reconnect): new BbRemoteServer(address, nPort, nServerGUID); CurrentServer.ConnectionChanged += OnConnectionEvent; CurrentServer.ConnectionChanged += m_mainWin.AppIconManager.onConnectionEvent; CurrentServer.ConnectionChanged += ReceiveFilesManager.OnConnectionEvent; CurrentServer.ConnectionChanged += SendFilesManager.onConnectionEvent; CurrentServer.ConnectionChanged += ScreenCapture.OnConnectionEvent; CurrentServer.ConnectionChanged += m_mainWin.OnConnectionEvent; CurrentServer.ReceivedInputFeedback += m_mainWin.OnInputFeedbackEvent; CurrentServer.ReceivedIcon += m_mainWin.AppIconManager.onReceivedIcon; CurrentServer.BatteryStatusChanged += m_mainWin.OnBatteryStatusChanged; CurrentServer.ReceivedFile += ReceiveFilesManager.OnReceivedFileEvent; CurrentServer.ReceivedSharedText += m_mainWin.OnSharedText; CurrentServer.ReceivedSendFileCommand += SendFilesManager.onSendFileEvent; Task <bool> connectTask = CurrentServer.ConnectAsync(); NotifyChange(new String[] { "IsConnecting", "IsConnectingOrDiscovering" }); bool bResult = await connectTask; if (!bResult) { NotifyChange(new String[] { "IsConnecting", "IsConnectingOrDiscovering" }); if (reconnect == null) { Log.i(TAG, "Failed to connect to " + address.ToString() + ":" + nPort, true); } } return(bResult); }
public void SendFiles(String[] aFiles, BbRemoteServer server) { int nActiveFiles = m_liSendFiles.Count(x => x.Status != SendFile.EStatus.WAITING); foreach (String file in aFiles) { if (!String.IsNullOrEmpty(file)) { SendFile newFile = SendFile.CreateFromString(file); if (newFile != null) { m_liSendFiles.Add(newFile); } } } if (nActiveFiles == 0) { StartNextFile(server); } }
public async Task UploadFile(BbRemoteServer server) { m_CancelToken = new CancellationTokenSource(); Status = EStatus.TRANSFERRING; m_swUploadStartTime = new LowResStopWatch(true); Log.i(TAG, "Sending " + FileName + " (" + FileSize.ToXByteSize() + ")", true); try { using (m_stream = File.OpenRead(FullPath)) { long lPosition = 0; while (lPosition < FileSize && server.Attached) { m_CancelToken.Token.ThrowIfCancellationRequested(); BbTcpPacket_SendFileData packet = new BbTcpPacket_SendFileData(server.UsedProtocolVersion, FileID, (ulong)lPosition); int nToRead = (int)Math.Min(packet.MaxDataSize, FileSize - lPosition); int nRead = await packet.WriteFileData(m_stream, nToRead, m_CancelToken.Token); if (nRead != nToRead) { throw new IOException("Unexpected read error (read less than expected)"); } lPosition += nRead; await server.SendLowPriorityDataPacketAsync(packet, m_CancelToken.Token); } } } finally { m_CancelToken.Dispose(); m_CancelToken = null; } Status = EStatus.FINISHED; m_swUploadStartTime.Stop(); Log.i(TAG, "Finished sending file " + FileName, true); }