private void ProcessPackageSource()

in nuget-extensions/nuget-commands/src/NuGetTeamCityListPackagesCommand.cs [71:109]


    private void ProcessPackageSource(INuGetSource source, List<INuGetPackage> request)
    {
      //todo: optimize query to return only required set of versions.
      foreach (var req in new[]
                              {
                                new { Data = request.Where(x => x.VersionSpec == null && x.IncludePrerelease).ToArray(), FetchOption = PackageFetchOption.IncludeLatestAndPrerelease }, 
                                new { Data = request.Where(x => x.VersionSpec == null && !x.IncludePrerelease).ToArray(), FetchOption = PackageFetchOption.IncludeLatest }, 
                                new { Data = request.Where(x => x.VersionSpec != null).ToArray(), FetchOption = PackageFetchOption.IncludeAll }
                              })
      {
        try
        {
          ProcessPackages(source, req.FetchOption, req.Data);
        }
        catch (Exception e)
        {
          string message;
          var aggregateException = e as AggregateException;
          if (aggregateException != null)
          {
            var ae = aggregateException;
            ae.Flatten();
            var stringBuilder = new StringBuilder();
            foreach (var exception in ae.InnerExceptions)
              stringBuilder.AppendLine(exception.Message);

            message = stringBuilder.ToString();
          }
          else
            message = e.Message;

          foreach (var pkg in req.Data)
            pkg.AddError(message);

          System.Console.Error.WriteLine("Failed to check package sources information for {0}: {1}", source, message);
          System.Console.Out.WriteLine(e);
        }
      }
    }