private void UpdateProgress(OperationInfo op) { ProgressListview.ProgressSubItem progress = op.Tag as ProgressListview.ProgressSubItem; if (progress != null) { progress.ProgressMaxValue = op.totalSize; progress.ProgressValue = op.doneSize; progress.ForeColor = GetStatusColor(op); progress.ShowProgress = true; ListViewItem item = progress.Owner; if (item != null) { item.SubItems[2].Text = GetSizeText(op); } double percent = 0; if (op.totalSize > 0) { percent = (double)op.doneSize / (double)op.totalSize; if (percent > 1.0f) { percent = 1.0f; } } progress.Text = string.Format("{0}%", percent.ToString("F2")); item.EnsureVisible(); } }
private void AddItems(OperationInfo[] ops, int i = -1) { lvItems.BeginUpdate(); foreach(OperationInfo op in ops) { ListViewItem item = new ListViewItem(op.from); item.Tag = op; if (op.operation == Operation.Download) item.ImageIndex = 1; else item.ImageIndex = 0; ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem(item, op.to); item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(item, GetSizeText(op)); item.SubItems.Add(subitem); ProgressListview.ProgressSubItem progress = new ProgressListview.ProgressSubItem(item, GetStatusText(op)); progress.Owner = item; progress.ProgressMaxValue = op.totalSize; progress.ProgressValue = op.doneSize; progress.ShowProgress = false; progress.ForeColor = GetStatusColor(op); progress.Tag = op; op.Tag = progress; item.SubItems.Add(progress); if (i >= 0) lvItems.Items.Insert(i, item); else lvItems.Items.Add(item); Statistics(op, 1); } lvItems.EndUpdate(); }
private void ChangeOpStatus(OperationInfo op, OperationStatus status) { Statistics(op, -1); op.status = status; Statistics(op, 1); worker.queue.place(op); ProgressListview.ProgressSubItem progress = op.Tag as ProgressListview.ProgressSubItem; if (progress != null) { progress.ForeColor = GetStatusColor(op); progress.Text = GetStatusText(op); } }
private void RemoveItems(OperationInfo[] ops) { lvItems.BeginUpdate(); foreach (OperationInfo op in ops) { ProgressListview.ProgressSubItem progress = op.Tag as ProgressListview.ProgressSubItem; if (progress != null && progress.Owner != null) { lvItems.Items.Remove(progress.Owner); } Statistics(op, -1); } lvItems.EndUpdate(); }
private void worker_OnCompleted(object sender, DUWorkerEventArgs e) { Interlocked.Add(ref pendingCount, -1); Statistics(e.op, 1); ProgressListview.ProgressSubItem progress = e.op.Tag as ProgressListview.ProgressSubItem; if (progress != null && progress.Owner != null) { lock (locker) { if (updatedOp.Contains(e.op)) { updatedOp.Remove(e.op); } } if (lvItems.InvokeRequired) { lvItems.Invoke(new AnonymousFunction(delegate() { progress.ShowProgress = false; progress.ForeColor = GetStatusColor(e.op); progress.Text = GetStatusText(e.op); ListViewItem item = progress.Owner; if (item != null) { item.SubItems[2].Text = GetSizeText(e.op); } })); } else { progress.ShowProgress = false; progress.ForeColor = GetStatusColor(e.op); progress.Text = GetStatusText(e.op); ListViewItem item = progress.Owner; if (item != null) { item.SubItems[2].Text = GetSizeText(e.op); } } } //重置速度计算 lock (locker) { speed = 0; orgDoneSize = 0; } }
private void AddItems(OperationInfo[] ops, int i = -1) { lvItems.BeginUpdate(); foreach (OperationInfo op in ops) { ListViewItem item = new ListViewItem(op.from); item.Tag = op; if (op.operation == Operation.Download) { item.ImageIndex = 1; } else { item.ImageIndex = 0; } ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem(item, op.to); item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(item, GetSizeText(op)); item.SubItems.Add(subitem); ProgressListview.ProgressSubItem progress = new ProgressListview.ProgressSubItem(item, GetStatusText(op)); progress.Owner = item; progress.ProgressMaxValue = op.totalSize; progress.ProgressValue = op.doneSize; progress.ShowProgress = false; progress.ForeColor = GetStatusColor(op); progress.Tag = op; op.Tag = progress; item.SubItems.Add(progress); if (i >= 0) { lvItems.Items.Insert(i, item); } else { lvItems.Items.Add(item); } Statistics(op, 1); } lvItems.EndUpdate(); }
private void worker_OnCompleted(object sender, DUWorkerEventArgs e) { Interlocked.Add(ref pendingCount, -1); Statistics(e.op, 1); if (e.op.status == OperationStatus.Fail) { if (AppSettings.RetryWhenDownloadFailed && e.op.operation == Operation.Download) { if (lvItems.InvokeRequired) { lvItems.Invoke(new AnonymousFunction(delegate() { ChangeOpStatus(e.op, OperationStatus.Pending); })); } else { ChangeOpStatus(e.op, OperationStatus.Pending); } return; } else if (AppSettings.RetryWhenUploadFailed && e.op.operation == Operation.Upload) { if (lvItems.InvokeRequired) { lvItems.Invoke(new AnonymousFunction(delegate() { ChangeOpStatus(e.op, OperationStatus.Pending); })); } else { ChangeOpStatus(e.op, OperationStatus.Pending); } return; } } ProgressListview.ProgressSubItem progress = e.op.Tag as ProgressListview.ProgressSubItem; if (progress != null && progress.Owner != null) { lock (locker) { if (updatedOp.Contains(e.op)) { updatedOp.Remove(e.op); } } if (lvItems.InvokeRequired) { lvItems.Invoke(new AnonymousFunction(delegate() { progress.ShowProgress = false; progress.ForeColor = GetStatusColor(e.op); progress.Text = GetStatusText(e.op); ListViewItem item = progress.Owner; if (item != null) { item.SubItems[2].Text = GetSizeText(e.op); } })); } else { progress.ShowProgress = false; progress.ForeColor = GetStatusColor(e.op); progress.Text = GetStatusText(e.op); ListViewItem item = progress.Owner; if (item != null) { item.SubItems[2].Text = GetSizeText(e.op); } } } //重置速度计算 lock (locker) { speed = 0; orgDoneSize = 0; } }