Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 public Download(
     DownloadPackage package,
     DownloadConfiguration configuration)
 {
     downloadService = new DownloadService(configuration);
     Package         = package;
     Status          = DownloadStatus.Stopped;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 9
0
 public async Task DownloadFileAsync(DownloadPackage package)
 {
     Package = package;
     InitialBegin(package.Address.OriginalString);
     await StartDownload();
 }
Ejemplo n.º 10
0
        public static void UpdatePackage(string packageID, Action <DownloadPackage> actionpackage)
        {
            DownloadPackage _package = _downloadPackages.FirstOrDefault(a => a.DId == packageID);

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