/// <summary> /// Constructor used to create a new handler for multi-tenency with domains and ids /// </summary> /// <param name="logger"></param> /// <param name="contentUrls"></param> /// <param name="itemsForRoute"></param> public ArticulateVirtualNodeByIdRouteHandler(ILogger logger, ContentUrls contentUrls, IEnumerable <IPublishedContent> itemsForRoute) { _logger = logger; _lazyHostsAndIds = new Lazy <Dictionary <string, int> >(() => { //make this lazy so we can reduce the startup overhead var hostsAndIds = new Dictionary <string, int>(StringComparer.InvariantCultureIgnoreCase); foreach (var publishedContent in itemsForRoute) { var allUrls = contentUrls.GetContentUrls(publishedContent); foreach (var url in allUrls) { //if there is a double slash, it will have a domain if (url.Contains("//")) { var uri = new Uri(url, UriKind.Absolute); hostsAndIds[uri.Host] = publishedContent.Id; } else { hostsAndIds[string.Empty] = publishedContent.Id; } } _logger.Debug <ArticulateVirtualNodeByIdRouteHandler>("Hosts/IDs map for node {NodeId}. Values: {ArticulateHostValues}", publishedContent.Id, DebugHostIdsCollection(hostsAndIds)); } return(hostsAndIds); }); }
public TagsOrCategoryPathRouteConstraint(ContentUrls contentUrls, IEnumerable <IPublishedContent> itemsForRoute) { if (itemsForRoute == null) { throw new ArgumentNullException(nameof(itemsForRoute)); } var urlNames = new List <UrlNames>(); foreach (var node in itemsForRoute) { var allUrls = contentUrls.GetContentUrls(node); foreach (var url in allUrls) { //if there is a double slash, it will have a domain if (url.Contains("//")) { var uri = new Uri(url, UriKind.Absolute); urlNames.Add(new UrlNames { Host = uri.Host, CategoryUrlName = node.Value <string>("categoriesUrlName"), TagsUrlName = node.Value <string>("tagsUrlName") }); } else { urlNames.Add(new UrlNames { Host = string.Empty, CategoryUrlName = node.Value <string>("categoriesUrlName"), TagsUrlName = node.Value <string>("tagsUrlName") }); } } } _urlNames = urlNames; }