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(); } }
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(); }
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(); } } }
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); }
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"]); }
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(); }
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)); }
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()); }
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(); } }
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); }
static Startup() { OwinServerFactory.Initialize(new Dictionary <string, object>()); }
public void InitializeNullProperties_Throws() { Assert.Throws <ArgumentNullException>(() => OwinServerFactory.Initialize(null)); }