Esempio n. 1
0
        async Task <bool> TryDownloadFile(Spec spec)
        {
            var done = false;

            spec.FullPath.MakeSureParentPathExists();
            try {
                if (spec.CurrentHost != null)
                {
                    await
                    _downloader.DownloadAsync(spec.GetUri(), spec.FullPath, spec.Status)
                    .ConfigureAwait(false);

                    done = true;
                    TryCleanTempFiles(spec.FullPath);
                }
            } catch (RsyncSoftException e) {
                spec.LastException = e;
                this.Logger().Warn("Failed transfer of {0} from {1}: {2}", spec.File, spec.CurrentHost, e.Message);
                this.Logger().Warn(e.Output);
            } catch (ZsyncSoftException e) {
                spec.LastException = e;
                this.Logger().Warn("Failed transfer of {0} from {1}: {2}", spec.File, spec.CurrentHost, e.Message);
                this.Logger().Warn(e.Output);
                if (e is ZsyncIncompatibleException)
                {
                    HostPicker.ZsyncIncompatHost(spec.CurrentHost);
                }
            } catch (DownloadSoftException e) {
                spec.LastException = e;
                this.Logger().Warn("Failed transfer of {0} from {1}: {2}", spec.File, spec.CurrentHost, e.Message);
                this.Logger().Warn(e.Output);
            } catch (DownloadException e) {
                spec.LastException = e;
                this.Logger().FormattedWarnException(e);
                this.Logger().Warn("Failed transfer of {0} from {1}: {2}", spec.File, spec.CurrentHost, e.Message);
                this.Logger().Warn(e.Output);
                if (AddExceptionType(e.GetType()))
                {
                    await Tools.InformUserError("Error occurred during download", null, e).ConfigureAwait(false);
                }
            } catch (TimeoutException e) {
                spec.LastException = e;
                this.Logger().FormattedWarnException(e);
                this.Logger()
                .Warn("Failed transfer of {0} from {1}: {2} (Timeout)", spec.File, spec.CurrentHost, e.Message);
            } catch (SocketException e) {
                spec.LastException = e;
                this.Logger().FormattedWarnException(e);
                this.Logger()
                .Warn("Failed transfer of {0} from {1}: {2} (ErrorCode: {3}, Native: {4}, Socket: {5})", spec.File,
                      spec.CurrentHost, e.Message, -1, /*e.ErrorCode, e.NativeErrorCode,*/ -1, e.SocketErrorCode);
            } catch (WebException e) {
                spec.LastException = e;
                this.Logger()
                .Warn("Failed transfer of {0} from {1}: {2} (Status: {3}, Type: {4}, Length: {5})", spec.File,
                      spec.CurrentHost, e.Message, e.Status, e.Response?.ContentType,
                      e.Response?.ContentLength ?? 0);
                this.Logger().FormattedWarnException(e);
            } catch (Exception e) {
                spec.LastException = e;
                this.Logger().FormattedWarnException(e);
                if (AddExceptionType(e.GetType()))
                {
                    await Tools.InformUserError("Error occurred during download", null, e).ConfigureAwait(false);
                }
            }
            return(done);
        }