Ejemplo n.º 1
0
        private void CalculateFileSizes()
        {
            FireEventFromWorker(UploadTransitions.CalculationFileSizesStarted);
            _totaluploadsize = 0;

            for (int i = 0; i <= (Uploads.Count - 1); i++)
            {
                _uploaderworker.ReportProgress((int)UploadInvokations.CalculatingFileNrRaiser, i + 1);
                try
                {
                    UploadFileInfo _upload = Uploads[i];

                    if (File.Exists(_upload.Path))
                    {
                        FileInfo _file = new FileInfo(_upload.Path);
                        _totaluploadsize += _file.Length;
                    }
                }
                catch { }
            }

            FireEventFromWorker(UploadTransitions.FileSizesCalculationComplete);
        }
Ejemplo n.º 2
0
        private void UploadFile(int index)
        {
            _currentuploadsize = 0; FireEventFromWorker(UploadTransitions.FileUploadAttempting);

            UploadFileInfo _file = Uploads[index]; double _size = 0;

            byte[]    _readbytes = new byte[PacketSize]; int _currentpackagesize = 0;
            FileInfo  _fileinfo = new FileInfo(_file.Path); FileStream _filestream = null;
            Stopwatch _speedtimer = new Stopwatch(); Stream _stream = null;
            Int32     _readings = 0; Exception _ex = null; int _packet = PacketSize;

            try { _size = _fileinfo.Length; }
            catch { }

            FtpWebRequest _request = null; FtpWebResponse _response = null;

            try
            {
                string _ftpaddress = Path.GetDirectoryName(Address).ToLower().Replace("ftp:\\", "ftp://").Replace("\\", "/") + "/" + Path.GetFileName(_file.Path);
                _request = (FtpWebRequest)WebRequest.Create(_ftpaddress);
                if (_credential != null)
                {
                    _request.Credentials = _credential;
                }
                _request.KeepAlive     = true; _request.UseBinary = true;
                _request.Method        = WebRequestMethods.Ftp.UploadFile;
                _filestream            = new FileStream(_file.Path, FileMode.Open);
                _request.ContentLength = VisualBasic.CLng(_size); _stream = _request.GetRequestStream();
            }
            catch (Exception ex) { _ex = ex; }

            _currentuploadsize = _size; FireEventFromWorker(UploadTransitions.FileUploadStarted);

            if (_ex != null)
            {
                _uploaderworker.ReportProgress((int)UploadInvokations.FileUploadFailedRaiser, _ex);
            }
            else
            {
                _currentlyuploaded = 0; _currentpackagesize = 0;

                do
                {
                    if (_uploaderworker.CancellationPending)
                    {
                        _filestream.Close(); _stream.Close(); _speedtimer.Stop();
                        if (_response != null)
                        {
                            _response.Close();
                        }
                        return;
                    }

                    _trigger.WaitOne(); _speedtimer.Start();
                    if (_stream == null &&
                        _response != null)
                    {
                        _stream = _response.GetResponseStream();
                    }


                    if (_readbytes.Length < PacketSize)
                    {
                        _packet = _readbytes.Length;
                    }
                    else
                    {
                        _packet = PacketSize;
                    }

                    _currentpackagesize = _filestream.Read(_readbytes, 0, _packet);
                    _currentlyuploaded += _currentpackagesize; _totaluploaded += _currentpackagesize;
                    FireEventFromWorker(UploadTransitions.ProgressChanged);

                    _stream.Write(_readbytes, 0, _currentpackagesize); _readings += 1;

                    if (_readings >= StopWatchCycle)
                    {
                        _uploadspeed = VisualBasic.CInt(_packet * StopWatchCycle * 1000 / (_speedtimer.ElapsedMilliseconds + 1));
                        _speedtimer.Reset(); _readings = 0;
                    }
                } while (_currentpackagesize != 0);

                _stream.Close(); _filestream.Close(); _speedtimer.Stop();
                FireEventFromWorker(UploadTransitions.FileUploadSucceeded);
            }

            FireEventFromWorker(UploadTransitions.FileUploadStopped);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds a new upload file information into the collection.
 /// </summary>
 /// <param name="upload">Upload file information</param>
 /// <returns></returns>
 public int Add(UploadFileInfo upload)
 {
     return(List.Add(upload));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns whether the specified upload information already exists within the collection or not.
 /// </summary>
 /// <param name="upload"></param>
 /// <returns></returns>
 public bool Contains(UploadFileInfo upload)
 {
     return(List.Contains(upload));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds a new upload file information into the collection.
 /// </summary>
 /// <param name="path">Local file path</param>
 /// <returns></returns>
 public UploadFileInfo Add(string path)
 {
     UploadFileInfo _upload = new UploadFileInfo(path);
     int            _index  = Add(_upload); return((UploadFileInfo)List[_index]);
 }
 /// <summary>
 ///  Removes the specified upload file information from the collection.
 /// </summary>
 /// <param name="upload">Development.Materia.Net.UploadFileInfo to remove.</param>
 public void Remove(UploadFileInfo upload)
 {
     if (Contains(upload)) List.Remove(upload);
 }
 /// <summary>
 /// Returns whether the specified upload information already exists within the collection or not.
 /// </summary>
 /// <param name="upload">Development.Materia.Net.UploadFileInfo to evaluate.</param>
 /// <returns>True if the specified Development.Materia.Net.UploadFileInfo aready exists within the collection otherwise false.</returns>
 public bool Contains(UploadFileInfo upload)
 { return List.Contains(upload); }
 /// <summary>
 /// Adds a new upload file information into the collection.
 /// </summary>
 /// <param name="upload">Upload file information</param>
 /// <returns>Index of the added Development.Materia.Net.UploadFileInfo in the collection.</returns>
 public int Add(UploadFileInfo upload)
 { return List.Add(upload); }
 /// <summary>
 /// Adds a new upload file information into the collection.
 /// </summary>
 /// <param name="path">Local file path</param>
 /// <returns>Newly added Development.Materia.Net.UploadFileInfo.</returns>
 public UploadFileInfo Add(string path)
 {
     UploadFileInfo _upload = new UploadFileInfo(path);
     int _index = Add(_upload); return (UploadFileInfo)List[_index];
 }