/// <summary>
 /// Initializes a new instance of the <see cref="PublishedCaches"/> class with a content cache
 /// and a media cache.
 /// </summary>
 public PublishedCaches(IPublishedContentCache contentCache, IPublishedMediaCache mediaCache)
 {
     _contentCache = contentCache;
     _mediaCache = mediaCache;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PublishedCaches"/> class with a content cache
 /// and a media cache.
 /// </summary>
 public PublishedCaches(IPublishedContentCache contentCache, IPublishedMediaCache mediaCache)
 {
     _contentCache = contentCache;
     _mediaCache   = mediaCache;
 }
        // TODO: Replace mediaCache with media url provider
        internal static string ParseInternalLinks(string text, UrlProvider urlProvider, IPublishedMediaCache mediaCache)
        {
            if (urlProvider == null)
            {
                throw new ArgumentNullException(nameof(urlProvider));
            }
            if (mediaCache == null)
            {
                throw new ArgumentNullException(nameof(mediaCache));
            }

            // Parse internal links
            var tags = LocalLinkPattern.Matches(text);

            foreach (Match tag in tags)
            {
                if (tag.Groups.Count > 0)
                {
                    var id = tag.Groups[1].Value; //.Remove(tag.Groups[1].Value.Length - 1, 1);

                    //The id could be an int or a UDI
                    if (Udi.TryParse(id, out var udi))
                    {
                        var guidUdi = udi as GuidUdi;
                        if (guidUdi != null)
                        {
                            var newLink = "#";
                            if (guidUdi.EntityType == Constants.UdiEntityType.Document)
                            {
                                newLink = urlProvider.GetUrl(guidUdi.Guid);
                            }
                            else if (guidUdi.EntityType == Constants.UdiEntityType.Media)
                            {
                                newLink = mediaCache.GetById(guidUdi.Guid)?.Url;
                            }

                            if (newLink == null)
                            {
                                newLink = "#";
                            }

                            text = text.Replace(tag.Value, "href=\"" + newLink);
                        }
                    }

                    if (int.TryParse(id, out var intId))
                    {
                        var newLink = urlProvider.GetUrl(intId);
                        text = text.Replace(tag.Value, "href=\"" + newLink);
                    }
                }
            }

            return(text);
        }
Beispiel #4
0
 /// <summary>
 /// Constructor used to return results from the caches
 /// </summary>
 /// <param name="contentCache"></param>
 /// <param name="mediaCache"></param>
 /// <param name="variationContextAccessor"></param>
 public PublishedContentQuery(IPublishedContentCache contentCache, IPublishedMediaCache mediaCache, IVariationContextAccessor variationContextAccessor)
 {
     _contentCache             = contentCache ?? throw new ArgumentNullException(nameof(contentCache));
     _mediaCache               = mediaCache ?? throw new ArgumentNullException(nameof(mediaCache));
     _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
 }