Exemple #1
0
 public void OnFileDownloadEvent(Object sender, AutoLoadArgs arg)
 {
     if (DownloadCompleteEvent != null)
     {
         DownloadCompleteEvent(this, arg);
     }
 }
 public void OnFileDownloadEvent(Object sender, AutoLoadArgs arg)
 {
     if (DownloadCompleteEvent != null)
     {
         DownloadCompleteEvent(this, arg);
     }
     //infoView.BeginInvoke(new MethodInvoker(Close));
 }
Exemple #3
0
        private void FileDownloadCallback(IAsyncResult result)
        {
            try {
                RequestState2 rs = (RequestState2)result.AsyncState;

                // Get the WebRequest from RequestState.
                WebRequest req = rs.Request;

                // Call EndGetResponse, which produces the WebResponse object
                //  that came from the request issued above.
                WebResponse resp = req.EndGetResponse(result);

                Stream   ftpStream  = resp.GetResponseStream();
                char     delimiter  = '/';
                string[] splitWords = fileList[rs.index].Split(delimiter);

                FileStream outputStream = new FileStream(folderBrowserDialog1.SelectedPath + "//" + splitWords[splitWords.Length - 1], FileMode.Create);
                long       cl           = resp.ContentLength;
                int        bufferSize   = 2048;
                int        readCount;
                byte[]     buffer = new byte[bufferSize];

                readCount = ftpStream.Read(buffer, 0, bufferSize);
                while (readCount > 0)
                {
                    outputStream.Write(buffer, 0, readCount);
                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                }

                ftpStream.Close();
                outputStream.Close();

                fileDownloadCount++;
                if (fileDownloadCount >= filesToDownload)
                {
                    fileDownloadCount          = 0;
                    toolStripStatusLabel1.Text = "Downloading complete.";
                    AutoLoadArgs arg = new AutoLoadArgs(autoLoadFilePath);
                    EnableDownloadButton(true);
                    OnFileDownloadEvent(this, arg);
                }
                else
                {
                    toolStripStatusLabel1.Text = "Downloaded " + fileDownloadCount.ToString() + " of " + filesToDownload.ToString() + " files...";
                }
                resp.Close();
            } catch (WebException we) {
                MessageBox.Show(we.Message, "File Download Error", MessageBoxButtons.OK);
            }
        }