public Suggestion(CustomRedirect customRedirect, int pageNumber, int pageSize, string searchWord) { CustomRedirect = customRedirect; PageNumber = pageNumber; PageSize = pageSize; SearchWord = searchWord; }
public CustomRedirect(CustomRedirect redirect) { OldUrl = redirect.OldUrl; NewUrl = redirect.NewUrl; AppendMatchToNewUrl = redirect.AppendMatchToNewUrl; ExactMatch = redirect.ExactMatch; IncludeQueryString = redirect.IncludeQueryString; }
public int Add(CustomRedirect customRedirect) { var oldUrl = HttpUtility.UrlDecode(customRedirect.OldUrl); if (_quickLookupTable.ContainsKey(oldUrl)) Log.WarnFormat("Two or more redirects set up for Old Url: {0}", customRedirect.OldUrl); else _quickLookupTable.Add(oldUrl, customRedirect); return List.Add(customRedirect); }
public virtual void SaveCustomRedirect(CustomRedirect currentCustomRedirect) { using (var store = GetStore()) { //check if there is an exisiting object with matching property "OldUrl" CustomRedirect match = store.Find<CustomRedirect>(OldUrlPropertyName, currentCustomRedirect.OldUrl.ToLower()) .SingleOrDefault(); //if there is a match, replace the value. if (match != null) store.Save(currentCustomRedirect, match.Id); else store.Save(currentCustomRedirect); } }
/// <summary> /// Parses the xml file and reads all redirects. /// </summary> /// <returns>A collection of CustomRedirect objects</returns> public CustomRedirectCollection Load() { const string URLPATH = "/redirects/urls/url"; const string NEWURL = "new"; const string OLDURL = "old"; const string SKIPWILDCARD = "onWildCardMatchSkipAppend"; var redirects = new CustomRedirectCollection(); // Parse all url nodes XmlNodeList nodes = _customRedirectsXmlFile.SelectNodes(URLPATH); foreach (XmlNode node in nodes) { // Each url new url can have several old values // we need to create a redirect object for each pair XmlNode newNode = node.SelectSingleNode(NEWURL); XmlNodeList oldNodes = node.SelectNodes(OLDURL); foreach (XmlNode oldNode in oldNodes) { bool skipWildCardAppend = false; XmlAttribute skipWildCardAttr = oldNode.Attributes[SKIPWILDCARD]; if (skipWildCardAttr != null) { // If value parsing fails, it will be false by default. We do // not really care to check if it fails, as we cannot do anything // about it (throwing an exception is not a good idea here) bool.TryParse(skipWildCardAttr.Value, out skipWildCardAppend); } // Create new custom redirect nodes var redirect = new CustomRedirect(oldNode.InnerText, newNode.InnerText, skipWildCardAppend, true, true, 0); redirects.Add(redirect); } } return redirects; }
private static void AddUrlToTouchedRedirects(Dictionary<CustomRedirect, List<string>> touchedRedirects, CustomRedirect redirect) { if (!touchedRedirects.ContainsKey(redirect)) touchedRedirects.Add(redirect, new List<string>()); touchedRedirects[redirect].Add(redirect.NewUrl); }
public void Remove(CustomRedirect customRedirect) { _quickLookupTable.Remove(customRedirect.OldUrl); List.Remove(customRedirect); }
public void Insert(int index, CustomRedirect customRedirect) { _quickLookupTable.Add(customRedirect.OldUrl, customRedirect); List.Insert(index, customRedirect); }
private static string AppendMatch(CustomRedirect customRedirect, string absolutePath) { var newUrl = new Uri(customRedirect.NewUrl, UriKind.RelativeOrAbsolute); var oldUri = new Uri(absolutePath, UriKind.RelativeOrAbsolute); var uriToAppend = GetPathFromLocalUri(oldUri).Substring(customRedirect.OldUrl.Length); var querystring = GetQueryFrom(newUrl); return CombineUri(newUrl, uriToAppend) + (string.IsNullOrWhiteSpace(querystring) ? string.Empty : string.Concat("?", querystring)); }
private CustomRedirect BuildNewUrl( CustomRedirect customRedirect, string oldUri, string absolutePath, string querystring) { var newUrl = customRedirect.AppendMatchToNewUrl ? AppendMatch(customRedirect, absolutePath) : customRedirect.NewUrl; if (customRedirect.IncludeQueryString && querystring.Length > 1) newUrl = CreateUrlWithQuerystring(querystring, newUrl); return customRedirect.WithNewUrl(newUrl); }
public override void SetUp() { base.SetUp(); _redirect = new CustomRedirect("/no/", "/new/?redirected=1", true, false, true); _redirects.Add(_redirect); }