static HttpListenerServer ConfigureWebServer(JObject config, IEnumerable <MapHandler> handlerMappers) { if (handlerMappers != null) { JArray urls = config["listenerUrls"] as JArray; //list of urls to listen on if (urls != null) { List <string> urlList = new List <string>(); foreach (JToken cur in urls) { string tmp = cur.ToString(); if (!string.IsNullOrEmpty(tmp)) { urlList.Add(tmp); } } if (urlList.Count > 0) { //ok we can start this thing ServerTaskPoolOptions options = new ServerTaskPoolOptions(); ServerRouting router = new ServerRouting(); foreach (MapHandler cur in handlerMappers) { if (cur != null) { router.Map.Add(cur); } } if (router.Map.Count > 0) { HttpListenerServerListener listener = new HttpListenerServerListener(urlList, new Shim(router)); HttpListenerServer server = HttpListenerServer.Create(listener, options, false); return(server); } } } } return(null); }
private static HttpListenerServer InitServer(IEnumerable <string> listenUrls, IEnumerable <IHandlerMapper> handlerMappers) { ServerTaskPoolOptions options = new ServerTaskPoolOptions(); ServerRouting router = new ServerRouting(); foreach (MapHandler cur in handlerMappers) { if (cur != null) { router.Map.Add(cur); } } if (router.Map.Count > 0) { HttpListenerServerListener listener = new HttpListenerServerListener(listenUrls, router); HttpListenerServer server = HttpListenerServer.Create(listener, options, false); return(server); } return(null); }