Пример #1
0
        public static IDisposable Create(AppDelegate app, int port, TextWriter output)
        {
            app = ExecutionContextPerRequest.Middleware(app);
            var endPoint = new IPEndPoint(IPAddress.Any, port);

            var schedulerDelegate = new NullSchedulerDelegate(output);
            var scheduler = KayakScheduler.Factory.Create(schedulerDelegate);

            var context = new Dictionary<string, object>
            {
                {"gate.Output", output},
            };
            var channel = new GateRequestDelegate(app, context);

            var server = KayakServer.Factory.CreateHttp(channel, scheduler);
            var listen = server.Listen(endPoint);

            var thread = new Thread(_ => scheduler.Start());
            thread.Start();

            return new Disposable(() =>
            {
                scheduler.Stop();
                thread.Join(5000);
                listen.Dispose();
                server.Dispose();
            });
        }
Пример #2
0
        public static IDisposable Create(AppFunc app, int port, TextWriter output)
        {
            app = ExecutionContextPerRequest.Middleware(app);
            var endPoint = new IPEndPoint(IPAddress.Any, port);

            var schedulerDelegate = new NullSchedulerDelegate(output);
            var scheduler         = KayakScheduler.Factory.Create(schedulerDelegate);

            var context = new Dictionary <string, object>
            {
                { "gate.Output", output },
            };
            var channel = new GateRequestDelegate(app, context);

            var server = KayakServer.Factory.CreateHttp(channel, scheduler);
            var listen = server.Listen(endPoint);

            var thread = new Thread(_ => scheduler.Start());

            thread.Start();

            return(new Disposable(() =>
            {
                scheduler.Stop();
                thread.Join(5000);
                listen.Dispose();
                server.Dispose();
            }));
        }