?
Something like this should work:
sealed class FilteredPackageStore : DirectoryPackageStore
{
private const int PackagesCount = 5;
public override Stream Create(string packageId, SemanticVersion packageVersion, bool allowOverwrite)
{
var packagesToDelete = StoredProcs.Packages_GetPackages(this.FeedId, "Y")
.Execute()
.Where(p => p.Package_Id.Equals(packageId, StringComparison.OrdinalIgnoreCase))
.OrderByDescending(p => p.Published_Date)
.Skip(PackagesCount);
foreach (var package in packagesToDelete)
this.Delete(package.Package_Id, new SemanticVersion(package.Version_Text));
return base.Create(packageId, packageVersion, allowOverwrite);
}
}