Esempio n. 1
0
        public void ExecutionContextOnSetupThread(ExecutionContextFlow flow)
        {
            ResetExecutionContextFlowForTestThread();

            CallContext.LogicalSetData("test.data", "test.value");
            var server = new ServerBuilder()
                .SetEndPoint(new IPEndPoint(IPAddress.Loopback, 8082))
                .SetExecutionContextFlow(flow)
                .SetRetrySocketBindingTime(System.TimeSpan.FromSeconds(4))
                .Build();
            server.Start();
            server.Dispose();
            Assert.Equal(
                "test.value",
                CallContext.LogicalGetData("test.data") as string);
        }
Esempio n. 2
0
        public void ExecutionContextFlowFromSetupThread(ExecutionContextFlow flow, string expectedLogicalContextValue)
        {
            ResetExecutionContextFlowForTestThread();

            CallContext.LogicalSetData("test.data", "test.value");

            var server = new ServerBuilder()
                .SetEndPoint(new IPEndPoint(IPAddress.Loopback, 8082))
                .SetExecutionContextFlow(flow)
                .SetRetrySocketBindingTime(System.TimeSpan.FromSeconds(4))
                .Build();
            server.Start();
            server.Dispose();
            

            var separateThreadValue = Task.Factory.StartNew(() => CallContext.LogicalGetData("test.data") as string);
            //Assert.True(ExecutionContext.IsFlowSuppressed());
            Assert.Equal(expectedLogicalContextValue, separateThreadValue.Result);
        }
Esempio n. 3
0
        public void ExecutionContextFlowToOwinApp(ExecutionContextFlow flow, string expectedValue)
        {
            ResetExecutionContextFlowForTestThread();

            string applicationValue = null;
            CallContext.LogicalSetData("test.data", "test.value");

            var server = new ServerBuilder()
                .SetEndPoint(new IPEndPoint(IPAddress.Loopback, 8082))
                .SetExecutionContextFlow(flow)
                .SetOwinApp(env=> AppReadingLogicalCallContext(out applicationValue))
                .SetRetrySocketBindingTime(System.TimeSpan.FromSeconds(4))
                .Build();
            server.Start();
            using (var httpClient = new HttpClient())
            {
                var response = httpClient.GetAsync("http://localhost:8082").Result;
            }
            server.Dispose();

            Assert.Equal(expectedValue, applicationValue);
        }
 public NowinServerInformation(ServerBuilder builder)
 {
     Builder = builder;
     builder.SetExecutionContextFlow(ExecutionContextFlow.Flow);
 }
Esempio n. 5
0
        public static IDisposable Create(Func <IDictionary <string, object>, Task> app, IDictionary <string, object> properties)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }

            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            var capabilities = properties.Get <IDictionary <string, object> >(OwinKeys.ServerCapabilitiesKey)
                               ?? new Dictionary <string, object>();

            var addresses = properties.Get <IList <IDictionary <string, object> > >("host.Addresses")
                            ?? new List <IDictionary <string, object> >();

            var servers   = new List <INowinServer>();
            var endpoints = new List <IPEndPoint>();

            foreach (var address in addresses)
            {
                var builder = ServerBuilder.New().SetOwinApp(app);
                int port;
                if (!int.TryParse(address.Get <string>("port"), out port))
                {
                    throw new ArgumentException("port must be number from 0 to 65535");
                }
                builder.SetPort(port);
                builder.SetOwinCapabilities(capabilities);
                var certificate = address.Get <X509Certificate>("certificate");
                if (certificate != null)
                {
                    builder.SetCertificate(certificate);
                }
                servers.Add(builder.Build());
                endpoints.Add(new IPEndPoint(IPAddress.Loopback, port));
            }

            var disposer = new Disposer(servers.Cast <IDisposable>().ToArray());

            try
            {
                foreach (var nowinServer in servers)
                {
                    nowinServer.Start();
                }
                // This is workaround to Windows Server 2012 issue by calling ReadLine after AcceptAsync, by making one bogus connection this problem goes away
                foreach (var ipEndPoint in endpoints)
                {
                    var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                    socket.Connect(ipEndPoint);
                    socket.Close();
                }
            }
            catch (Exception)
            {
                disposer.Dispose();
                throw;
            }
            return(disposer);
        }
Esempio n. 6
0
 public NowinServer(IOptions <ServerBuilder> options)
 {
     Features.Set <IServerAddressesFeature>(new ServerAddressesFeature());
     _builder = options.Value;
 }
Esempio n. 7
0
 public NowinServerInformation(ServerBuilder builder)
 {
     Builder = builder;
 }