Пример #1
0
        static void Main(string[] args)
        {
            var owinbuilder = new AppBuilder();

            OwinServerFactory.Initialize(owinbuilder.Properties);
            new SampleOwinApp.Startup().Configuration(owinbuilder);
            var builder = ServerBuilder.New()
                          .SetPort(8888)
                          .SetOwinApp(owinbuilder.Build())
                          .SetOwinCapabilities((IDictionary <string, object>)owinbuilder.Properties[OwinKeys.ServerCapabilitiesKey])
                          .SetExecutionContextFlow(ExecutionContextFlow.SuppressAlways);

            //builder
            //    .SetCertificate(new X509Certificate2("../../../sslcert/test.pfx", "nowin"))
            //    .RequireClientCertificate();
            using (var server = builder.Build())
            {
                // Workaround for bug in Windows Server 2012 when ReadLine is called directly after AcceptAsync
                // By starting it in another thread and probably even later than calling readline it works
                Task.Run(() => server.Start());
                //using (new Timer(o =>
                //    {
                //        var s = (INowinServer)o;
                //        Console.WriteLine("Connections {0}/{1}", s.ConnectionCount, s.CurrentMaxConnectionCount);
                //    }, server, 2000, 2000))
                {
                    Console.WriteLine("Listening on ports 8888. Enter to exit.");
                    Console.ReadLine();
                }
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            // create a new AppBuilder
            IAppBuilder app = new AppBuilder();

            // init nowin's owin server factory.
            OwinServerFactory.Initialize(app.Properties);

            Configure(app);

            var          serverBuilder = new ServerBuilder();
            const string ip            = "127.0.0.1";
            const int    port          = 8888;

            serverBuilder.SetAddress(IPAddress.Parse(ip)).SetPort(port)
            .SetOwinApp(app.Build())
            .SetOwinCapabilities((IDictionary <string, object>)app.Properties[OwinKeys.ServerCapabilitiesKey]);

            using (var server = serverBuilder.Build()) {
                var serverRef = new WeakReference <INowinServer>(server);

                Task.Run(() => {
                    INowinServer nowinServer;
                    if (serverRef.TryGetTarget(out nowinServer))
                    {
                        nowinServer.Start();
                    }
                });

                var baseAddress = "http://" + ip + ":" + port + "/";
                Console.WriteLine("Nowin server listening {0}, press ENTER to exit.", baseAddress);

                Console.ReadLine();
            }
        }
Пример #3
0
        static void StartWebServer()
        {
            var appBuilder = new AppBuilder();

            OwinServerFactory.Initialize(appBuilder.Properties);

            appBuilder.Properties.Add("host.AppName", "QED");

            fn.ConfigureBuilder(appBuilder);

            var serverBuilder = ServerBuilder
                                .New()
                                .SetPort(fn.GetConfiguration <int>(Constants.Configuration.PortKey))
                                .SetOwinApp(appBuilder.Build())
                                .SetOwinCapabilities((IDictionary <string, object>)appBuilder.Properties[OwinKeys.ServerCapabilitiesKey]);

            var server = serverBuilder.Start();

            Console.CancelKeyPress += (sender, eventArgs) => server.Dispose();

            Console.WriteLine("Started qed.");
            Console.WriteLine("Listening on port {0}.", fn.GetConfiguration <int>(Constants.Configuration.PortKey));
            Console.WriteLine("Press CTRL+C to exit.");
            Console.WriteLine();
        }
Пример #4
0
        public virtual async Task StartAsync <TContext>(IHttpApplication <TContext> application, CancellationToken cancellationToken)
        {
            CreateOwinProps(application, out Func <IDictionary <string, object>, Task> appFunc, out Dictionary <string, object> props);

            OwinServerFactory.Initialize(props);

            _HttpListenerServer = OwinServerFactory.Create(appFunc, props);
        }
Пример #5
0
        public void Initialize_PopulatesExpectedFields()
        {
            var properties = new Dictionary <string, object>();

            OwinServerFactory.Initialize(properties);

            Assert.Equal("1.0", properties["owin.Version"]);
            Assert.IsType <OwinHttpListener>(properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"]);
            Assert.IsType <System.Net.HttpListener>(properties["System.Net.HttpListener"]);
        }
Пример #6
0
        public WebServer(IPEndPoint endpoint)
        {
            var owinbuilder = new AppBuilder();

            OwinServerFactory.Initialize(owinbuilder.Properties);
            new Startup().Configuration(owinbuilder);
            var builder = ServerBuilder.New()
                          .SetEndPoint(endpoint)
                          .SetOwinApp(owinbuilder.Build())
                          .SetServerHeader("DotOPDS");

            server = builder.Start();
        }
Пример #7
0
        static void Main(string[] args)
        {
            var app = new AppBuilder();

            OwinServerFactory.Initialize(app.Properties);

            app.UseWindsorContainer("windsor.config");

            var container     = app.GetWindsorContainer();
            var logMiddleware = container.Resolve <ConsoleLogMiddleware>();

            app.Use(logMiddleware);

            var options = container.Resolve <StaticFileMiddlewareOptions>();

            app.UseStaticFile(options);

            var startup = new Startup();

            startup.Configuration(app);

            var          builder = new ServerBuilder();
            const string ip      = "127.0.0.1";
            const int    port    = 8888;

            builder.SetAddress(IPAddress.Parse(ip)).SetPort(port)
            .SetOwinApp(app.Build())
            .SetOwinCapabilities((IDictionary <string, object>)app.Properties[OwinKeys.ServerCapabilitiesKey]);

            using (var server = builder.Build()) {
                var serverRef = new WeakReference <INowinServer>(server);

                Task.Run(() => {
                    INowinServer nowinServer;
                    if (serverRef.TryGetTarget(out nowinServer))
                    {
                        nowinServer.Start();
                    }
                });

                var baseAddress = "http://" + ip + ":" + port + "/";
                Console.WriteLine("Nowin server listening {0}, press ENTER to exit.", baseAddress);

                Console.ReadLine();
            }
        }
        public static IDisposable CreateHttpListenerServer(List <Uri> baseAddresses, Func <IDictionary <string, object>, Task> appFunc)
        {
            var props = new Dictionary <string, object>();

            var addresses = baseAddresses.Select(baseAddress => new Dictionary <string, object>()
            {
                { "host", baseAddress.Host },
                { "port", baseAddress.Port.ToString() },
                { "scheme", baseAddress.Scheme },
                { "path", baseAddress.AbsolutePath }
            }).Cast <IDictionary <string, object> >().ToList();

            props["host.Addresses"] = addresses;
            //props["server.LoggerFactory"] = LoggerFunc goes here;
            OwinServerFactory.Initialize(props);
            return(OwinServerFactory.Create(appFunc, props));
        }
Пример #9
0
        private IDisposable CreateListener(int port)
        {
            var appProperties = new AppProperties(new Dictionary <string, object>())
            {
                Addresses = AddressCollection.Create()
            };

            var address = Address.Create();

            address.Scheme = "http";
            address.Host   = "localhost";
            address.Port   = port.ToString();
            address.Path   = "/sonarlint/api/";
            appProperties.Addresses.Add(address);

            // Create a new Owin HTTPListener that forwards all requests to our processor for handling.
            return(OwinServerFactory.Create(requestProcessor.ProcessRequest, appProperties.Dictionary));
        }
Пример #10
0
        private static void Main(string[] args)
        {
            var properties = new Dictionary <string, object> {
                { "host.Addresses", new [] { new Dictionary <string, object> {
                                                 { "port", "1337" },
                                                 { "host", "localhost" }
                                             } as IDictionary <string, object> }.ToList() }
            };

            //var server = Server.AppFuncServer();
            var server = Server.MiddlewareFuncServer();

            var cancelWait = new ManualResetEvent(false);

            Console.CancelKeyPress += (sender, e) => { cancelWait.Set(); };
            using (OwinServerFactory.Create(server, properties))
            {
                Console.WriteLine("Listening on http://localhost:1337");
                cancelWait.WaitOne();
            }
        }
Пример #11
0
        private static INowinServer BuildNowinServer(IPAddress ip, int port)
        {
            // create a new AppBuilder
            var appBuilder = new AppBuilder();

            // init nowin's owin server factory.
            OwinServerFactory.Initialize(appBuilder.Properties);
            var startup = new Startup();

            startup.Configuration(appBuilder);
            // build server
            var serverBuilder = new ServerBuilder();
            var capabilities  = appBuilder.Properties[OwinKeys.ServerCapabilitiesKey];

            serverBuilder
            .SetAddress(ip)
            .SetPort(port)
            .SetOwinApp(appBuilder.Build())
            .SetOwinCapabilities((IDictionary <string, object>)capabilities);
            return(serverBuilder.Build());
        }
Пример #12
0
        public static void Main(string[] args)
        {
            // create a new AppBuilder
            IAppBuilder app = new AppBuilder();

            // init nowin's owin server factory.
            OwinServerFactory.Initialize(app.Properties);

            app.UseStaticFile(new StaticFileMiddlewareOptions {
                RootDirectory    = @"C:\inetpub\wwwroot",
                DefaultFile      = "iisstart.htm",
                EnableETag       = true,
                MimeTypeProvider = new MimeTypeProvider()
            });

            var          serverBuilder = new ServerBuilder();
            const string ip            = "127.0.0.1";
            const int    port          = 8888;

            serverBuilder.SetAddress(IPAddress.Parse(ip)).SetPort(port)
            .SetOwinApp(app.Build())
            .SetOwinCapabilities((IDictionary <string, object>)app.Properties[OwinKeys.ServerCapabilitiesKey]);

            using (var server = serverBuilder.Build()) {
                var serverRef = new WeakReference <INowinServer>(server);

                Task.Run(() => {
                    INowinServer nowinServer;
                    if (serverRef.TryGetTarget(out nowinServer))
                    {
                        nowinServer.Start();
                    }
                });

                var baseAddress = "http://" + ip + ":" + port + "/";
                Console.WriteLine("Nowin server listening {0}, press ENTER to exit.", baseAddress);

                Console.ReadLine();
            }
        }
Пример #13
0
        public void Start <TContext>(IHttpApplication <TContext> application)
        {
            Func <IDictionary <string, object>, Task> appFunc = async env =>
            {
                FeatureCollection features = new FeatureCollection(new OwinFeatureCollection(env));

                TContext context = application.CreateContext(features);

                try
                {
                    await application.ProcessRequestAsync(context);
                }
                catch (Exception ex)
                {
                    application.DisposeContext(context, ex);
                    throw;
                }

                application.DisposeContext(context, null);
            };

            appFunc = OwinWebSocketAcceptAdapter.AdaptWebSockets(appFunc);

            Dictionary <string, object> props = new Dictionary <string, object>
            {
                ["host.Addresses"] =
                    Features.Get <IServerAddressesFeature>()
                    .Addresses.Select(add => new Uri(add))
                    .Select(add => new Address(add.Scheme, add.Host, add.Port.ToString(), add.LocalPath).Dictionary)
                    .ToList()
            };


            OwinServerFactory.Initialize(props);

            _HttpListenerServer = OwinServerFactory.Create(appFunc, props);
        }
 internal void InitManager(Uri url)
 {
     _owinServerRef = OwinServerFactory.CreateOwinServer(url);
 }
Пример #15
0
 public void InitializeNullProperties_Throws()
 {
     Assert.Throws <ArgumentNullException>(() => OwinServerFactory.Initialize(null));
 }
 public Func <IDisposable> Build()
 {
     return(() => OwinServerFactory.Create(c => RunMiddleware(Middleware.ToArray(), c), Properties));
 }
Пример #17
0
 public void CreateNullAppFunc_Throws()
 {
     Assert.Throws <ArgumentNullException>(() => OwinServerFactory.Create(null, new Dictionary <string, object>()));
 }
Пример #18
0
 public void CreateNullProperties_Throws()
 {
     Assert.Throws <ArgumentNullException>(() => OwinServerFactory.Create(_notImplemented, null));
 }
Пример #19
0
 static Startup()
 {
     OwinServerFactory.Initialize(new Dictionary <string, object>());
 }
Пример #20
0
 public void CreateEmptyProperties_Success()
 {
     OwinServerFactory.Create(_notImplemented, new Dictionary <string, object>());
 }
 public void Dispose()
 {
     OwinServerFactory.UnRegisterOwinServer(_owinServerRef);
 }