예제 #1
0
        protected static void HttpDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            NetworkDownloadInfo dlInfo = (NetworkDownloadInfo)e.UserState;

            dlInfo.progress    = 1.0;
            dlInfo.error       = e.Error;
            dlInfo.cancelled   = e.Cancelled;
            dlInfo.destFileMD5 = MD5(dlInfo.destFilePath);

            if (e.Error != null)
            {
                Console.WriteLine("Error: " + e.Error.ToString());
            }
            else if (e.Cancelled)
            {
                Console.WriteLine("Download cancelled");
            }
            else
            {
            }
            //file finished downloading
            Console.WriteLine("Download Completed");

            if (dlInfo.responseDelegate != null)
            {
                dlInfo.responseDelegate.Invoke(dlInfo);
            }
        }
예제 #2
0
        public static void HttpDownloadFile(string url, string destFilePath, Action <NetworkDownloadInfo> responseDelegate, Action <NetworkDownloadInfo> progressDelegate)
        {
            if (File.Exists(destFilePath))
            {
                Exception e = new Exception("File already exists: " + destFilePath);

                throw(e);
            }

            NetworkDownloadInfo dlInfo = new NetworkDownloadInfo();

            WebClient client = new WebClient();
            Uri       uri    = new Uri(url);

            client.DownloadFileCompleted   += new AsyncCompletedEventHandler(HttpDownloadFileCompleted);
            client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(HttpDownloadFileProgress);

            dlInfo.url              = url;
            dlInfo.destFilePath     = destFilePath;
            dlInfo.responseDelegate = responseDelegate;
            dlInfo.progressDelegate = progressDelegate;
            dlInfo.client           = client;

            client.DownloadFileAsync(uri, destFilePath, dlInfo);
        }
예제 #3
0
        protected static void HttpDownloadFileProgress(object sender, DownloadProgressChangedEventArgs e)
        {
            NetworkDownloadInfo dlInfo = (NetworkDownloadInfo)e.UserState;

            dlInfo.progress = (double)e.BytesReceived / (double)e.TotalBytesToReceive;

            if (dlInfo.progressDelegate != null)
            {
                dlInfo.progressDelegate.Invoke(dlInfo);
            }
            // Displays the operation identifier, and the transfer progress.
            Console.WriteLine("{0}    downloaded {1} of {2} bytes. {3} % complete...",
                              Path.GetFileName(dlInfo.destFilePath),
                              e.BytesReceived,
                              e.TotalBytesToReceive,
                              e.ProgressPercentage);
        }
예제 #4
0
 protected void FileDownloadProgress(NetworkDownloadInfo info)
 {
 }
예제 #5
0
 protected void FileDownloaded(NetworkDownloadInfo info)
 {
 }