Пример #1
0
        private static async void _run(DownloadPackage package)
        {
            DownloadService ds = new DownloadService(package.Options);

            ds.DownloadProgressChanged += OnDownloadProgressChanged;
            ds.DownloadFileCompleted   += OnDownloadFileCompleted;
            await ds.DownloadFileAsync(package.Address.AbsoluteUri, package.FileName);
        }
Пример #2
0
 public Download(
     DownloadPackage package,
     DownloadConfiguration configuration)
 {
     downloadService = new DownloadService(configuration);
     Package         = package;
     Status          = DownloadStatus.Stopped;
 }
Пример #3
0
        public DownloadService(DownloadConfiguration options = null)
        {
            Package = new DownloadPackage {
                Options = options ?? new DownloadConfiguration()
            };

            ServicePointManager.SecurityProtocol =
                SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            ServicePointManager.Expect100Continue       = false; // accept the request for POST, PUT and PATCH verbs
            ServicePointManager.DefaultConnectionLimit  = 1000;
            ServicePointManager.MaxServicePointIdleTime = 1000;
        }
Пример #4
0
        public DownloadService(DownloadConfiguration options = null)
        {
            Package = new DownloadPackage()
            {
                Options = options ?? new DownloadConfiguration()
            };

            ServicePointManager.Expect100Continue       = false; // accept the request for POST, PUT and PATCH verbs
            ServicePointManager.DefaultConnectionLimit  = 100;
            ServicePointManager.MaxServicePointIdleTime = 1000;

            Cts = new CancellationTokenSource();
        }
Пример #5
0
        public async Task DownloadFileAsync(DownloadPackage package)
        {
            IsBusy  = true;
            Cts     = new CancellationTokenSource();
            Package = package;
            Package.Options.Validate();

            CheckSizes();

            if (File.Exists(Package.FileName))
            {
                File.Delete(Package.FileName);
            }

            await StartDownload();
        }
Пример #6
0
        public async Task DownloadFileAsync(DownloadPackage package)
        {
            IsBusy  = true;
            Package = package;

            if (Package.TotalFileSize <= 0)
            {
                throw new InvalidDataException("File size is invalid!");
            }

            if (File.Exists(Package.FileName))
            {
                File.Delete(Package.FileName);
            }

            await StartDownload();
        }
Пример #7
0
        public static string AddTask(string url, string name, string savePath = null, int threadCount = 4, int blockSize = 3)
        {
            MaxThread = threadCount;
            DownloadConfiguration configuration = new DownloadConfiguration();

            configuration.SaveDirectory = savePath ?? configuration.SaveDirectory;
            configuration.ChunkCount    = blockSize;
            configuration.TempDirectory = "C:\\temp";
            DownloadPackage package = new DownloadPackage
            {
                Options       = configuration,
                Address       = new Uri(url),
                FileName      = name,
                SaveDirectory = configuration.SaveDirectory
            };

            _downloadPackages.Add(package);
            return(package.DId);
        }
Пример #8
0
        // ReSharper disable once MemberCanBePrivate.Global
        public DownloadService()
        {
            _bandwidth = new Bandwidth();
            Options    = new DownloadConfiguration();
            Package    = new DownloadPackage();

            // This property selects the version of the Secure Sockets Layer (SSL) or
            // existing connections aren't changed.
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            // Accept the request for POST, PUT and PATCH verbs
            ServicePointManager.Expect100Continue = false;

            // Note: Any changes to the DefaultConnectionLimit property affect both HTTP 1.0 and HTTP 1.1 connections.
            // It is not possible to separately alter the connection limit for HTTP 1.0 and HTTP 1.1 protocols.
            ServicePointManager.DefaultConnectionLimit = 1000;

            // Set the maximum idle time of a ServicePoint instance to 10 seconds.
            // After the idle time expires, the ServicePoint object is eligible for
            // garbage collection and cannot be used by the ServicePointManager object.
            ServicePointManager.MaxServicePointIdleTime = 10000;
        }
Пример #9
0
 public async Task DownloadFileAsync(DownloadPackage package)
 {
     Package = package;
     InitialBegin(package.Address.OriginalString);
     await StartDownload();
 }
Пример #10
0
        public static void UpdatePackage(string packageID, Action <DownloadPackage> actionpackage)
        {
            DownloadPackage _package = _downloadPackages.FirstOrDefault(a => a.DId == packageID);

            actionpackage(_package);
        }
Пример #11
0
 public async Task DownloadFileAsync(DownloadPackage package)
 {
     Package = package;
     InitialDownloader(package.Address.OriginalString);
     await StartDownload().ConfigureAwait(false);
 }
Пример #12
0
 public static IDownload Build(DownloadPackage package, DownloadConfiguration downloadConfiguration)
 {
     return(new Download(package, downloadConfiguration));
 }
Пример #13
0
 public static IDownload Build(DownloadPackage package)
 {
     return(Build(package, new DownloadConfiguration()));
 }
Пример #14
0
 public async Task <Stream> DownloadFileTaskAsync(DownloadPackage package)
 {
     Package = package;
     InitialDownloader(package.Address);
     return(await StartDownload().ConfigureAwait(false));
 }