private Response HandleGetRatingsRequest(dynamic parameters) { string vsixId = parameters.id; var rating = FileCounter.GetRating(vsixId, _configuration); return(Response.AsText("{\"rating\": " + rating.Item1 + ", \"count\": " + rating.Item2 + "}", "application/json")); }
public IHttpActionResult GetVsixRating(string id) { var rating = FileCounter.GetRating(id, _configuration); var popularity = new PackagePopularity() { Rating = rating.Item1, Count = rating.Item2 }; return(Ok(popularity)); }
private void AddExtensions(SyndicationItem item, IVsixPackage pkg) { var ns = XNamespace.Get("http://schemas.microsoft.com/developer/vsx-syndication-schema/2010"); var xsi = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance"); // If enabled then fetch the download count for the file, otherwise don't specify it var dlCountElement = new XElement(ns + "DownloadCount", _configGallery.TrackDownloads ? (object)FileCounter.GetDownloadCount(pkg.Id, _configStorage) : new XAttribute(xsi + "nil", "true")); // Default is not set var ratingElement = new XElement(ns + "Rating", new XAttribute(xsi + "nil", "true")); var ratingCountElement = new XElement(ns + "RatingCount", new XAttribute(xsi + "nil", "true")); // If ratings are enabled then attempt to resolve them if (_configGallery.TrackRatings) { // Only apply ratings if there are any var rating = FileCounter.GetRating(pkg.Id, _configStorage); if (rating != null && rating.Item2 > 0) { ratingElement = new XElement(ns + "Rating", rating.Item1); ratingCountElement = new XElement(ns + "RatingCount", rating.Item2); } } var content = new XElement(ns + "Vsix", new XAttribute(XNamespace.Xmlns + "xsi", xsi), new XElement(ns + "Id", pkg.Id), new XElement(ns + "Version", pkg.Version), new XElement(ns + "References"), ratingElement, ratingCountElement, dlCountElement); using (var stringReader = new StringReader(content.ToString())) using (var reader = XmlReader.Create(stringReader)) { item.ElementExtensions.Add(reader); } }