コード例 #1
0
        public ITaskResult Execute(JobTicket objJobTicket)
        {
            TaskResultType         enuTaskResult             = TaskResultType.Completed;
            DownloadResult         objDownloadResult         = null;
            DownloadRequestSession objDownloadRequestSession = new DownloadRequestSession(this, objJobTicket);

            try
            {
                enuTaskResult     = Execute(objDownloadRequestSession);
                objDownloadResult = new DownloadResult(this, enuTaskResult, objDownloadRequestSession.DownloadStats);
            }
            catch (Exception objException)
            {
                ErrorMessage objErrorMessage = new ErrorMessage(objException);
                ApplicationManager.Logs.WriteMessage(objErrorMessage);

                string strErrorMessage = objException.ToString();
                objDownloadResult = new DownloadResult(this, TaskResultType.Failed, objDownloadRequestSession.DownloadStats, strErrorMessage);
            }

            return(objDownloadResult);
        }
コード例 #2
0
 public override TaskResultType Execute(DownloadRequestSession objDownloadRequestSession)
 {
     throw new NotSupportedException("The 'EmptyDownloadRequest' class cannot be executed.");
 }
コード例 #3
0
        public override TaskResultType Execute(DownloadRequestSession objDownloadRequestSession)
        {
            TaskResultType enuTaskResult = TaskResultType.Completed;

            objDownloadRequestSession.UpdateProgess();

            HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create(base.Source);

            if (base.Credentials != null)
            {
                objWebRequest.Credentials = base.Credentials.CreateNetworkCredentials();
            }
            objWebRequest.Timeout = base.TimeOut;
            objWebRequest.Proxy   = ProxySettings.DefaultProxy;

            using (HttpWebResponse objWebResponse = (HttpWebResponse)objWebRequest.GetResponse())
            {
                objDownloadRequestSession.DownloadStats.Size = objWebResponse.ContentLength;
                objDownloadRequestSession.UpdateProgess();

                bool blnFileExists = FileManager.Exists(base.Destination);
                if (blnFileExists == true)
                {
                    FileManager.Delete(base.Destination);
                }

                string strDirectory       = Path.GetDirectoryName(base.Destination);
                bool   blnDirectoryExists = DirectoryManager.Exists(strDirectory);
                if (blnDirectoryExists == false)
                {
                    DirectoryManager.Create(strDirectory);
                }

                using (Stream objResponseStream = objWebResponse.GetResponseStream())
                {
                    using (FileStream objFileStream = new FileStream(base.Destination, FileMode.Create, FileAccess.Write))
                    {
                        byte[] bytBuffer    = new byte[57344];
                        int    intBytesRead = objResponseStream.Read(bytBuffer, 0, bytBuffer.Length);

                        while ((intBytesRead != 0) && (objDownloadRequestSession.JobTicket.Cancelled == false))
                        {
                            objFileStream.Write(bytBuffer, 0, intBytesRead);
                            objFileStream.Flush();

                            objDownloadRequestSession.DownloadStats.BytesReceived += intBytesRead;
                            objDownloadRequestSession.UpdateProgess();

                            intBytesRead = objResponseStream.Read(bytBuffer, 0, bytBuffer.Length);
                        }
                    }
                }

                objDownloadRequestSession.DownloadStats.EndTime = DateTime.Now;
                objDownloadRequestSession.UpdateProgess();

                if (objDownloadRequestSession.JobTicket.Cancelled == true)
                {
                    FileManager.Delete(base.Destination);
                }
            }

            enuTaskResult = ((objDownloadRequestSession.JobTicket.Cancelled == true) ? TaskResultType.Cancelled : TaskResultType.Completed);

            return(enuTaskResult);
        }
コード例 #4
0
 public abstract TaskResultType Execute(DownloadRequestSession objDownloadRequestSession);