Example #1
0
        public static string[] GetWebLinkVariations(string originalUrl, WebLinkVariationTypes variationTypes)
        {
            var trimmed = originalUrl?.Trim();

            if (string.IsNullOrEmpty(trimmed))
            {
                return(new string[0]);
            }

            var variations = Enumerable.Repeat(trimmed, 1);

            if (variationTypes.HasFlag(WebLinkVariationTypes.IgnoreScheme))
            {
                variations = GetSchemeAgnostic(trimmed);
            }

            if (variationTypes.HasFlag(WebLinkVariationTypes.IgnoreTrailingSlash))
            {
                variations = variations.SelectMany(v => GetSlashAgnostic(v));
            }

            return(variations.ToArray());
        }
        /// <summary>
        /// Matches weblink by URL, including all scheme variations (no scheme, http, https).
        /// </summary>
        /// <remarks>
        /// If link is https://www.nicovideo.jp/user/9979822, this matches
        /// www.nicovideo.jp/user/9979822 (no scheme)
        /// https://www.nicovideo.jp/user/9979822 (https)
        /// http://www.nicovideo.jp/user/9979822 (http)
        /// </remarks>
        public static IQueryable <TLink> WhereUrlIs <TLink>(this IQueryable <TLink> query, string url, WebLinkVariationTypes variationTypes)
            where TLink : class, IWebLink
        {
            var variations = WebLinkVariationsFactory.GetWebLinkVariations(url, variationTypes);

            return(query.Where(w => variations.Contains(w.Url)));
        }
Example #3
0
        public static IQueryable <T> WhereHasLink <T, TLink>(this IQueryable <T> query, string url, WebLinkVariationTypes variationTypes)
            where T : IEntryWithLinks <TLink> where TLink : WebLink
        {
            var variations = WebLinkVariationsFactory.GetWebLinkVariations(url, variationTypes);

            return(query.Where(e => e.WebLinks.Any(w => variations.Contains(w.Url))));
        }