protected override void StartRun() { using (_tcpClient = new TcpClient()) { _tcpClient.SendTimeout = Settings.Default.DownloadTimeoutTime * 1000; _tcpClient.ReceiveTimeout = Settings.Default.DownloadTimeoutTime * 1000; try { _tcpClient.Connect(IP, Port); _log.Info("StartRun() connected"); using (Stream stream = new ThrottledStream(_tcpClient.GetStream(), Settings.Default.MaxDownloadSpeedInKB * 1000)) { StartWriting(); using (var reader = new BinaryReader(stream)) { Int64 missing = Size; Int64 max = Settings.Default.DownloadPerReadBytes; byte[] data = null; do { data = reader.ReadBytes((int)(missing < max ? missing : max)); if (data != null && data.Length != 0) { SaveData(data); missing -= data.Length; } else { _log.Warn("StartRun() no data received"); break; } } while (AllowRunning && missing > 0); } _log.Info("StartRun() end"); } } catch (ObjectDisposedException) {} catch (Exception ex) { _log.Fatal("StartRun()", ex); } finally { StopWriting(); _tcpClient = null; _writer = null; } } }
protected override void StartRun() { Packet.Parent.QueuePosition = 0; Packet.Parent.QueueTime = 0; Packet.Parent.Commit(); using (_tcpClient = new TcpClient()) { _tcpClient.SendTimeout = Settings.Default.DownloadTimeoutTime * 1000; _tcpClient.ReceiveTimeout = Settings.Default.DownloadTimeoutTime * 1000; try { _tcpClient.Connect(IP, Port); _log.Info("StartRun() connected"); using (Stream stream = new ThrottledStream(_tcpClient.GetStream(), Settings.Default.MaxDownloadSpeedInKB * 1000)) { InitializeWriting(); using (var reader = new BinaryReader(stream)) { Int64 missing = MaxData; Int64 max = Settings.Default.DownloadPerReadBytes; byte[] data = null; // start watch to look if our connection is still receiving data StartWatch(Settings.Default.DownloadTimeoutTime, IP + ":" + Port); int failCounter = 0; do { data = reader.ReadBytes((int) (missing < max ? missing : max)); LastContact = DateTime.Now; if (data != null && data.Length != 0) { SaveData(data); missing -= data.Length; } else { failCounter++; _log.Warn("StartRun() no data received - " + failCounter); if (failCounter > Settings.Default.MaxNoDateReceived) { _log.Warn("StartRun() no data received - skipping"); break; } } } while (AllowRunning && missing > 0); } _log.Info("StartRun() end"); } } catch (ObjectDisposedException) {} catch (Exception ex) { _log.Fatal("StartRun()", ex); } finally { _log.Info("StartRun() finishing"); FinishWriting(); _tcpClient = null; _writer = null; } } }
protected override void StartRun() { using (_tcpClient = new TcpClient()) { _tcpClient.SendTimeout = Settings.Default.DownloadTimeoutTime * 1000; _tcpClient.ReceiveTimeout = Settings.Default.DownloadTimeoutTime * 1000; try { _tcpClient.Connect(IP, Port); _log.Info("StartRun() connected"); using (Stream stream = new ThrottledStream(_tcpClient.GetStream(), Settings.Default.MaxDownloadSpeedInKB * 1000)) { StartWriting(); using (var reader = new BinaryReader(stream)) { Int64 missing = Size; Int64 max = Settings.Default.DownloadPerReadBytes; byte[] data = null; do { data = reader.ReadBytes((int) (missing < max ? missing : max)); if (data != null && data.Length != 0) { SaveData(data); missing -= data.Length; } else { _log.Warn("StartRun() no data received"); break; } } while (AllowRunning && missing > 0); } _log.Info("StartRun() end"); } } catch (ObjectDisposedException) {} catch (Exception ex) { _log.Fatal("StartRun()", ex); } finally { StopWriting(); _tcpClient = null; _writer = null; } } }
protected override void StartRun() { Name = IP + ":" + Port; Packet.Parent.QueuePosition = 0; Packet.Parent.QueueTime = 0; Packet.Parent.Commit(); using (_tcpClient = new TcpClient()) { _tcpClient.SendTimeout = Settings.Default.DownloadTimeoutTime * 1000; _tcpClient.ReceiveTimeout = Settings.Default.DownloadTimeoutTime * 1000; try { _tcpClient.Connect(IP, Port); _log.Info("StartRun() connected"); using (Stream stream = new ThrottledStream(_tcpClient.GetStream(), Settings.Default.MaxDownloadSpeedInKB * 1000)) { InitializeWriting(); using (var reader = new BinaryReader(stream)) { Int64 missing = MaxData; Int64 max = Settings.Default.DownloadPerReadBytes; byte[] data = null; // start watch to look if our connection is still receiving data StartWatch(Settings.Default.DownloadTimeoutTime, IP + ":" + Port); int failCounter = 0; do { data = reader.ReadBytes((int)(missing < max ? missing : max)); LastContact = DateTime.Now; if (data != null && data.Length != 0) { SaveData(data); missing -= data.Length; } else { failCounter++; _log.Warn("StartRun() no data received - " + failCounter); if (failCounter > Settings.Default.MaxNoDateReceived) { _log.Warn("StartRun() no data received - skipping"); break; } } } while (AllowRunning && missing > 0); } _log.Info("StartRun() end"); } } catch (ObjectDisposedException) {} catch (Exception ex) { _log.Fatal("StartRun()", ex); } finally { _log.Info("StartRun() finishing"); FinishWriting(); _tcpClient = null; _writer = null; } } }