using System;
using Umbraco.Core;
namespace Umbraco.Web.Routing
{
///
/// Represents a published snapshot domain with its normalized uri.
///
///
/// In Umbraco it is valid to create domains with name such as example.com, https://www.example.com, example.com/foo/.
/// The normalized uri of a domain begins with a scheme and ends with no slash, eg http://example.com/, https://www.example.com/, http://example.com/foo/.
///
public class DomainAndUri : Domain
{
///
/// Initializes a new instance of the class.
///
/// The original domain.
/// The context current Uri.
public DomainAndUri(Domain domain, Uri currentUri)
: base(domain)
{
try
{
Uri = DomainUtilities.ParseUriFromDomainName(Name, currentUri);
}
catch (UriFormatException)
{
throw new ArgumentException($"Failed to parse invalid domain: node id={domain.ContentId}, hostname=\"{Name.ToCSharpString()}\"."
+ " Hostname should be a valid uri.", nameof(domain));
}
}
///
/// Gets the normalized uri of the domain, within the current context.
///
public Uri Uri { get; }
public override string ToString()
{
return $"{{ \"{Name}\", \"{Uri}\" }}";
}
}
}