Exemplo n.º 1
0
        public void Start()
        {
            if (Interlocked.CompareExchange(ref isRunning, Running, NotRunning) == NotRunning)
            {
                httpListener = new HttpListener
                {
                    Prefixes =
                    {
                        $"http://+:{ServerOptions.Port}/{ServerOptions.MethodName}/"
                    }
                };

                Console.WriteLine($"Server is starting listening prefixes: {String.Join(";", httpListener.Prefixes)}");

                if (ServerOptions.Async)
                {
                    Console.WriteLine("Press ENTER to stop listening");
                    httpListener.StartProcessingRequestsAsync(CreateAsyncCallback(ServerOptions));
                }
                else
                {
                    httpListener.StartProcessingRequestsSync(CreateSyncCallback(ServerOptions));
                }
            }
        }
Exemplo n.º 2
0
        // private static ConcurrentBag<string> StopedIds { get; }


        public static void Main(string[] args)
        {
            XmlConfigurator.Configure();

            try
            {
                ServerArguments parsedArguments;
                if (!ServerArguments.TryGetArguments(args, out parsedArguments))
                {
                    return;
                }

                var listener = new HttpListener
                {
                    Prefixes =
                    {
                        string.Format("http://+:{0}/{1}/",
                                      parsedArguments.Port,
                                      parsedArguments.MethodName)
                    }
                };

                log.InfoFormat("Server is starting listening prefixes: {0}", string.Join(";", listener.Prefixes));

                if (parsedArguments.Async)
                {
                    log.InfoFormat("Press ENTER to stop listening");
                    listener.StartProcessingRequestsAsync(CreateAsyncCallback(parsedArguments), CreateAsyncCallbackOk(parsedArguments));

                    Console.ReadLine();
                    log.InfoFormat("Server stopped!");
                }
                else
                {
                    listener.StartProcessingRequestsSync(CreateSyncCallback(parsedArguments));
                }
            }
            catch (Exception e)
            {
                Log.Fatal(e);
            }
        }
        public void Start()
        {
            if (Interlocked.CompareExchange(ref isRunning, Running, NotRunning) == NotRunning)
            {
                httpListener = new HttpListener
                {
                    Prefixes =
                    {
                        $"http://+:{ServerOptions.Port}/{ServerOptions.MethodName}/"
                    }
                };

                log.InfoFormat($"Server is starting listening prefixes: {string.Join(";", httpListener.Prefixes)}");
                if (ServerOptions.Async)
                {
                    httpListener.StartProcessingRequestsAsync(CreateAsyncCallback(ServerOptions.MethodDuration));
                }
                else
                {
                    httpListener.StartProcessingRequestsSync(CreateSyncCallback(ServerOptions.MethodDuration));
                }
            }
        }