Example #1
0
        public void DownloadAndInstallPackage(
			ReportInstallProgress reportProgress,
			DownloadComplete downloadComplete,
			DownloadError downloadError,
			VerificationError verificationError,
			IsCancelled isCancelled
		)
        {
            string downloadPath = PrepareDownloadFilePath (FileUtil.GetUniqueTempPathInProject (), config.Filename);

            new Detail.AsyncTaskRunnerBuilder<byte[]> ().Do ((object[] args) => {
                return Net.Validator.MakeRequest (() => {
                    return API.V1.DownloadFile (config.PackageUrl, (progress) => reportProgress(progress), () => { return isCancelled (); });
                });
            }).OnError ((System.Exception e) => {
                downloadError(e);
                return Detail.AsyncTaskRunner<byte[]>.ErrorRecovery.Nothing;
            }).OnCompletion ((byte[] downloadedBytes) => {
                if (downloadedBytes.Length == 0) {
                    return;
                }
                try {
                    System.IO.File.WriteAllBytes (downloadPath, downloadedBytes);
                    string signatureUrl = SignatureUrlFromPackageUrl (config.PackageUrl);

                    VerifySignature (signatureUrl, downloadedBytes, verificationError, downloadError, isCancelled, () => {
                        downloadComplete (downloadPath);
                        InstallPackage (downloadPath);
                    });
                } catch (IOException e) {
                    downloadError (e as Exception);
                }
            }).Run ();
        }
        public void DownloadAndInstallPackage(
            ReportInstallProgress reportProgress,
            DownloadComplete downloadComplete,
            DownloadError downloadError,
            VerificationError verificationError,
            IsCancelled isCancelled
            )
        {
            string downloadPath = PrepareDownloadFilePath(FileUtil.GetUniqueTempPathInProject(), config.Filename);

            new Detail.AsyncTaskRunnerBuilder <byte[]> ().Do((object[] args) => {
                return(Net.Validator.MakeRequest(() => {
                    return API.V1.DownloadFile(config.PackageUrl, (progress) => reportProgress(progress), () => { return isCancelled(); });
                }));
            }).OnError((System.Exception e) => {
                downloadError(e);
                return(Detail.AsyncTaskRunner <byte[]> .ErrorRecovery.Nothing);
            }).OnCompletion((byte[] downloadedBytes) => {
                if (downloadedBytes.Length == 0)
                {
                    return;
                }
                try {
                    System.IO.File.WriteAllBytes(downloadPath, downloadedBytes);
                    string signatureUrl = SignatureUrlFromPackageUrl(config.PackageUrl);

                    VerifySignature(signatureUrl, downloadedBytes, verificationError, downloadError, isCancelled, () => {
                        downloadComplete(downloadPath);
                        InstallPackage(downloadPath);
                    });
                } catch (IOException e) {
                    downloadError(e as Exception);
                }
            }).Run();
        }