Last active
October 20, 2016 13:42
-
-
Save sshibani/34a955a2bbb1f13dfda659ed1067d9ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Web; | |
using Tridion.ContentDelivery.DynamicContent; | |
namespace SDlWeb8.Examples | |
{ | |
public class PublicationMappingResolver | |
{ | |
private readonly DynamicMappingsRetriever _mappingsRetriever; | |
public PublicationMappingResolver(ILogger logger) | |
{ | |
_mappingsRetriever = new DynamicMappingsRetriever(); | |
} | |
public IPublicationMapping Resolve(Uri uri) | |
{ | |
var url = uri.GetLeftPart(UriPartial.Path); | |
int espaceIndex = url.IndexOf("%"); | |
if (espaceIndex > 0) | |
{ | |
url = url.Substring(0, espaceIndex); | |
} | |
try | |
{ | |
var mapping = _mappingsRetriever.GetPublicationMapping(url); | |
if (mapping == null || (!mapping.Port.IsNullOrEmpty() && mapping.Port != uri.Port.ToString())) | |
{ | |
throw new Exception(string.Format("Mapping not found for URL '{0}'", url)); | |
} | |
return mapping; | |
} | |
catch (Exception ex) | |
{ | |
throw new Exception(string.Format("Mapping not found for URL '{0}'", url)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment