public async void exec(Req req, Res res, Middleware middle) { var config = Singleton.GetSingleton(); var list = config.getRoute(); string path = req.context.Path; var arrayPath = path.Split('/'); var methodHTTP = req.context.Method; var execute = false; var index = 0; ResultValidate resultat = new ResultValidate(); while (!execute && index != list.Count()) { resultat = list[index].ValidateRoute(methodHTTP, arrayPath); execute = resultat.valid; if (!execute) { index++; } else { } } if (execute) { req.paramsUrl = resultat.paramsUrl; if (req.context.HasFormContentType) { var form = await req.context.ReadFormAsync(); req.form = form; } list[index].Execute(req, res); } else { //ERROR 404 } }
public ResultValidate ValidateRoute(string methodName, string[] url) { var i = 0; var y = 0; var result = new ResultValidate(); if (methodName != this.methode) { result.valid = false; return(result); } while (result.valid && i != url.Count() && y != routeSplit.Count()) { bool paramsPresent = false; if (!String.IsNullOrEmpty(routeSplit[y]) && routeSplit[y][0] == ':') { paramsPresent = true; result.paramsUrl.Add(routeSplit[y].Replace(":", ""), url[i]); } if (url[i] == routeSplit[y] || paramsPresent) { } else { result.valid = false; } y++; i++; } if (i != url.Count() || y != routeSplit.Count()) { result.valid = false; } return(result); }