public DownloadTransferMsg(KfsDownloadThread downloadThread) { DownloadThread = downloadThread; }
public DownloadCancelMsg(KfsDownloadThread downloadThread, UInt64 orderID) : base(downloadThread) { OrderID = orderID; }
/// <summary> /// Start a new file transfer batch. /// </summary> public void StartBatch() { Debug.Assert(OrderTree.Count > 0); Debug.Assert(Status == DownloadManagerStatus.Idle); Debug.Assert(TransferThread == null); Debug.Assert(Ticket != null); try { // Build the tree. SortedDictionary<UInt64, KfsDownloadBatchFile> tree = new SortedDictionary<UInt64, KfsDownloadBatchFile>(); foreach (KfsFileDownload f in OrderTree.Values) { Debug.Assert(f.Status == FileTransferStatus.Queued); f.Status = FileTransferStatus.Batched; tree[f.OrderID] = new KfsDownloadBatchFile(f.OrderID, f.Version, VersionCachePath(f.Version)); } // Start the transfer. TransferThread = new KfsDownloadThread(Share, Ticket, tree); TransferThread.Start(); Status = DownloadManagerStatus.Batch; Ticket = null; } catch (Exception ex) { Share.FatalError(ex); } }
/// <summary> /// This method is called when a file download batch has been completed. /// 'successFlag' is true if the thread has been cancelled (this is not /// an error). /// </summary> public void OnBatchCompleted(bool successFlag, String reason) { // Join with the download batch thread. Debug.Assert(TransferThread != null); TransferThread = null; // The transfer batch failed. if (!successFlag) { // Cancel the download of all queued and batched files and do a // full run to clear the downloaded files. CancelOnError(reason); Share.Pipeline.Run("file download batch failed", true); } // The transfer batch succeeded. else { // If the transfers of some files were cancelled, then the download // thread may have bailed out early. Mark the non-cancelled batched // files as non-batched, otherwise cancel their transfers. SortedDictionary<ulong, KfsFileDownload> orderTreeCopy = new SortedDictionary<ulong, KfsFileDownload>(OrderTree); foreach (KfsFileDownload f in orderTreeCopy.Values) { if (f.Status == FileTransferStatus.Batched) { if (f.CancelFlag) OnFileDownloadCancelled(f.OrderID); else f.Status = FileTransferStatus.Queued; } } // Go idle and run the pipeline. GoIdle(); Share.Pipeline.Run("file download batch finished", false); } }