public IHttpActionResult Get( ODataQueryOptions <V2FeedPackage> options, string curatedFeedName, [FromUri] string semVerLevel = null) { var result = GetCuratedFeedResult(curatedFeedName); if (result.ActionResult != null) { return(result.ActionResult); } var semVerLevelKey = SemVerLevelKey.ForSemVerLevel(semVerLevel); var queryable = result .Packages .Where(p => p.PackageStatusKey == PackageStatus.Available) .Where(SemVerLevelKey.IsPackageCompliantWithSemVerLevelPredicate(semVerLevel)) .ToV2FeedPackageQuery( _configurationService.GetSiteRoot(UseHttps()), _configurationService.Features.FriendlyLicenses, semVerLevelKey) .InterceptWith(new NormalizeVersionInterceptor()); return(TrackedQueryResult(options, queryable, MaxPageSize, customQuery: true)); }
public IHttpActionResult Get(ODataQueryOptions <V1FeedPackage> options) { if (!_featureFlagService.IsODataV1GetAllEnabled()) { return(BadRequest(Strings.ODataDisabled)); } if (!ODataQueryVerifier.AreODataOptionsAllowed(options, ODataQueryVerifier.V1Packages, _configurationService.Current.IsODataFilterEnabled, nameof(Get))) { return(BadRequest(ODataQueryVerifier.GetValidationFailedMessage(options))); } bool result = TryShouldIgnoreOrderById(options, out var shouldIgnoreOrderById); if (!result) { return(BadRequest("Invalid OrderBy parameter")); } var queryable = GetAll() .Where(p => !p.IsPrerelease && p.PackageStatusKey == PackageStatus.Available) .Where(SemVerLevelKey.IsUnknownPredicate()) .WithoutSortOnColumn(Version) .WithoutSortOnColumn(Id, shouldIgnoreOrderById) .ToV1FeedPackageQuery(_configurationService.GetSiteRoot(UseHttps())); return(TrackedQueryResult(options, queryable, MaxPageSize, customQuery: true)); }
public static IHtmlString PreFormattedText(this HtmlHelper self, string text, IGalleryConfigurationService configurationService) { // Encode HTML entities. Important! Security! var encodedText = HttpUtility.HtmlEncode(text); // Turn HTTP and HTTPS URLs into links. // Source: https://stackoverflow.com/a/4750468 string anchorEvaluator(Match match) { string trimmedEntityValue = string.Empty; string trimmedAnchorValue = match.Value; foreach (var trimmedEntity in _trimmedHtmlEntities) { if (match.Value.EndsWith(trimmedEntity)) { // Remove trailing html entity from anchor URL trimmedAnchorValue = match.Value.Substring(0, match.Value.Length - trimmedEntity.Length); trimmedEntityValue = trimmedEntity; break; } } if (PackageHelper.TryPrepareUrlForRendering(trimmedAnchorValue, out string formattedUri)) { string anchorText = formattedUri; string siteRoot = configurationService.GetSiteRoot(useHttps: true); // Format links to NuGet packages Match packageMatch = RegexEx.MatchWithTimeout(formattedUri, $@"({Regex.Escape(siteRoot)}\/packages\/(?<name>\w+([_.-]\w+)*(\/[0-9a-zA-Z-.]+)?)\/?$)", RegexOptions.IgnoreCase); if (packageMatch != null && packageMatch.Groups["name"].Success) { anchorText = packageMatch.Groups["name"].Value; } return($"<a href=\"{formattedUri}\" rel=\"nofollow\">{anchorText}</a>" + trimmedEntityValue); } return(match.Value); } encodedText = RegexEx.TryReplaceWithTimeout( encodedText, @"((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)", anchorEvaluator, RegexOptions.IgnoreCase); // Replace new lines with the <br /> tag. encodedText = encodedText.Replace("\n", "<br />"); // Replace more than one space in a row with a space then . encodedText = RegexEx.TryReplaceWithTimeout( encodedText, " +", match => " " + string.Join(string.Empty, Enumerable.Repeat(" ", match.Value.Length - 1)), RegexOptions.None); return(self.Raw(encodedText)); }
public IHttpActionResult Get(ODataQueryOptions <V1FeedPackage> options) { var queryable = _packagesRepository.GetAll() .Where(p => !p.IsPrerelease && !p.Deleted) .WithoutVersionSort() .ToV1FeedPackageQuery(_configurationService.GetSiteRoot(UseHttps())); return(QueryResult(options, queryable, MaxPageSize)); }
public IHttpActionResult Get(ODataQueryOptions <V2FeedPackage> options, string curatedFeedName) { if (!_entities.CuratedFeeds.Any(cf => cf.Name == curatedFeedName)) { return(NotFound()); } var queryable = _curatedFeedService.GetPackages(curatedFeedName) .ToV2FeedPackageQuery(_configurationService.GetSiteRoot(UseHttps()), _configurationService.Features.FriendlyLicenses) .InterceptWith(new NormalizeVersionInterceptor()); return(QueryResult(options, queryable, MaxPageSize)); }
public IHttpActionResult Get(ODataQueryOptions <V1FeedPackage> options) { if (!ODataQueryVerifier.AreODataOptionsAllowed(options, ODataQueryVerifier.V1Packages, _configurationService.Current.IsODataFilterEnabled, nameof(Get))) { return(BadRequest(ODataQueryVerifier.GetValidationFailedMessage(options))); } var queryable = _packagesRepository.GetAll() .Where(p => !p.IsPrerelease && !p.Deleted) .WithoutVersionSort() .ToV1FeedPackageQuery(_configurationService.GetSiteRoot(UseHttps())); return(QueryResult(options, queryable, MaxPageSize)); }
public IHttpActionResult Get(ODataQueryOptions <V1FeedPackage> options) { if (!ODataQueryVerifier.AreODataOptionsAllowed(options, ODataQueryVerifier.V1Packages, _configurationService.Current.IsODataFilterEnabled, nameof(Get))) { return(BadRequest(ODataQueryVerifier.GetValidationFailedMessage(options))); } var queryable = _packagesRepository.GetAll() .Where(p => !p.IsPrerelease && p.PackageStatusKey == PackageStatus.Available) .Where(SemVerLevelKey.IsUnknownPredicate()) .WithoutSortOnColumn(Version) .WithoutSortOnColumn(Id, ShouldIgnoreOrderById(options)) .ToV1FeedPackageQuery(_configurationService.GetSiteRoot(UseHttps())); return(QueryResult(options, queryable, MaxPageSize)); }
public IHttpActionResult Get( ODataQueryOptions <V2FeedPackage> options, string curatedFeedName, [FromUri] string semVerLevel = null) { if (!_entities.CuratedFeeds.Any(cf => cf.Name == curatedFeedName)) { return(NotFound()); } var semVerLevelKey = SemVerLevelKey.ForSemVerLevel(semVerLevel); var queryable = _curatedFeedService.GetPackages(curatedFeedName) .Where(SemVerLevelKey.IsPackageCompliantWithSemVerLevel(semVerLevel)) .ToV2FeedPackageQuery( _configurationService.GetSiteRoot(UseHttps()), _configurationService.Features.FriendlyLicenses, semVerLevelKey) .InterceptWith(new NormalizeVersionInterceptor()); return(QueryResult(options, queryable, MaxPageSize)); }
internal static string GetSiteRoot(bool useHttps) { return(_configuration.GetSiteRoot(useHttps)); }
public static IHtmlString PreFormattedText(this HtmlHelper self, string text, IGalleryConfigurationService configurationService) { void appendText(StringBuilder builder, string inputText) { var encodedText = HttpUtility.HtmlEncode(inputText); // Replace new lines with the <br /> tag. encodedText = encodedText.Replace("\n", "<br />"); // Replace more than one space in a row with a space then . encodedText = RegexEx.TryReplaceWithTimeout( encodedText, " +", match => " " + string.Join(string.Empty, Enumerable.Repeat(" ", match.Value.Length - 1)), RegexOptions.None); builder.Append(encodedText); } void appendUrl(StringBuilder builder, string inputText) { string trimmedEntityValue = string.Empty; string trimmedAnchorValue = inputText; foreach (var trimmedEntity in _trimmedHtmlEntities) { if (inputText.EndsWith(trimmedEntity)) { // Remove trailing html entity from anchor URL trimmedAnchorValue = inputText.Substring(0, inputText.Length - trimmedEntity.Length); trimmedEntityValue = trimmedEntity; break; } } if (PackageHelper.TryPrepareUrlForRendering(trimmedAnchorValue, out string formattedUri)) { string anchorText = formattedUri; string siteRoot = configurationService.GetSiteRoot(useHttps: true); // Format links to NuGet packages Match packageMatch = RegexEx.MatchWithTimeout( formattedUri, $@"({Regex.Escape(siteRoot)}\/packages\/(?<name>\w+([_.-]\w+)*(\/[0-9a-zA-Z-.]+)?)\/?$)", RegexOptions.IgnoreCase); if (packageMatch != null && packageMatch.Groups["name"].Success) { anchorText = packageMatch.Groups["name"].Value; } builder.AppendFormat( "<a href=\"{0}\" rel=\"nofollow\">{1}</a>{2}", HttpUtility.HtmlEncode(formattedUri), HttpUtility.HtmlEncode(anchorText), HttpUtility.HtmlEncode(trimmedEntityValue)); } else { builder.Append(HttpUtility.HtmlEncode(inputText)); } } // Turn HTTP and HTTPS URLs into links. // Source: https://stackoverflow.com/a/4750468 var matches = RegexEx.MatchesWithTimeout( text, @"((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)", RegexOptions.IgnoreCase); var output = new StringBuilder(text.Length); var currentIndex = 0; if (matches != null && matches.Count > 0) { foreach (Match match in matches) { // Encode the text literal before the URL, if any. var literalLength = match.Index - currentIndex; if (literalLength > 0) { var literal = text.Substring(currentIndex, literalLength); appendText(output, literal); } // Encode the URL. var url = match.Value; appendUrl(output, url); currentIndex = match.Index + match.Length; } } // Encode the text literal appearing after the last URL, if any. if (currentIndex < text.Length) { var literal = text.Substring(currentIndex, text.Length - currentIndex); appendText(output, literal); } return(self.Raw(output.ToString())); }
protected virtual string GetSiteRoot() { return(_configurationService.GetSiteRoot(UseHttps()).TrimEnd('/') + '/'); }