Tornado.web.Application.add_handlers C# (CSharp) Method

add_handlers() public method

public add_handlers ( string host_pattern, object>.TupleList host_handlers ) : void
host_pattern string
host_handlers object>.TupleList
return void
        public void add_handlers(string host_pattern, TupleList<string, CreateRequestHandler, Dictionary<string, object>> host_handlers)
        {
            /*Appends the given handlers to our handler list.

            Note that host patterns are processed sequentially in the
            order they were added, and only the first matching pattern is
            used.  This means that all handlers for a given host must be
            added in a single add_handlers call.
            */
            if (!host_pattern.EndsWith("$"))
                host_pattern += "$";
            var handlers_ = new List<URLSpec>();
            // The handlers with the wildcard host_pattern are a special
            // case - they're added in the constructor but should have lower
            // precedence than the more-precise handlers added later.
            // If a wildcard handler group exists, it should always be last
            // in the list, so insert new groups just before it.
            if (handlers.Any() && handlers.Last().Item1.ToString() == ".*$")
                handlers.Insert(handlers.Count - 1, Tuple.Create(new Regex(host_pattern, RegexOptions.Compiled), handlers_));
            else
                handlers.Add(Tuple.Create(new Regex(host_pattern, RegexOptions.Compiled), handlers_));

            foreach (var spec in host_handlers)
            {
                URLSpec spec_ = null;

                //todo? if type(spec) is type(()):
                {
                    //assert len(spec) in (2, 3)
                    var pattern = spec.Item1;
                    var handler = spec.Item2;

                    /*if isinstance(handler, str):
                        # import the Module and instantiate the class
                        # Must be a fully qualified name (module.ClassName)
                        handler = import_object(handler)*/

                    /*if len(spec) == 3:
                        kwargs = spec[2]
                    else:
                        kwargs = {}*/
                    var kwargs = spec.Item3;
                    spec_ = new URLSpec(pattern, handler, kwargs);
                }
                handlers_.Add(spec_);
                if (spec_.name != null)
                {
                    if (named_handlers.ContainsKey(spec_.name))
                        logging.warning(string.Format("Multiple handlers named {0}; replacing previous value", spec_.name));
                    named_handlers[spec_.name] = spec_;
                }
            }
        }