Пример #1
0
        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.");
                        }
                    }
                }
            }));
        }
Пример #2
0
        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));
        }
Пример #3
0
        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);
                }
            }
        });
Пример #4
0
        private static string GetCacheFileName(FdbServerUrl url)
        {
            string fileName = Path.Combine(GetCacheFolder(), Path.GetFileName(url.Uri.LocalPath));

            return(fileName);
        }
Пример #5
0
 internal static IResult Retrieve(FdbServerUrl url, string outputFile)
 {
     return(CheckAvailability(url)
            .Then(_ => Try.Wrap(() => File.Copy(GetCacheFileName(url), outputFile, true))));
 }
Пример #6
0
 public static Task <IResult> Load(FdbServerUrl url)
 => FdbServerDownloader.Download(url, GetCacheFileName(url));