/// <summary> /// Adds a new Redirection. /// </summary> /// <param name="source">The source Page.</param> /// <param name="destination">The destination Page.</param> /// <returns>True if the Redirection is added, false otherwise.</returns> /// <remarks>The method prevents circular and multi-level redirection.</remarks> public static void AddRedirection(PageInfo source, PageRedirection destination) { if (source == null) { throw new ArgumentNullException("source"); } if (destination == null) { throw new ArgumentNullException("destination"); } Cache.Provider.AddRedirection(source.FullName, destination); }
/// <summary> /// Adds the redirection information for a page (overwrites the previous value, if any). /// </summary> /// <param name="source">The source page.</param> /// <param name="destination">The destination page.</param> /// <exception cref="ArgumentNullException">If <b>source</b> or <b>destination</b> are <c>null</c>.</exception> /// <exception cref="ArgumentException">If <b>source</b> or <b>destination</b> are empty.</exception> public void AddRedirection(string source, PageRedirection destination) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (source.Length == 0) { throw new ArgumentException("Source cannot be empty", nameof(source)); } if (destination == null) { throw new ArgumentNullException(nameof(destination)); } lock (_redirections) { _redirections[source.ToLowerInvariant()] = destination; } }
/// <summary> /// Gets the destination of a redirection. /// </summary> /// <param name="source">The source page.</param> /// <returns>The destination page, if any, <c>null</c> otherwise.</returns> /// <exception cref="ArgumentNullException">If <b>source</b> is <c>null</c>.</exception> /// <exception cref="ArgumentException">If <b>source</b> is empty.</exception> public PageRedirection GetRedirectionDestination(string source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (source.Length == 0) { throw new ArgumentException("Source cannot be empty", nameof(source)); } PageRedirection dest = null; lock (_redirections) { _redirections.TryGetValue(source.ToLowerInvariant(), out dest); } return(dest); }