Esempio n. 1
0
        /// <summary>
        /// <see cref="IDownloader.DownloadModules(NetFileCache, IEnumerable{CfanModule})"/>
        /// </summary>
        public void DownloadModules(
            NetFileCache cache,
            IEnumerable <CfanModule> modules
            )
        {
            // Walk through all our modules, but only keep the first of each
            // one that has a unique download path.
            Dictionary <Uri, CfanModule> unique_downloads = modules.Where(module => module.download != null)
                                                            .GroupBy(module => module.download)
                                                            .ToDictionary(p => prepareDownloadUri(p.First()), p => p.First());

            this.modules.AddRange(unique_downloads.Values);

            // Schedule us to process our modules on completion.
            downloader.onCompleted =
                (_uris, paths, errors) =>
                ModuleDownloadsComplete(cache, _uris, paths, errors);

            // retrieve the expected download size for each mod
            List <KeyValuePair <Uri, long> > downloads_with_size = unique_downloads
                                                                   .Select(item => new KeyValuePair <Uri, long>(item.Key, item.Value.download_size))
                                                                   .ToList();

            // Start the download!
            downloader.DownloadAndWait(downloads_with_size);
        }
        /// <summary>
        /// <see cref="IDownloader.DownloadModules(NetFileCache, IEnumerable{CkanModule})"/>
        /// </summary>
        public void DownloadModules(IEnumerable <CkanModule> modules)
        {
            // Walk through all our modules, but only keep the first of each
            // one that has a unique download path (including active downloads).
            var currentlyActive = new HashSet <Uri>(this.modules.Select(m => m.download));
            Dictionary <Uri, CkanModule> unique_downloads = modules
                                                            .GroupBy(module => module.download)
                                                            .Where(group => !currentlyActive.Contains(group.Key))
                                                            .ToDictionary(group => group.Key, group => group.First());

            this.modules.AddRange(unique_downloads.Values);

            try
            {
                // Start the downloads!
                downloader.DownloadAndWait(
                    unique_downloads.Select(item => new Net.DownloadTarget(
                                                item.Key,
                                                item.Value.InternetArchiveDownload,
                                                // Use a temp file name
                                                null,
                                                item.Value.download_size,
                                                // Send the MIME type to use for the Accept header
                                                // The GitHub API requires this to include application/octet-stream
                                                string.IsNullOrEmpty(item.Value.download_content_type)
                            ? defaultMimeType
                            : $"{item.Value.download_content_type};q=1.0,{defaultMimeType};q=0.9"
                                                )).ToList()
                    );
                if (AllComplete != null)
                {
                    AllComplete();
                }
            }
            catch (DownloadErrorsKraken kraken)
            {
                // Associate the errors with the affected modules
                throw new ModuleDownloadErrorsKraken(this.modules, kraken);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// <see cref="IDownloader.DownloadModules(NetFileCache, IEnumerable{CkanModule})"/>
        /// </summary>
        public void DownloadModules(NetModuleCache cache, IEnumerable <CkanModule> modules)
        {
            // Walk through all our modules, but only keep the first of each
            // one that has a unique download path.
            Dictionary <Uri, CkanModule> unique_downloads = modules
                                                            .GroupBy(module => module.download)
                                                            .ToDictionary(p => p.First().download, p => p.First());

            this.modules.AddRange(unique_downloads.Values);

            // Schedule us to process our modules on completion.
            downloader.onCompleted =
                (_uris, paths, errors) =>
                ModuleDownloadsComplete(cache, _uris, paths, errors);

            try
            {
                // Start the downloads!
                downloader.DownloadAndWait(
                    unique_downloads.Select(item => new Net.DownloadTarget(
                                                item.Key,
                                                item.Value.InternetArchiveDownload,
                                                // Use a temp file name
                                                null,
                                                item.Value.download_size,
                                                // Send the MIME type to use for the Accept header
                                                // The GitHub API requires this to include application/octet-stream
                                                string.IsNullOrEmpty(item.Value.download_content_type)
                            ? defaultMimeType
                            : $"{item.Value.download_content_type};q=1.0,{defaultMimeType};q=0.9"
                                                )).ToList()
                    );
            }
            catch (DownloadErrorsKraken kraken)
            {
                // Associate the errors with the affected modules
                throw new ModuleDownloadErrorsKraken(this.modules, kraken);
            }
        }