Ejemplo n.º 1
0
        public static HttpRouter.Tree MapTree(this HttpRouter.Tree @this, HttpRouter.Tree tree)
        {
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }
            if (tree == null)
            {
                throw new ArgumentNullException(nameof(tree));
            }

            foreach (var item in tree)
            {
                @this.Map(item.Key, item.Value);
            }
            return(@this);
        }
Ejemplo n.º 2
0
        public static HttpRouter.Tree MapSlash(this HttpRouter.Tree @this)
        {
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }

            var tempTree = new Dictionary <string, IHttpHandler>();

            foreach (var item in @this)
            {
                tempTree.Add(item.Key, item.Value);
            }
            var tempRouter = new List <KeyValuePair <string, IHttpHandler> >();

            foreach (var item in tempTree)
            {
                var template = item.Key;
                var index    = template.LastIndexOf('/');
                if (index < template.Length - 1)
                {
                    if (!template.Substring(index + 1).StartsWith("{*"))
                    {
                        var newTemplate = item.Key + '/';
                        if (!tempTree.ContainsKey(newTemplate))
                        {
                            tempRouter.Add(new KeyValuePair <string, IHttpHandler>(newTemplate, item.Value));
                        }
                    }
                }
            }
            foreach (var item in tempRouter)
            {
                @this.Map(item.Key, item.Value);
            }
            return(@this);
        }