/// <summary> /// Adds the regex redirect. /// </summary> /// <param name="item">The item.</param> /// <returns>redirect item</returns> private static RegExItem AddRegExRedirect(Item item) { if (item == null) { return null; } var regExRedirect = new RegExRedirect(item); if (string.IsNullOrEmpty(regExRedirect.Expression.Value) || string.IsNullOrEmpty(regExRedirect.Value.Value)) { return null; } var redirectItem = new RegExItem { ItemId = regExRedirect.ID, Value = new Regex(regExRedirect.Value.Value, RegexOptions.IgnoreCase), Expression = new Regex(regExRedirect.Expression.Value, RegexOptions.IgnoreCase), RedirectCode = regExRedirect.RedirectCode }; return redirectItem; }
/// <summary> /// Prepares the redirect URL. /// </summary> /// <param name="item">The item.</param> /// <param name="url">The URL.</param> /// <returns> /// The redirect URL. /// </returns> private static string PrepareRedirectUrl(RegExItem item, string url) { if (item == null) { return string.Empty; } var foundKey = item.Expression.ToString(); var targetUrl = Regex.Replace(url, foundKey, string.Concat(item.Value, "$2"), RegexOptions.IgnoreCase); return UrlNormalizer.EncodeUrl(targetUrl); }
/// <summary> /// Adds the item to list. /// </summary> /// <param name="item">The item.</param> /// <param name="list">The list.</param> /// <returns> /// The item to list. /// </returns> private static List<RegExItem> AddItemToList(RegExItem item, List<RegExItem> list) { if (item != null) { if (!CheckDuplicates(item.Expression, list)) { list.Add(item); } } return list; }