示例#1
0
 /// <summary>
 /// Tidy-up the state after a download batch has been completed or an
 /// error occured.
 /// </summary>
 private void GoIdle()
 {
     Status = DownloadManagerStatus.Idle;
 }
示例#2
0
        /// <summary>
        /// This method is called when a download ticket reply is received.
        /// </summary>
        public void OnTicket(AnpMsg m)
        {
            Debug.Assert(Status == DownloadManagerStatus.Ticket);
            Debug.Assert(Ticket == null);

            // Store the ticket and run the pipeline.
            if (m.Type == KAnpType.KANP_RES_KFS_DOWNLOAD_REQ)
            {
                Status = DownloadManagerStatus.Idle;
                Ticket = m.Elements[0].Bin;
                Share.Pipeline.Run("got download ticket", false);
            }

            // On failure, cancel all downloads.
            else
            {
                CancelOnError(m.Elements[0].String);
                Share.Pipeline.Run("could not obtain download ticket", true);
            }
        }
示例#3
0
        /// <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);
            }
        }
示例#4
0
 /// <summary>
 /// Ask a download ticket.
 /// </summary>
 public void AskTicket()
 {
     Debug.Assert(Status == DownloadManagerStatus.Idle);
     Debug.Assert(Ticket == null);
     Share.AskDownloadTicket();
     Status = DownloadManagerStatus.Ticket;
 }