/// <summary> /// This method downloads the package represented by the PackageDownloadHandle, /// /// </summary> /// <param name="packageDownloadHandle">package download handle</param> internal virtual Task <(PackageDownloadHandle handle, string downloadPath)> Download(PackageDownloadHandle packageDownloadHandle) { // We only want to display the last 3 downloaded packages to the user // in the form of toast notifications. // We remove all but the last 2 packages and add the most recently-downloaded package if (Downloads.Count > 2) { Downloads.RemoveRange(index: 0, count: Downloads.Count - 2); } Downloads.Add(packageDownloadHandle); packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Downloading; return(Task.Factory.StartNew(() => { // Attempt to download package string pathDl; var res = Model.DownloadPackage(packageDownloadHandle.Id, packageDownloadHandle.VersionName, out pathDl); // if you fail, update download handle and return if (!res.Success) { packageDownloadHandle.Error(res.Error); pathDl = string.Empty; } return (handle: packageDownloadHandle, downloadPath: pathDl); })); }