Exemplo n.º 1
0
        internal static bool Initialize()
        {
            LogProviderBase log = null;

            if (LogManager.Instance.State == RunState.Running)
            {
                log = LogManager.Instance.GetProvider(typeof(OncorServer));
            }
            if (log == null)
            {
                log = new NullLogger(typeof(OncorServer));
            }

            ConfigurationProviderBase prov = ConfigurationManager.Instance.GetProvider();

            if (prov != null)
            {
                ConfigurationParameter param      = prov.Get(typeof(HttpListenerServerListener), "listenerUrls");
                List <string>          listenUrls = new List <string>();
                if (param != null)
                {
                    string[] tmp = (string[])param.Value;
                    listenUrls.AddRange(tmp);

                    List <IHandlerMapper> handlers = new List <IHandlerMapper>();
                    handlers.Add(InitApi(prov));
                    handlers.Add(InitFiles(prov));
                    Server = InitServer(listenUrls, handlers);
                    return(Server != null);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        private static void Test_HttpServer()
        {
            using (var server = new HttpListenerServer())
            {
                server.TcpPort = 23979;
                server.Start();

                while (server.IsRunning)
                {
                }
            }
        }
Exemplo n.º 3
0
        public void Init()
        {
            mailResponder = new MailResponder();

            server = new HttpListenerServer(new string[] { URL }, mailResponder);
            server.Start();

            HttpWebRequest requestTemplate = (HttpWebRequest)HttpWebRequest.Create(URL);
            requestTemplate.Timeout = 6000;
            requestTemplate.Proxy = null;
            transceiver = new HttpTransceiver(requestTemplate);
            proxy = new GenericRequestor(transceiver, MailResponder.Protocol);
        }
Exemplo n.º 4
0
        //[TestInitialize]
        public void Init()
        {
            mailResponder = new MailResponder();

            server = new HttpListenerServer(new string[] { URL }, mailResponder);
            server.Start();

            HttpWebRequest requestTemplate = (HttpWebRequest)HttpWebRequest.Create(URL);

            requestTemplate.Timeout = 6000;
            requestTemplate.Proxy   = null;
            transceiver             = new HttpTransceiver(requestTemplate);
            proxy = new GenericRequestor(transceiver, MailResponder.Protocol);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            bool    running = false;
            JObject config  = LoadConfig();

            if (config != null)
            {
                MapHandler fileHandler = ConfigureFileHandler(config);

                List <MapHandler> handlers = new List <MapHandler>();
                if (fileHandler != null)
                {
                    handlers.Add(fileHandler);
                }

                HttpListenerServer server = ConfigureWebServer(config, handlers);
                if (server != null)
                {
                    running = true;

                    server.Start();

                    Console.WriteLine("Listening, enter to stop");
                    Console.ReadLine();
                    server.Stop();
                    Console.WriteLine("Stopped");
                    server.Dispose();
                }
            }

            if (!running) //we failed along the way
            {
                Console.WriteLine("Failed to configure and startup");
            }

            Console.WriteLine("Enter to exit");
            Console.ReadLine();
        }
Exemplo n.º 7
0
        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);
        }
 public void SetUp()
 {
     _httpListenerServer = new HttpListenerServer(8020);
     _requestHandlerMock = new VerifyingRequestHandlerMock();
 }