示例#1
0
        /// <summary>
        ///     Initialises a new <see cref="UrlMapping"/>.</summary>
        /// <param name="handler">
        ///     The request handler to map to.</param>
        /// <param name="domain">
        ///     If <c>null</c>, the mapping applies to all domain names. Otherwise, the mapping applies to this domain and all
        ///     subdomains or to this domain only, depending on the value of <paramref name="specificDomain"/>.</param>
        /// <param name="port">
        ///     If <c>null</c>, the mapping applies to all ports; otherwise to the specified port only.</param>
        /// <param name="path">
        ///     If <c>null</c>, the mapping applies to all URL paths. Otherwise, the mapping applies to this path and all
        ///     subpaths or to this path only, depending on the value of <paramref name="specificPath"/>.</param>
        /// <param name="specificDomain">
        ///     If <c>false</c>, the mapping applies to all subdomains of the domain specified by <paramref name="domain"/>.
        ///     Otherwise it applies to the specific domain only.</param>
        /// <param name="specificPath">
        ///     If <c>false</c>, the mapping applies to all subpaths of the path specified by <paramref name="path"/>.
        ///     Otherwise it applies to the specific path only.</param>
        /// <param name="skippable">
        ///     If <c>true</c>, the handler may be skipped if it returns <c>null</c>.</param>
        public UrlMapping(Func <HttpRequest, HttpResponse> handler, string domain = null, int?port = null, string path = null, bool specificDomain = false, bool specificPath = false, bool skippable = false)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            Hook      = new UrlHook(domain, port, path, specificDomain, specificPath);
            Handler   = handler;
            Skippable = skippable;
        }
示例#2
0
 /// <summary>Adds the specified mapping to this collection.</summary>
 public void Add(UrlHook hook, Func <HttpRequest, HttpResponse> handler, bool skippable = false)
 {
     if (hook == null)
     {
         throw new ArgumentNullException("hook");
     }
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     Add(new UrlMapping(hook, handler, skippable));
 }
示例#3
0
        /// <summary>
        ///     Initialises a new <see cref="UrlMapping"/>.</summary>
        /// <param name="hook">
        ///     The URL properties to map from.</param>
        /// <param name="handler">
        ///     The request handler to map to.</param>
        /// <param name="skippable">
        ///     If <c>true</c>, the handler may be skipped if it returns <c>null</c>.</param>
        public UrlMapping(UrlHook hook, Func <HttpRequest, HttpResponse> handler, bool skippable = false)
        {
            if (hook == null)
            {
                throw new ArgumentNullException("mapping");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            Hook      = hook;
            Handler   = handler;
            Skippable = skippable;
        }
示例#4
0
 /// <summary>
 ///     Removes all mappings with a hook equivalent to the specified one.</summary>
 /// <returns>
 ///     The number of elements removed.</returns>
 public int Remove(UrlHook hook)
 {
     lock (Locker)
         return(_mappings.RemoveAll(item => item.Hook.Equals(hook)));
 }