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); }
protected bool Equals(PackageDimension other) { return(string.Equals(PackageId.ToLower(EnUsCulture), other.PackageId.ToLower(EnUsCulture)) && string.Equals(PackageVersion, other.PackageVersion, StringComparison.OrdinalIgnoreCase)); }
protected bool Equals(PackageDimension other) { return string.Equals(PackageId, other.PackageId, StringComparison.OrdinalIgnoreCase) && string.Equals(PackageVersion, other.PackageVersion, StringComparison.OrdinalIgnoreCase); }