Last active
November 27, 2016 10:54
-
-
Save warrenbuckley/1380daf1c4f8c6c99d6d to your computer and use it in GitHub Desktop.
V3 Nuget API using Nuget.Core Package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Web.Http; | |
using NuGet.Configuration; | |
using NuGet.Protocol.Core.Types; | |
using NuGet.Protocol.Core.v3; | |
using NuGet.Versioning; | |
namespace Umbraco.Forms.UpdateChecker.Controller | |
{ | |
//TODO: Look at WebAPI Cache Output Attributes | |
//Not built into WebAPI | |
//From a MS MVP - Filip W (http://www.strathweb.com) | |
//https://github.com/filipw/AspNetWebApi-OutputCache | |
[RoutePrefix("api/UpdateChecker")] | |
public class UpdateCheckerController : ApiController | |
{ | |
[HttpGet] | |
[Route("Ping")] | |
public string Ping() | |
{ | |
return "Pong"; | |
} | |
[HttpGet] | |
[Route("HasUpdate")] | |
public async Task<string> HasUpdate(string versionNumber) | |
{ | |
//Check to see if we can find a newer/greater version number on Nuget.org | |
var repo = Repository.Factory.GetCoreV3(NuGetConstants.V3FeedUrl); | |
var resource = await repo.GetResourceAsync<MetadataResource>(); | |
var lastestFormsVersion = await resource.GetLatestVersion("UmbracoForms",false,false,CancellationToken.None); | |
//Parse the current version so we can compare easier | |
var currentVersion = NuGetVersion.Parse(versionNumber); | |
if (lastestFormsVersion > currentVersion) | |
{ | |
return lastestFormsVersion.ToString(); | |
} | |
return currentVersion.ToString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to Members of the Nuget.org Dev Team on help me getting started with the new V3 Nuget API
Requires the following Nuget Packages: