public static IResult Verify(FdbServerUrl url, string fileName) { return(Try.Wrap(() => { var checksum = url.Sha512Hash; using (var hashAlgorithm = SHA512.Create()) { using (var destination = File.OpenRead(fileName)) { var hash = hashAlgorithm.ComputeHash(destination); var hashString = ToHex(hash); if (hashString.Equals(checksum, StringComparison.OrdinalIgnoreCase)) { return new SuccessResult(); } else { return new FailureResult("File checksum did not match stored checksum."); } } } })); }
public static IResult CheckAvailability(FdbServerUrl url) { var fileName = GetCacheFileName(url); if (!File.Exists(fileName)) { return(new FailureResult("Cache does not contain version " + url.Version)); } return(IntegrityVerifier.Verify(url, fileName)); }
public static Task <IResult> Download(FdbServerUrl url, string destinationFile) => Try.Wrap(async() => { using (var webclient = new HttpClient()) { var serverDownloadTask = webclient.GetStreamAsync(url.Uri); using (var destination = File.OpenWrite(destinationFile)) { var stream = await serverDownloadTask.ConfigureAwait(false); await stream.CopyToAsync(destination).ConfigureAwait(false); await destination.FlushAsync().ConfigureAwait(false); } } });
private static string GetCacheFileName(FdbServerUrl url) { string fileName = Path.Combine(GetCacheFolder(), Path.GetFileName(url.Uri.LocalPath)); return(fileName); }
internal static IResult Retrieve(FdbServerUrl url, string outputFile) { return(CheckAvailability(url) .Then(_ => Try.Wrap(() => File.Copy(GetCacheFileName(url), outputFile, true)))); }
public static Task <IResult> Load(FdbServerUrl url) => FdbServerDownloader.Download(url, GetCacheFileName(url));