Exemplo n.º 1
0
        public override bool Execute()
        {
            LogMessage("Starting XamarinDownloadPartialZips");
            LogMessage("DestinationBase: {0}", DestinationBase);
            LogMessage("CacheDirectory: {0}", CacheDirectory);

            Task.Run(async() => {
                List <PartialZipDownload> parts = null;
                try {
                    http = new HttpClient();

                    var cacheDir      = DownloadUtils.GetCacheDir(CacheDirectory);
                    var downloadUtils = new DownloadUtils(this, cacheDir);

                    parts = downloadUtils.ParsePartialZipDownloadItems(Parts, AllowUnsecureUrls);

                    await DownloadAll(cacheDir, parts).ConfigureAwait(false);
                } catch (Exception ex) {
                    LogErrorFromException(ex);

                    // Log Custom error if one was specified in the partial download info
                    var firstPart = parts?.FirstOrDefault();
                    if (!string.IsNullOrEmpty(firstPart?.CustomErrorCode) && !string.IsNullOrEmpty(firstPart?.CustomErrorMessage))
                    {
                        LogCodedError(firstPart.CustomErrorCode, firstPart.CustomErrorMessage);
                    }
                } finally {
                    Complete();
                }
            });

            var result = base.Execute();

            return(result && !Log.HasLoggedErrors);
        }
Exemplo n.º 2
0
        public override bool Execute()
        {
            var results = new List <ITaskItem> ();

            downloadUtils = new DownloadUtils(this, CacheDirectory);

            var items = downloadUtils.ParseDownloadItems(Archives);

            if (items != null)
            {
                foreach (var item in items)
                {
                    if (downloadUtils.IsAlreadyDownloaded(item))
                    {
                        continue;
                    }
                    var taskItem = new TaskItem(item.Id);
                    taskItem.SetMetadata("Type", "Download");
                    taskItem.SetMetadata("Url", item.Url);
                    taskItem.SetMetadata("CacheFile", item.CacheFile);

                    if (!string.IsNullOrEmpty(item.Sha1))
                    {
                        taskItem.SetMetadata("Sha1", item.Sha1);
                    }

                    results.Add(taskItem);
                }
            }

            var partials = downloadUtils.ParsePartialZipDownloadItems(PartialZipDownloads);

            if (partials != null)
            {
                foreach (var partialZipDownload in partials)
                {
                    if (downloadUtils.IsAlreadyDownloaded(CacheDirectory, partialZipDownload))
                    {
                        continue;
                    }
                    var taskItem = new TaskItem(partialZipDownload.Id);
                    taskItem.SetMetadata("Type", "PartialZipDownload");
                    taskItem.SetMetadata("Url", partialZipDownload.Url);
                    taskItem.SetMetadata("RangeStart", partialZipDownload.RangeStart.ToString());
                    taskItem.SetMetadata("RangeEnd", partialZipDownload.RangeEnd.ToString());

                    if (!string.IsNullOrEmpty(partialZipDownload.Md5))
                    {
                        taskItem.SetMetadata("Md5", partialZipDownload.Md5);
                    }

                    results.Add(taskItem);
                }
            }

            ArchivesToDownload = results.ToArray();

            return(true);
        }