示例#1
0
        private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                // handle error scenario
                //throw e.Error;
            }

            if (e.Cancelled)
            {
                // handle cancelled scenario
            }
            else
            {
                if (_downloadList.Count > 0)
                {
                    DownloadInfo downloadInfo = _downloadList[0];

                    string exePath   = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    string localPath = exePath + "\\" + downloadInfo._filePath.Replace('/', '\\');

                    _downloadList.RemoveAt(0);

                    if (downloadInfo._completeHandler != null)
                    {
                        downloadInfo._completeHandler(localPath);
                    }
                }
            }

            DownloadAsync();
        }
示例#2
0
        private void DownloadAsync()
        {
            _Client = null;

            if (_downloadList.Any())
            {
                DownloadInfo downloadInfo = _downloadList[0];

                string exePath   = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                string localPath = exePath + "\\" + downloadInfo._filePath.Replace('/', '\\');

                if (File.Exists(localPath) == true)
                {
                    _downloadList.RemoveAt(0);

                    if (downloadInfo._completeHandler != null)
                    {
                        downloadInfo._completeHandler(localPath);
                    }

                    DownloadAsync();
                    return;
                }

                string[] folderNames = localPath.Split('\\');
                string   folderPath  = string.Empty;
                fileName = folderNames[folderNames.Length - 1];
                for (int i = 0; i < folderNames.Length - 1; i++)
                {
                    folderPath += folderNames[i];

                    if (Directory.Exists(folderPath) == false)
                    {
                        Directory.CreateDirectory(folderPath);
                    }

                    folderPath += '\\';
                }

                _Client       = new WebClient();
                _Client.Proxy = null;

                _Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                _Client.DownloadFileCompleted   += new AsyncCompletedEventHandler(client_DownloadFileCompleted);

                var url = Window1._ServerPath + downloadInfo._filePath;

                _Client.DownloadFileAsync(new Uri(url), localPath);

                _ProgressBarWindow.Show();
                _ProgressBarWindow.Left = downloadInfo._window.Left + downloadInfo._window.Width / 2;
                _ProgressBarWindow.Top  = downloadInfo._window.Top + downloadInfo._window.Height / 2;

                return;
            }

            _ProgressBarWindow.Hide();
        }
示例#3
0
        private AsyncCompletedEventHandler DownloadFileCompleted(string strFileName, DownloadInfo downloadInfo)
        {
            Action <object, AsyncCompletedEventArgs> action = (sender, e) =>
            {
                var _filename = strFileName;

                if (e.Error != null)
                {
                    //throw e.Error;
                }

                if (downloadInfo._completeHandler != null)
                {
                    downloadInfo._completeHandler(strFileName);
                }
            };

            return(new AsyncCompletedEventHandler(action));
        }