Example #1
0
 bool TryDownload(MultiMirrorFileDownloadSpec spec, Uri host)
 {
     try {
         TryDownloadFile(spec, host);
         spec.End();
         return(true);
     } catch (TransferException) {} catch (VerificationError) {}
     return(false);
 }
Example #2
0
        async Task <bool> TryDownloadAsync(MultiMirrorFileDownloadSpec spec, Uri host)
        {
            try {
                await TryDownloadFileAsync(spec, host).ConfigureAwait(false);

                spec.End();
                return(true);
            } catch (TransferException) {} catch (VerificationError) {}
            return(false);
        }
Example #3
0
 static FileDownloadSpec BuildSpec(MultiMirrorFileDownloadSpec spec, Uri host) => spec.Progress == null
     ? new FileDownloadSpec(spec.GetUri(host), spec.LocalFile)
 {
     Verification      = spec.Verification,
     CancellationToken = spec.CancellationToken,
     ExistingFile      = spec.ExistingFile
 }
     : new FileDownloadSpec(spec.GetUri(host), spec.LocalFile, spec.Progress)
 {
     Verification      = spec.Verification,
     CancellationToken = spec.CancellationToken,
     ExistingFile      = spec.ExistingFile
 };
Example #4
0
        protected static MultiMirrorFileDownloadSpec GetDlSpec(FileQueueSpec spec,
                                                               KeyValuePair <FileFetchInfo, ITransferStatus> file)
        {
            var dlSpec = new MultiMirrorFileDownloadSpec(file.Key.FilePath,
                                                         spec.Location.GetChildFileWithName(file.Key.FilePath))
            {
                Progress     = file.Value,
                Verification = file.Key.OnVerify,
                ExistingFile =
                    file.Key.ExistingPath != null?spec.Location.GetChildFileWithName(file.Key.ExistingPath) : null
            };

            dlSpec.LocalFile.MakeSureParentPathExists();
            return(dlSpec);
        }
Example #5
0
 protected void TryDownloadFile(MultiMirrorFileDownloadSpec spec, Uri host)
 {
     try {
         _downloader.Download(BuildSpec(spec, host));
     } catch (Exception ex) {
         if (!(ex is IProgramError))
         {
             _mirrorStrategy.Failure(host);
         }
         else
         {
             _mirrorStrategy.ProgramFailure();
         }
         throw;
     }
     _mirrorStrategy.Success(host);
 }
Example #6
0
 protected async Task TryDownloadFileAsync(MultiMirrorFileDownloadSpec spec, Uri host)
 {
     try {
         await _downloader.DownloadAsync(BuildSpec(spec, host))
         .ConfigureAwait(false);
     } catch (Exception ex) {
         if (!(ex is IProgramError))
         {
             _mirrorStrategy.Failure(host);
         }
         else
         {
             _mirrorStrategy.ProgramFailure();
         }
         throw;
     }
     _mirrorStrategy.Success(host);
 }
Example #7
0
 public void Download(MultiMirrorFileDownloadSpec spec)
 {
     spec.Start();
     try {
         while (true)
         {
             var host = _mirrorStrategy.GetHost();
             if (TryDownload(spec, host))
             {
                 break;
             }
             ResetSpec(spec);
             Thread.Sleep(MillisecondsTimeout);
         }
     } catch (Exception) {
         spec.Fail();
         throw;
     }
 }
Example #8
0
 public void Download(MultiMirrorFileDownloadSpec spec, CancellationToken token)
 {
     spec.Start();
     try {
         while (true)
         {
             token.ThrowIfCancellationRequested();
             var host = _mirrorStrategy.GetHost();
             if (TryDownload(spec, host))
             {
                 break;
             }
             spec.Progress?.Reset();
             Thread.Sleep(MillisecondsTimeout);
         }
     } catch (Exception) {
         spec.Fail();
         throw;
     }
 }
Example #9
0
 public async Task DownloadAsync(MultiMirrorFileDownloadSpec spec)
 {
     spec.Start();
     try {
         while (true)
         {
             var host = _mirrorStrategy.GetHost();
             spec.UpdateHost(host);
             if (await TryDownloadAsync(spec, host).ConfigureAwait(false))
             {
                 break;
             }
             ResetSpec(spec);
             await Task.Delay(MillisecondsTimeout).ConfigureAwait(false);
         }
     } catch (Exception) {
         spec.Fail();
         throw;
     }
 }
Example #10
0
 private static void ResetSpec(MultiMirrorFileDownloadSpec spec)
 => spec.Progress?.Update(null, spec.Progress.Progress);