示例#1
0
        private static void UseCustomMadeServer(string baseAddress, string outputFile, int numberOfWorkers)
        {
            var calculations = new ITextStatCalculation[]
            {
                new AlphanumericCountTextStatCalculation(),
                new NCountTextStatCalculation(),
                new ParagraphCountTextStatCalculation(),
                new SixteenOrMoreWordsSentenceTextStatCalculation()
            };
            IStatsCalculator statsCalculator = new StatsCalculator(calculations);
            IStatsPersister  statsPersister  = new StatsPersister(outputFile);
            var textStatsProcessor           = new TextStatsProcessor(statsCalculator, statsPersister);
            var textStatsProcessorHandler    = new TextStatsProcessorHandler("/", textStatsProcessor);

            IHttpListenerContextHandler[] handlers =
            {
                textStatsProcessorHandler,
                new PongHandler("/ping")
            };

            var options = new HttpServerOptions(baseAddress, handlers, numberOfWorkers);

            using (var server = new HttpServer(options))
            {
                server.Start();
                Ping(baseAddress);
                TellAndWait(baseAddress);
                server.Stop();
            }

            textStatsProcessorHandler.Complete();
        }
示例#2
0
 public HttpServer(HttpServerOptions options)
 {
     _buffer          = new ActionBlock <HttpListenerContext>((Func <HttpListenerContext, Task>)HandleContextAsync);
     _handlers        = options.HttpListenerContextHandlers;
     _numberOfWorkers = options.NumberOfWorkers;
     _listener        = new HttpListener();
     _listener.Prefixes.Add(options.BaseAddress);
 }