void ProcessTransferUpdate(FileTransfer transfer) { int idx = this.ViewModel.FindIndexById(transfer.Id); if (idx == -1) { Log.WarnFormat("Could not notify ViewModel, id={0}", transfer.Id); } else { // update items FileTransferViewItem viewItem = this.ViewModel.FileTransfers[idx]; viewItem.Progress = transfer.PercentComplete; viewItem.Status = transfer.TransferStatus; viewItem.Message = transfer.TransferStatusMsg; viewItem.Start = transfer.StartTime; viewItem.End = transfer.EndTime; viewItem.CanCancel = FileTransfer.CanCancel(viewItem.Status); viewItem.CanRestart = FileTransfer.CanRestart(viewItem.Status); viewItem.CanDelete = FileTransfer.CanRestart(viewItem.Status); // notify on update this.ViewModel.FileTransfers.ResetItem(idx); } }
public void Cancel(int id) { FileTransfer transfer = GetById(id); if (transfer != null) { if (FileTransfer.CanCancel(transfer.TransferStatus)) { transfer.Cancel(); } else { throw new InvalidOperationException("Can not cancel inactive transfer, id=" + id); } } }