示例#1
0
        /// <summary>
        /// Tells the transfer service that transmission is being
        /// paused for an unknown period of time. This should keep
        /// the transfer enabled, but gives the service time to
        /// free or unlock resources.
        /// </summary>
        /// <param name="transferId">Identifies the transfer and resource.</param>
        /// <exception cref="UnknownTransferException">In case no such transfer
        /// is currently maintained.</exception>
        public virtual void PauseTransfer(string transferId)
        {
            var context = IsUploadService
                      ? FileSystemTask.UploadTransferPauseRequest
                      : FileSystemTask.DownloadTransferPauseRequest;

            TTransfer transfer = GetCachedTransfer(transferId, true, context);

            lock (transfer.SyncRoot)
            {
                if (!transfer.Status.Is(TransferStatus.Starting, TransferStatus.Running))
                {
                    AuditEvent auditEvent = AuditEvent.InvalidTransferStatusChange;
                    AuditHelper.AuditInvalidTransferPauseRequest(Auditor, transfer, context, auditEvent);

                    string msg = "Only active transfers can be paused. Current status is: [{0}].";
                    msg = String.Format(msg, transfer.Status);

                    throw new TransferStatusException(msg)
                          {
                              IsAudited = true, EventId = (int)auditEvent
                          };
                }

                PauseTransferImpl(transfer);
                transfer.Status = TransferStatus.Paused;

                AuditHelper.AuditChangedTransferStatus(Auditor, transfer, context, AuditEvent.TransferPaused);
            }
        }