using System; using Oqtane.Shared; namespace Oqtane.Models { /// /// A route is comprised of multiple components: /// {scheme}://{hostname}/{aliaspath}/{pagepath}/*/{moduleid}/{action}/!/{urlparameters}?{query}#{fragment} /// public class Route { // default constructor accepts an absolute route url and alias public Route(string route, string aliaspath) { Uri uri = new Uri(route); Authority = uri.Authority; Scheme = uri.Scheme; Host = uri.Host; Port = uri.Port.ToString(); Query = uri.Query; Fragment = uri.Fragment; AbsolutePath = uri.AbsolutePath; AliasPath = aliaspath; PagePath = AbsolutePath; ModuleId = ""; Action = ""; UrlParameters = ""; if (AliasPath.Length != 0) { PagePath = PagePath.Substring(AliasPath.Length + 1); } int pos = PagePath.IndexOf("/" + Constants.UrlParametersDelimiter + "/"); if (pos != -1) { UrlParameters = PagePath.Substring(pos + 3); PagePath = PagePath.Substring(1, pos); } pos = PagePath.IndexOf("/" + Constants.ModuleDelimiter + "/"); if (pos != -1) { ModuleId = PagePath.Substring(pos + 3); PagePath = PagePath.Substring(1, pos); } if (ModuleId.Length != 0) { pos = ModuleId.IndexOf("/"); if (pos != -1) { Action = ModuleId.Substring(pos + 1); ModuleId = ModuleId.Substring(0, pos); } } if (PagePath.StartsWith("/")) { PagePath = (PagePath.Length == 1) ? "" : PagePath.Substring(1); } if (PagePath.EndsWith("/")) { PagePath = PagePath.Substring(0, PagePath.Length - 1); } } /// /// The host name or IP address and port number (does not include scheme or trailing slash) /// public string Authority { get; set; } /// /// A fully qualified route contains a scheme (ie. http, https ) /// public string Scheme { get; set; } /// /// A fully qualified route contains a host name. The host name may include a port number. /// public string Host { get; set; } /// /// A host name may contain a port number /// public string Port { get; set; } /// /// The absolute path for the route /// public string AbsolutePath { get; set; } /// /// An absolute path may contain an alias path /// public string AliasPath { get; set; } /// /// A absolute path may contain a page path. /// public string PagePath { get; set; } /// /// A route may contain a module id (ie. when created using EditUrl) located after the module delimiter segment (/*/). /// public string ModuleId { get; set; } /// /// A route may contain an action (ie. when created using EditUrl) located after the module id. /// public string Action { get; set; } /// /// A route may contain parameters located after the url parameter delimiter segment (/!/). /// public string UrlParameters { get; set; } /// /// A route may contain querystring parameters located after the ? delimiter /// public string Query { get; set; } /// /// A route may contain a fragment located after the # delimiter /// public string Fragment { get; set; } } }