コード例 #1
0
ファイル: Warehouse.cs プロジェクト: girish/NuGet.Jobs
        private static async Task <IReadOnlyCollection <PackageDimension> > RetrievePackageDimensions(IReadOnlyCollection <PackageStatistics> sourceData, SqlConnection connection)
        {
            var packages = sourceData
                           .Select(e => new PackageDimension(e.PackageId, e.PackageVersion))
                           .Distinct()
                           .ToList();

            var results = new List <PackageDimension>();

            if (!packages.Any())
            {
                return(results);
            }

            results.AddRange(_cachedPackageDimensions
                             .Where(p1 => packages
                                    .FirstOrDefault(p2 =>
                                                    string.Equals(p1.PackageId, p2.PackageId, StringComparison.OrdinalIgnoreCase) &&
                                                    string.Equals(p1.PackageVersion, p2.PackageVersion, StringComparison.OrdinalIgnoreCase)) != null
                                    )
                             );

            var nonCachedPackageDimensions = packages.Except(results).ToList();
            var parameterValue             = CreateDataTable(nonCachedPackageDimensions);

            var command = connection.CreateCommand();

            command.CommandText    = "[dbo].[EnsurePackageDimensionsExist]";
            command.CommandTimeout = _defaultCommandTimeout;
            command.CommandType    = CommandType.StoredProcedure;

            var parameter = command.Parameters.AddWithValue("packages", parameterValue);

            parameter.SqlDbType = SqlDbType.Structured;
            parameter.TypeName  = "[dbo].[PackageDimensionTableType]";

            using (var dataReader = await command.ExecuteReaderAsync())
            {
                while (await dataReader.ReadAsync())
                {
                    var package = new PackageDimension(dataReader.GetString(1), dataReader.GetString(2));
                    package.Id = dataReader.GetInt32(0);

                    if (!results.Contains(package))
                    {
                        results.Add(package);
                    }
                    if (!_cachedPackageDimensions.Contains(package))
                    {
                        _cachedPackageDimensions.Add(package);
                    }
                }
            }

            return(results);
        }
コード例 #2
0
 protected bool Equals(PackageDimension other)
 {
     return(string.Equals(PackageId.ToLower(EnUsCulture), other.PackageId.ToLower(EnUsCulture)) && string.Equals(PackageVersion, other.PackageVersion, StringComparison.OrdinalIgnoreCase));
 }
コード例 #3
0
ファイル: PackageDimension.cs プロジェクト: joyhui/NuGet.Jobs
 protected bool Equals(PackageDimension other)
 {
     return string.Equals(PackageId, other.PackageId, StringComparison.OrdinalIgnoreCase) && string.Equals(PackageVersion, other.PackageVersion, StringComparison.OrdinalIgnoreCase);
 }