public void AddDownloadSize(int size) { if (sizeDownloadList.Count == 2) sizeDownloadList[1] = new TransLog(size, DateTime.Now); else sizeDownloadList.Add(new TransLog(size, DateTime.Now)); sizeDownload += size; }
public void AddSpeedLog(TransLog speed) { lock (this) { if (speedLog == null) { speedLog = new List <TransLog>(); } if (speed.size > 0) { speedLog.Add(speed); } while (speedLog.Count > 20) { speedLog.RemoveAt(0); } } }
public void AddSpeedLog(TransLog speed) { lock (this) { if (speedLog == null) speedLog = new List<TransLog>(); if (speed.size > 0) speedLog.Add(speed); while (speedLog.Count > 20) { speedLog.RemoveAt(0); } } }
private static void UpdateTransLog(IList <TransLog> transLog, int bytes, DateTime now, ref long maxTrans, bool updateMaxTrans) { if (transLog.Count > 0) { const int base_time_diff = 100; const int max_time_diff = 3 * base_time_diff; var time_diff = (int)(now - transLog[transLog.Count - 1].recvTime).TotalMilliseconds; if (time_diff < 0) { transLog.Clear(); transLog.Add(new TransLog(bytes, now)); return; } if (time_diff < base_time_diff) { transLog[transLog.Count - 1].times++; transLog[transLog.Count - 1].size += bytes; if (transLog[transLog.Count - 1].endTime < now) { transLog[transLog.Count - 1].endTime = now; } } else { if (time_diff >= 0) { transLog.Add(new TransLog(bytes, now)); var base_times = 1 + (maxTrans > 1024 * 512 ? 1 : 0); var last_index = transLog.Count - 1 - 2; if (updateMaxTrans && transLog.Count >= 6 && transLog[last_index].times > base_times) { var begin_index = last_index - 1; for (; begin_index > 0; --begin_index) { if ((transLog[begin_index + 1].recvTime - transLog[begin_index].endTime).TotalMilliseconds > max_time_diff || transLog[begin_index].times <= base_times ) { break; } } if (begin_index <= last_index - 4) { begin_index++; var t = new TransLog(transLog[begin_index].firstsize, transLog[begin_index].recvTime) { endTime = transLog[last_index].endTime, size = 0 }; for (var i = begin_index; i <= last_index; ++i) { t.size += transLog[i].size; } if (maxTrans == 0) { maxTrans = (long)((t.size - t.firstsize) / (t.endTime - t.recvTime).TotalSeconds * 0.7); } else { const double a = 2.0 / (1 + 32); maxTrans = (long)(0.5 + maxTrans * (1 - a) + a * ((t.size - t.firstsize) / (t.endTime - t.recvTime).TotalSeconds)); } } } } else { var i = transLog.Count - 1; for (; i >= 0; --i) { if (transLog[i].recvTime > now && i > 0) { continue; } transLog[i].times += 1; transLog[i].size += bytes; if (transLog[i].endTime < now) { transLog[i].endTime = now; } break; } } } while (transLog.Count > 0 && now > transLog[0].recvTime.AddSeconds(AvgTime)) { transLog.RemoveAt(0); } } else { transLog.Add(new TransLog(bytes, now)); } }
protected static void UpdateTransLog(List <TransLog> transLog, int bytes, DateTime now, ref long maxTrans, bool updateMaxTrans) { if (transLog.Count > 0) { const int base_time_diff = 100; const int max_time_diff = 3 * base_time_diff; int time_diff = (int)(now - transLog[transLog.Count - 1].recvTime).TotalMilliseconds; if (time_diff < base_time_diff) { transLog[transLog.Count - 1].times++; transLog[transLog.Count - 1].size += bytes; if (transLog[transLog.Count - 1].endTime < now) { transLog[transLog.Count - 1].endTime = now; } } else { if (time_diff >= 0) { transLog.Add(new TransLog(bytes, now)); int base_times = maxTrans > 1024 * 100 ? 3 : 2; int last_index = (transLog.Count - 1) - 2; if (updateMaxTrans && transLog.Count >= 5 && transLog[last_index].times > base_times) { int begin_index = last_index - 1; for (; begin_index > 0; --begin_index) { if ((transLog[begin_index + 1].recvTime - transLog[begin_index].endTime).TotalMilliseconds > max_time_diff || transLog[begin_index].times <= base_times ) { break; } } if (begin_index <= last_index - 3) { begin_index++; TransLog t = new TransLog(transLog[begin_index].firstsize, transLog[begin_index].recvTime); t.endTime = transLog[last_index].endTime; t.size = 0; for (int i = begin_index; i <= last_index; ++i) { t.size += transLog[i].size; } if (maxTrans == 0) { maxTrans = (long)((t.size - t.firstsize) / (t.endTime - t.recvTime).TotalSeconds * 0.7); } else { double a = 2.0 / (1 + 32); maxTrans = (long)(0.5 + maxTrans * (1 - a) + a * ((t.size - t.firstsize) / (t.endTime - t.recvTime).TotalSeconds)); } } } } else { int i = transLog.Count - 1; for (; i >= 0; --i) { if (transLog[i].recvTime > now && i > 0) { continue; } transLog[i].times += 1; transLog[i].size += bytes; if (transLog[i].endTime < now) { transLog[i].endTime = now; } break; } } } while (transLog.Count > 0 && now > transLog[0].recvTime.AddSeconds(avgTime)) { transLog.RemoveAt(0); } } else { transLog.Add(new TransLog(bytes, now)); } }