Exemple #1
0
        public override TaskResultType Execute(UploadRequestSession objUploadRequestSession)
        {
            TaskResultType enuTaskResult = TaskResultType.Completed;

            bool blnFileExists = FileManager.Exists(base.Source);

            if (blnFileExists == false)
            {
                string strFailedMessage = "The source file '" + base.Source + "' does not exist.";
                throw new Exception(strFailedMessage);
            }

            objUploadRequestSession.UploadStats.Size = FileManager.Size(base.Source);
            objUploadRequestSession.UpdateProgess();

            FileWebRequest objWebRequest = (FileWebRequest)WebRequest.Create(base.Destination);

            objWebRequest.Credentials = base.Credentials.CreateNetworkCredentials();
            objWebRequest.Timeout     = base.TimeOut;
            objWebRequest.Method      = WebRequestMethods.File.UploadFile;
            objWebRequest.Proxy       = ProxySettings.DefaultProxy;

            using (Stream objReguestStream = objWebRequest.GetRequestStream())
            {
                using (FileStream objFileStream = new FileStream(base.Source, FileMode.Open, FileAccess.Read))
                {
                    byte[] bytBuffer    = new byte[DefaultBufferSize];
                    int    intBytesRead = objFileStream.Read(bytBuffer, 0, bytBuffer.Length);

                    while ((intBytesRead != 0) && (objUploadRequestSession.JobTicket.Cancelled == false))
                    {
                        objReguestStream.Write(bytBuffer, 0, intBytesRead);
                        objUploadRequestSession.UploadStats.BytesSent += intBytesRead;
                        intBytesRead = objFileStream.Read(bytBuffer, 0, bytBuffer.Length);

                        objUploadRequestSession.UpdateProgess();
                    }
                }

                objUploadRequestSession.UploadStats.EndTime = DateTime.Now;
                objUploadRequestSession.UpdateProgess();
            }

            enuTaskResult = ((objUploadRequestSession.JobTicket.Cancelled == true) ? TaskResultType.Cancelled : TaskResultType.Completed);
            return(enuTaskResult);
        }
Exemple #2
0
        public ITaskResult Execute(JobTicket objJobTicket)
        {
            TaskResultType       enuTaskResult           = TaskResultType.Completed;
            UploadResult         objUploadResult         = null;
            UploadRequestSession objUploadRequestSession = new UploadRequestSession(this, objJobTicket);

            try
            {
                enuTaskResult   = Execute(objUploadRequestSession);
                objUploadResult = new UploadResult(this, enuTaskResult, objUploadRequestSession.UploadStats);
            }
            catch (Exception objException)
            {
                ErrorMessage objErrorMessage = new ErrorMessage(objException);
                ApplicationManager.Logs.WriteMessage(objErrorMessage);

                string strErrorMessage = objException.ToString();
                objUploadResult = new UploadResult(this, TaskResultType.Failed, objUploadRequestSession.UploadStats, strErrorMessage);
            }

            return(objUploadResult);
        }
Exemple #3
0
 public override TaskResultType Execute(UploadRequestSession objUploadRequestSession)
 {
     throw new NotSupportedException("The 'EmptyUploadRequest' class cannot be executed.");
 }
Exemple #4
0
 public abstract TaskResultType Execute(UploadRequestSession objUploadRequestSession);