public static RouteHandler CreateRouteHandler(XElement controllersEl) { RouteHandler router = new RouteHandler(); if (controllersEl == null) { return(router); } foreach (var controllerEl in controllersEl.Elements()) { if (controllerEl.Name != "Controller") { throw new Exception("Invalid config file"); } foreach (var urlPattern in controllerEl.Elements("Url-pattern")) { router._urlPatterns.Add(new UrlPattern(controllerEl.Element("Url-pattern").Value), controllerEl.Element("Controller-class").Value); } } return(router); }
private void ConfigureDispatcher(String configPath) { try { _controllers = new Dictionary <string, Controller>(); _variables = new Dictionary <string, string>(); XDocument doc = XDocument.Load(configPath); XElement root = doc.Root; // var variablesElement = root.Element("Variables"); if (variablesElement != null) { foreach (var variableElement in variablesElement.Elements("Variable")) { _variables.Add(variableElement.Element("Name").Value, variableElement.Element("Value").Value); } } //Configures route handler var controllersElement = root.Element("Controllers"); _router = RouteHandler.CreateRouteHandler(controllersElement); //Configures resolver var resolverElement = root.Element("ResourceResolver"); _resolver = Utilities.CreateClassExample <IResourceResolver>(resolverElement.Element("Resolver-class").Value); _resolver.Path = resolverElement.Element("Path") == null ? "resources/" : resolverElement.Element("Path").Value; } catch (Exception ex) { Console.WriteLine(ex); _resolver = new ResourceResolver() { Path = "/" }; } }