public Task <bool> NominateProjectAsync(string projectUniqueName, IVsProjectRestoreInfo projectRestoreInfo, CancellationToken token) { if (string.IsNullOrEmpty(projectUniqueName)) { throw new ArgumentException(Resources.Argument_Cannot_Be_Null_Or_Empty, nameof(projectUniqueName)); } if (projectRestoreInfo == null) { throw new ArgumentNullException(nameof(projectRestoreInfo)); } if (projectRestoreInfo.TargetFrameworks == null) { throw new InvalidOperationException("TargetFrameworks cannot be null."); } try { _logger.LogInformation( $"The nominate API is called for '{projectUniqueName}'."); var projectNames = ProjectNames.FromFullProjectPath(projectUniqueName); var dgSpec = ToDependencyGraphSpec(projectNames, projectRestoreInfo); #if DEBUG DumpProjectRestoreInfo(projectUniqueName, dgSpec); #endif _projectSystemCache.AddProjectRestoreInfo(projectNames, dgSpec); // returned task completes when scheduled restore operation completes. var restoreTask = _restoreWorker.ScheduleRestoreAsync( SolutionRestoreRequest.OnUpdate(), token); return(restoreTask); } catch (Exception e) when(e is InvalidOperationException || e is ArgumentException || e is FormatException) { _logger.LogError(e.ToString()); return(Task.FromResult(false)); } catch (Exception e) { _logger.LogError(e.ToString()); throw; } }
public override Task <DownloadResourceResult> GetDownloadResourceResultAsync( PackageIdentity identity, Configuration.ISettings settings, NuGet.Common.ILogger logger, CancellationToken token) { // settings are not used here, since, global packages folder are not used for v2 sources if (identity == null) { throw new ArgumentNullException(nameof(identity)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } string displayUri = V2Client.Source; return(Task.Run(() => { token.ThrowIfCancellationRequested(); for (int i = 0; i < 3; i++) { try { var sourcePackage = identity as SourcePackageDependencyInfo; var repository = V2Client as DataServicePackageRepository; bool isFromUri = repository != null && sourcePackage?.PackageHash != null && sourcePackage?.DownloadUri != null; if (isFromUri) { // If this is a SourcePackageDependencyInfo object with everything populated // and it is from an online source, use the machine cache and download it using the // given url. return DownloadFromUrl(sourcePackage, repository, logger, token); } else { // Look up the package from the id and version and download it. return DownloadFromIdentity(identity, V2Client, logger, token); } } catch (OperationCanceledException) { return new DownloadResourceResult(DownloadResourceResultStatus.Cancelled); } catch (IOException ex) when(ex.InnerException is SocketException && i < 2) { string message = string.Format(CultureInfo.CurrentCulture, Strings.Log_ErrorDownloading, identity, displayUri) + Environment.NewLine + ExceptionUtilities.DisplayMessage(ex); logger.LogWarning(message); } catch (Exception ex) { string message = string.Format(CultureInfo.CurrentCulture, Strings.Log_ErrorDownloading, identity, displayUri); logger.LogError(message + Environment.NewLine + ExceptionUtilities.DisplayMessage(ex)); throw new FatalProtocolException(message, ex); } } // This line cannot be reached, but the compiler doesn't understand it throw new InvalidOperationException("Can never reach here."); })); }