private UrlSegments GetSegments(string requestPath) { var result = new UrlSegments(); if (string.IsNullOrEmpty(requestPath)) { return(result); } if (!requestPath.Contains("/")) { return(result); } var segments = SplitOnCharAndTrim(requestPath, '/'); if (segments.Count > 0) { result.FirstSegment = segments[0]; } if (segments.Count > 1) { result.SecondSegment = segments[1]; } return(result); }
public override string ToString() { return ($"-- Resource: {Resource}{System.Environment.NewLine}" + $"-- Method: {Method}{System.Environment.NewLine}" + $"-- Params: {string.Join(";", Params.Select(x => x.Key + "=" + x.Value).ToArray())}" + $"-- Headers: {string.Join(";", Headers.Select(x => x.Key + "=" + x.Value).ToArray())}" + $"-- UrlSegments: {string.Join(";", UrlSegments.Select(x => x.Key + "=" + x.Value).ToArray())}" + $"-- ContentType: {ContentType}{System.Environment.NewLine}" + $"-- RequestBody: {RequestBody}{System.Environment.NewLine}"); }
public void AddUrlSegment(string name, string value) { if (!UrlSegments.ContainsKey(name)) { UrlSegments.Add(name, value); } else { UrlSegments[name] = value; } }
// Constructor public RouteSegmentSettings(string urlSegments) { UrlSegments = VirtualPathUtility.AppendTrailingSlash(urlSegments.Trim()); // Converts the url segments string into a collection UrlSegmentsCollection = UrlSegments.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).ToList(); // Position of the segment to compare with the property value PositionOfPropertyValueSegment = UrlSegmentsCollection.Select((value, index) => new { value, index }) .Where(x => x.value.InvariantEquals("{PropertyValue}")) .Select(x => x.index + 1) .FirstOrDefault(); }
/// <summary> /// /// </summary> /// <param name="baseUrl"></param> /// <returns></returns> public Uri GetResourceUri(string baseUrl) { foreach (var segment in UrlSegments.Where(c => !c.IsQueryString)) { Resource = Resource.Replace("{" + segment.Key + "}", Uri.EscapeUriString(segment.Value)); } if (UrlSegments.Any(c => c.IsQueryString)) { var queryString = UrlSegments.Where(c => c.IsQueryString) .Aggregate(new StringBuilder(), (current, next) => current.Append(string.Format("&{0}={1}", Uri.EscapeUriString(next.Key), Uri.EscapeDataString(next.Value)))) .ToString(); Resource = string.Format(Resource.Contains("?") ? "{0}{1}" : "{0}?{1}", Resource, queryString); } Resource = CombineUriParts(baseUrl, Resource); return(new Uri(Resource, UriKind.RelativeOrAbsolute)); }
/// <summary> /// Appends a key/value pair to the end of the existing QueryString in a URI. /// </summary> /// <param name="key">The string key to append to the QueryString.</param> /// <param name="value">The string value to append to the QueryString.</param> public void AddQueryString(string key, string value) { UrlSegments.Add(new UrlSegment(key, value, true)); }
/// <summary> /// Replaces tokenized segments of the URL with a desired value. /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <example>If <code>Resource = "{entity}/Samples.aspx"</code> and <code>someVariable.Publisher = "Disney";</code>, then /// <code>Resource.AddUrlSegment("entity", someVariable.Publisher);</code> becomes <code>Resource = "Disney/Samples.aspx";</code></example> public void AddUrlSegment(string key, string value) { UrlSegments.Add(new UrlSegment(key, value)); }
public IHttpRequest AddUrlSegment(string key, string value) { UrlSegments.Add(key, value); return(this); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="value"></param> public void AddUrlSegment(string key, string value) { UrlSegments.Add(new KeyValuePair <string, string>(key, value)); }