Permalink
Browse files

Adding curator for packages compatible with Windows 8 Metro-style app…

…lications.
  • Loading branch information...
1 parent 513f257 commit aa30aa5db6ecb217ebd4d7ed2ac2560c2b7d65f0 @anurse anurse committed Jun 18, 2012
View
2 Website/App_Start/ContainerBindings.cs
@@ -173,6 +173,8 @@ public override void Load()
// todo: bind all package curators by convention
Bind<IAutomaticPackageCurator>()
.To<WebMatrixPackageCurator>();
+ Bind<IAutomaticPackageCurator>()
+ .To<Windows8PackageCurator>();
// todo: bind all commands by convention
Bind<IAutomaticallyCuratePackageCommand>()
View
43 Website/PackageCurators/TagBasedPackageCurator.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using NuGet;
+
+namespace NuGetGallery
+{
+ public abstract class TagBasedPackageCurator : AutomaticPackageCurator
+ {
+ /// <summary>
+ /// Gets a list of tags required for a package to be selected by this curator. A package MUST have ONE of the specified tags to be curated.
+ /// </summary>
+ protected abstract IEnumerable<string> RequiredTags { get; }
+
+ /// <summary>
+ /// Gets the name of the curated feed to add the package to.
+ /// </summary>
+ protected abstract string CuratedFeedName { get; }
+
+ public override void Curate(Package galleryPackage, IPackage nugetPackage)
+ {
+ // Check if this package should be curated
+ if (galleryPackage.Tags != null && RequiredTags.Any(s => galleryPackage.Tags.ToLowerInvariant().Contains(s)))
+ {
+ // It should! Add it to the curated feed
+ AddPackageToFeed(galleryPackage);
+ }
+ }
+
+ protected virtual void AddPackageToFeed(Package galleryPackage)
+ {
+ CuratedFeed feed = GetTargetFeed();
+ GetService<ICreateCuratedPackageCommand>().Execute(
+ feed.Key, galleryPackage.PackageRegistration.Key, automaticallyCurated: true);
+ }
+
+ protected virtual CuratedFeed GetTargetFeed()
+ {
+ return GetService<ICuratedFeedByNameQuery>().Execute(CuratedFeedName, includePackages: false);
+ }
+ }
+}
View
25 Website/PackageCurators/Windows8PackageCurator.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace NuGetGallery
+{
+public class Windows8PackageCurator : TagBasedPackageCurator
+{
+ protected override IEnumerable<string> RequiredTags
+ {
+ get {
+ yield return "winrt";
+ yield return "win8";
+ yield return "windows8";
+ yield return "winjs";
+ }
+ }
+
+ protected override string CuratedFeedName
+ {
+ get { return "Win8"; }
+ }
+}
+}
View
4 Website/Website.csproj
@@ -357,7 +357,9 @@
<Compile Include="Migrations\MigrationsConfiguration.cs" />
<Compile Include="PackageCurators\IAutomaticPackageCurator.cs" />
<Compile Include="PackageCurators\AutomaticPackageCurator.cs" />
+ <Compile Include="PackageCurators\TagBasedPackageCurator.cs" />
<Compile Include="PackageCurators\WebMatrixPackageCurator.cs" />
+ <Compile Include="PackageCurators\Windows8PackageCurator.cs" />
<Compile Include="PackagesController.generated.cs">
<DependentUpon>T4MVC.tt</DependentUpon>
</Compile>
@@ -927,4 +929,4 @@
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />
-</Project>
+</Project>

0 comments on commit aa30aa5

Please sign in to comment.