/// <summary> /// Replaces exising dispatcher for <paramref name="pathTemplate"/> with <paramref name="dispatcher"/>. /// If there's no dispatcher for the specified path, adds a new one. /// </summary> /// <param name="routes">Route collection</param> /// <param name="pathTemplate">Path template</param> /// <param name="dispatcher">Dispatcher to set for specified path</param> public static void Replace(this RouteCollection routes, string pathTemplate, IDashboardDispatcher dispatcher) { if (routes == null) { throw new ArgumentNullException(nameof(routes)); } if (pathTemplate == null) { throw new ArgumentNullException(nameof(pathTemplate)); } if (dispatcher == null) { throw new ArgumentNullException(nameof(dispatcher)); } var list = routes.GetDispatchers(); for (int i = 0; i < list.Count; i++) { var pair = list[i]; if (pair.Item1 == pathTemplate) { list[i] = new Tuple <string, IDashboardDispatcher>(pathTemplate, dispatcher); return; } } routes.Add(pathTemplate, dispatcher); }
public void Add([NotNull] string pathTemplate, [NotNull] IDashboardDispatcher dispatcher) { if (_Routes == null) { throw new ArgumentNullException("RouteCollection"); } _Routes.Add(pathTemplate, dispatcher); }
public void AddDispatcher(IDashboardDispatcher dispatcher) { if (dispatcher == null) { throw new ArgumentNullException(nameof(dispatcher)); } _dispatchers.Add(dispatcher); }
public void Add([NotNull] string pathTemplate, [NotNull] IDashboardDispatcher dispatcher) { if (pathTemplate == null) { throw new ArgumentNullException(nameof(pathTemplate)); } if (dispatcher == null) { throw new ArgumentNullException(nameof(dispatcher)); } _dispatchers.Add(new Tuple <string, IDashboardDispatcher>(pathTemplate, dispatcher)); }
/// <summary> /// Adds a route pattern to route-collection /// </summary> /// <param name="pathPattern">url path pattern.</param> /// <param name="dashboardDispatcher">dispatcher class to be executed when a path matches.</param> public void AddRoute(string pathPattern, IDashboardDispatcher dashboardDispatcher) { if (string.IsNullOrEmpty(pathPattern)) { throw new ArgumentNullException("pathPattern"); } if (dashboardDispatcher == null) { throw new ArgumentNullException("dashboardDispatcher"); } _dispatchers.Add(pathPattern, dashboardDispatcher); }
//[Obsolete("Use the Add(string, IDashboardDispatcher) overload instead. Will be removed in 2.0.0.")] //public void Add([NotNull] string pathTemplate, [NotNull] IRequestDispatcher dispatcher) //{ // if (pathTemplate == null) throw new ArgumentNullException(nameof(pathTemplate)); // if (dispatcher == null) throw new ArgumentNullException(nameof(dispatcher)); // _dispatchers.Add(new Tuple<string, IDashboardDispatcher>(pathTemplate, new RequestDispatcherWrapper(dispatcher))); //} #endif public void Add([NotNull] string pathTemplate, [NotNull] IDashboardDispatcher dispatcher) { if (pathTemplate == null) { throw new ArgumentNullException(nameof(pathTemplate)); } if (dispatcher == null) { throw new ArgumentNullException(nameof(dispatcher)); } if (!_dispatchers.ContainsKey(pathTemplate)) { _dispatchers.Add(pathTemplate, dispatcher); } else { _dispatchers[pathTemplate] = dispatcher; } }
/// <summary> /// Combines exising dispatcher for <paramref name="pathTemplate"/> with <paramref name="dispatcher"/>. /// If there's no dispatcher for the specified path, adds a new one. /// </summary> /// <param name="routes">Route collection</param> /// <param name="pathTemplate">Path template</param> /// <param name="dispatcher">Dispatcher to add or append for specified path</param> public static void Append(this RouteCollection routes, string pathTemplate, IDashboardDispatcher dispatcher) { if (routes == null) { throw new ArgumentNullException(nameof(routes)); } if (pathTemplate == null) { throw new ArgumentNullException(nameof(pathTemplate)); } if (dispatcher == null) { throw new ArgumentNullException(nameof(dispatcher)); } var list = routes.GetDispatchers(); for (var i = 0; i < list.Count; i++) { var pair = list[i]; if (pair.Item1 == pathTemplate) { var composite = pair.Item2 as CompositeDispatcher; if (composite == null) { // replace original dispatcher with a composite one composite = new CompositeDispatcher(pair.Item2); list[i] = new Tuple <string, IDashboardDispatcher>(pathTemplate, composite); } composite.AddDispatcher(dispatcher); return; } } routes.Add(pathTemplate, dispatcher); }