예제 #1
0
 private void Clear()
 {
     FileList.Items.Clear();
     downloadFile.Enabled = false;
     lblStatus.Text       = string.Empty;
     DownloadStatusTextbox.Clear();
     dlProgressBar.Value = 0;
 }
예제 #2
0
        public void DownloadFiles()
        {
            DownloadStatusTextbox.Clear();
            UpdateStatus(string.Empty);


            List <DownloadArg> downloadArgs = new List <DownloadArg>();

            for (int i = 0; i < FileList.Items.Count; i++)
            {
                string _strListItem = FileList.Items[i].ToString();
                string _strFileUri  = string.Empty;
                string _strFilePath = string.Empty;
                if (!string.IsNullOrEmpty(_strListItem))
                {
                    _strFileUri  = GetUri(_strListItem);
                    _strFilePath = GetFileName(_strListItem);
                    if (string.IsNullOrEmpty(_strFileUri) || string.IsNullOrEmpty(_strFilePath))
                    {
                        break;
                    }
                }
                downloadArgs.Add(new DownloadArg {
                    SourceLogFilename = _strListItem,
                    SourceLogFileUri  = _strFileUri,
                    TargetLogFile     = _strFilePath
                });
            }

            if (downloadArgs.Count > 0)
            {
                ParameterizedThreadStart ts = new ParameterizedThreadStart(doDownloadFiles);
                Thread downloadThread       = new Thread(ts);
                downloadThread.Start(downloadArgs);
            }
        }
예제 #3
0
        private void doDownloadFiles(object args)
        {
            List <DownloadArg> downloadArgs = args as List <DownloadArg>;
            int counter = 0;
            int total   = downloadArgs.Count;

            //dlProgressBar.Maximum = total;
            this.Invoke((Action) delegate(){
                downloadFile.Enabled         = false;
                dlProgressBar.Visible        = true;
                CancelDownloadButton.Visible = true;
            });
            _downloadCanceled = false;
            _resetEvent       = new AutoResetEvent(false);
            foreach (var downloadArg in downloadArgs)
            {
                counter++;
                try
                {
                    this.Invoke((Action) delegate(){
                        DownloadStatusTextbox.AppendText(string.Format("Downloading {0} to {1} ({2}/{3}) ... ",
                                                                       downloadArg.SourceLogFilename,
                                                                       downloadArg.TargetLogFile, counter, total));
                        dlProgressBar.Value = 0;
                    });

                    wcClient = new WebClient();
                    setCredentials(wcClient);
                    wcClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
                    wcClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(wc_DownloadFileCompleted);
                    wcClient.DownloadFileAsync(new Uri(downloadArg.SourceLogFileUri), downloadArg.TargetLogFile);

                    _resetEvent.WaitOne();

                    this.Invoke((Action) delegate()
                    {
                        DownloadStatusTextbox.AppendText((!_downloadCanceled ? "[OK]" : "[Canceled]") + Environment.NewLine);
                        // TODO: JABE uncomment
                        //dlProgressBar.Value = counter;
                    });
                    if (_downloadCanceled)
                    {
                        break;
                    }
                }
                catch (WebException exc)
                {
                    this.Invoke((Action) delegate()
                    {
                        DownloadStatusTextbox.AppendText("[FAILED] Details: " + exc.Message + Environment.NewLine);
                    });
                }
            }
            this.Invoke((Action) delegate()
            {
                DownloadStatusTextbox.AppendText(Environment.NewLine + (_downloadCanceled ? "DOWNLOAD CANCELED" : "DOWNLOAD COMPLETED"));

                downloadFile.Enabled         = true;
                dlProgressBar.Value          = 0;
                dlProgressBar.Visible        = false;
                PercentageLabel.Text         = string.Empty;
                CancelDownloadButton.Visible = false;
            });
        }