예제 #1
0
        public IEnumerable <ThreadInfo> HandlePath(ThreadManager TM, IEnumerable <string> path, Dictionary <string, string> query, object state)
        {
            var currentThread = TM.CurrentThread;

            if (path.Any())
            {
                if (Redirects.ContainsKey(path.First()))
                {
                    yield return(TM.Await(currentThread, Redirects[path.First()].HandlePath(TM, path.Skip(1), query, state)));
                }
                else
                {
                    int intValue;
                    if (Int32.TryParse(path.First(), out intValue))
                    {
                        yield return(TM.Await(currentThread, HandleIntPath(TM, intValue, state)));

                        if (!(TM.GetResultNoException(currentThread) is JsonResponse))
                        {
                            yield return(TM.Await(currentThread, IntRedirect.HandlePath(TM, path.Skip(1), query, TM.GetResult(currentThread))));
                        }
                    }
                    else
                    {
                        double floatValue;
                        if (Double.TryParse(path.First(), out floatValue))
                        {
                            yield return(TM.Await(currentThread, HandleFloatPath(TM, floatValue, state)));

                            if (!(TM.GetResultNoException(currentThread) is JsonResponse))
                            {
                                yield return(TM.Await(currentThread, FloatRedirect.HandlePath(TM, path.Skip(1), query, TM.GetResult(currentThread))));
                            }
                        }
                        else
                        {
                            yield return(TM.Await(currentThread, HandleUnknownPath(TM, path.First(), state)));

                            if (!(TM.GetResultNoException(currentThread) is JsonResponse))
                            {
                                yield return(TM.Await(currentThread, UnknownRedirect.HandlePath(TM, path.Skip(1), query, TM.GetResult(currentThread))));
                            }
                        }
                    }
                }
            }
            else
            {
                yield return(TM.Await(currentThread, HandleNoPath(TM, query, state)));
            }

            yield return(TM.Return(currentThread));
        }