示例#1
0
        public static IDisposable Create(AppFunc app, IDictionary <string, object> properties)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            // Retrieve the instances created in Initialize
            OwinHttpListener wrapper = properties.Get <OwinHttpListener>(typeof(OwinHttpListener).FullName)
                                       ?? new OwinHttpListener();

            System.Net.HttpListener listener = properties.Get <System.Net.HttpListener>(typeof(System.Net.HttpListener).FullName)
                                               ?? new System.Net.HttpListener();

            AddressList addresses = properties.Get <AddressList>(Constants.HostAddressesKey)
                                    ?? new List <IDictionary <string, object> >();

            CapabilitiesDictionary capabilities =
                properties.Get <CapabilitiesDictionary>(Constants.ServerCapabilitiesKey)
                ?? new Dictionary <string, object>();

            var loggerFactory = properties.Get <LoggerFactoryFunc>(Constants.ServerLoggerFactoryKey);

            wrapper.Start(listener, app, addresses, capabilities, loggerFactory);
            return(wrapper);
        }
示例#2
0
        public static void Initialize(IDictionary <string, object> properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            properties[Constants.VersionKey] = Constants.OwinVersion;

            CapabilitiesDictionary capabilities =
                properties.Get <CapabilitiesDictionary>(Constants.ServerCapabilitiesKey)
                ?? new Dictionary <string, object>();

            properties[Constants.ServerCapabilitiesKey] = capabilities;

            capabilities[Constants.ServerNameKey] = Constants.ServerName;

            DetectWebSocketSupport(properties);

            // Let users set advanced configurations directly.
            var wrapper = new OwinHttpListener();

            properties[typeof(OwinHttpListener).FullName]        = wrapper;
            properties[typeof(System.Net.HttpListener).FullName] = wrapper.Listener;
        }