public static DownloadTaskEntry convert(Task _task) { DownloadTask task = (DownloadTask)_task; DownloadTaskEntry res = new DownloadTaskEntry(); res.fileName = task.fileName; res.url = task.url; res.id = task.id; res.isDone = task.isDone(); res.leftTime = "--"; string percent = "0%"; string rate = "0k/s"; string leftTime = ""; if (task.getSize() == -1 || task.getSize() == 0) { percent = "0%"; } else { long curr = task.getCurrent(); long size = task.getSize(); long lastPos = task.getLastPos(); percent = NumberUtil.toFixed(((curr + 0.0) / size) * 100, 1); percent = percent == "100.0" ? "100" : percent; percent = percent + "%"; var deltaRate = (curr - lastPos + 0.0) / _1K; res.speedL = deltaRate; rate = NumberUtil.toFixed(deltaRate, 1) + " k/s"; if (deltaRate >= _1K) { rate = NumberUtil.toFixed(deltaRate / _1K, 2) + " M/s"; } long leftSize = size - curr; if (curr == lastPos) { leftTime = ""; } else { var time = (leftSize) / (curr - lastPos);// seconds leftTime = HourTimeConverter.convert(time); } } res.speed = rate; if (task.isDone()) percent = "100%"; res.percent = percent; res.leftTime = leftTime; res.finishedTime = task.finishedTime(DateTime.MinValue); return res; }
private void addRow(DownloadTaskEntry entry) { this.taskGrid.Rows.Add(new string[] { entry.id, entry.fileName, entry.percent, entry.speed, entry.leftTime,GlobalUtil.formatTime(entry.finishedTime),entry.url }); }
private void updateGrid(DownloadTaskEntry taskEntry) { string taskId = taskEntry.id; int rowCount = this.taskGrid.RowCount; for (int i = 0; i < rowCount; i++) { try { string id = this.taskGrid.Rows[i].Cells[0].Value.ToString(); if (id == taskId) { var speed = taskEntry.speed; var leftTime = taskEntry.leftTime; if (taskEntry.isDone) { speed = ""; leftTime = ""; } //this.taskGrid.Rows[i].Cells[1].Value = taskEntry.fileName; this.taskGrid.Rows[i].Cells[2].Value = taskEntry.percent; this.taskGrid.Rows[i].Cells[3].Value = speed; this.taskGrid.Rows[i].Cells[4].Value = leftTime; this.taskGrid.Rows[i].Cells[5].Value = GlobalUtil.formatTime(taskEntry.finishedTime); break; } } catch (Exception e) { } } }