Click here to Skip to main content
15,881,715 members
Articles / Programming Languages / C#

Downloader Component

Rate me:
Please Sign up or sign in to vote.
4.82/5 (20 votes)
14 Jan 20072 min read 84.4K   3.7K   103  
A component to download files over the network with support for proxies, SSL and resume.
using System;

namespace Downloader.Core
{
    #region DownloadErrorEventArgs

    /// <summary>
    /// AutoUpdateErrorEventArgs
    /// </summary>
    public class DownloadErrorEventArgs : EventArgs
    {
        #region Fields

        private Exception ex;
        private string message;

        #endregion

        #region Ctor

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="ex"></param>
        /// <param name="message"></param>
        public DownloadErrorEventArgs(Exception ex, string message)
        {
            this.ex = ex;
            this.message = message;
        }

        #endregion

        #region Props

        /// <summary>
        /// Exception
        /// </summary>
        public Exception Exception
        {
            get { return ex; }
        }

        /// <summary>
        /// Message
        /// </summary>
        public string Message
        {
            get { return message; }
        }

        #endregion
    }

    #endregion

    #region DownloadProgressEventArgs

    /// <summary>
    /// AutoUpdateProgressEventArgs
    /// </summary>
    public class DownloadProgressEventArgs : EventArgs
    {
        #region Fields

        private long _totalBytes;
        private long _bytesRead;
        private string _message;

        #endregion

        #region Ctor

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="totalBytes"></param>
        /// <param name="message"></param>
        /// <param name="bytesRead"></param>
        public DownloadProgressEventArgs(long bytesRead, long totalBytes, string message)
        {
            _totalBytes = totalBytes;
            _message = message;
            _bytesRead = bytesRead;
        }

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="bytesRead"></param>
        /// <param name="totalBytes"></param>
        public DownloadProgressEventArgs(long bytesRead, long totalBytes)
            : this(bytesRead, totalBytes, string.Empty)
        {
        }

        /// <summary>
        /// Ctor
        /// </summary>
        public DownloadProgressEventArgs()
            : this(0, 0)
        {
        }

        #endregion

        #region Props

        /// <summary>
        /// FileLength
        /// </summary>
        public long BytesRead
        {
            get { return _bytesRead; }
        }

        /// <summary>
        /// Current Progress
        /// </summary>
        public long TotalBytes
        {
            get { return _totalBytes; }
        }

        /// <summary>
        /// Message
        /// </summary>
        public string Message
        {
            get { return _message; }
        }

        #endregion
    }

    #endregion

    #region DownloadCompleteEventArgs

    /// <summary>
    /// AutoUpdateCompleteEventArgs
    /// </summary>
    public class DownloadCompleteEventArgs : EventArgs
    {
        #region Fields

        private bool _isSuccessfull;
        private bool _isAborted;

        #endregion

        #region Ctor

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="isSuccessfull"></param>
        /// <param name="isAborted"></param>
        public DownloadCompleteEventArgs(bool isSuccessfull, bool isAborted)
        {
            _isSuccessfull = isSuccessfull;
            _isAborted = isAborted;
        }

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="isSuccessfull"></param>
        public DownloadCompleteEventArgs(bool isSuccessfull)
        {
            _isSuccessfull = isSuccessfull;
        }

        /// <summary>
        /// Ctor
        /// </summary>
        public DownloadCompleteEventArgs() : this(true, false)
        {
        }

        #endregion

        #region Props

        /// <summary>
        /// Is operation finished successfully
        /// </summary>
        public bool IsSuccessfull
        {
            get { return _isSuccessfull; }
        }

        /// <summary>
        /// Is download aborted
        /// </summary>
        public bool IsAborted
        {
            get { return _isAborted; }
        }

        #endregion
    }

    #endregion
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Readify
Australia Australia
Working on both Java and .NET Technology, I have developed various enterprise level applications on both platforms. Currently, I am working as a Senior Software Developer at Readify which is a leading company on .NET technology in Australia.

Comments and Discussions