/// <summary> /// Starts the listener and request processing threads. /// </summary> internal void Start(System.Net.HttpListener listener, AppFunc appFunc, IList <IDictionary <string, object> > addresses, IDictionary <string, object> capabilities, LoggerFactoryFunc loggerFactory) { Contract.Assert(_appFunc == null); // Start should only be called once Contract.Assert(listener != null); Contract.Assert(appFunc != null); Contract.Assert(addresses != null); _listener = listener; _appFunc = appFunc; _loggerFactory = loggerFactory; if (_loggerFactory != null) { _logger = _loggerFactory(typeof(OwinHttpListener).FullName); } _basePaths = new List <string>(); foreach (var address in addresses) { // build url from parts string scheme = address.Get <string>("scheme") ?? Uri.UriSchemeHttp; string host = address.Get <string>("host") ?? "localhost"; string port = address.Get <string>("port") ?? "5000"; string path = address.Get <string>("path") ?? string.Empty; // if port is present, add delimiter to value before concatenation if (!string.IsNullOrWhiteSpace(port)) { port = ":" + port; } // Assume http(s)://+:9090/BasePath/, including the first path slash. May be empty. Must end with a slash. if (!path.EndsWith("/", StringComparison.Ordinal)) { // Http.Sys requires that the URL end in a slash path += "/"; } _basePaths.Add(path); // add a server for each url string url = scheme + "://" + host + port + path; _listener.Prefixes.Add(url); } _capabilities = capabilities; _disconnectHandler = new DisconnectHandler(_listener); if (!_listener.IsListening) { _listener.Start(); _disconnectHandler.Initialize(); } OffloadStartNextRequest(); }
internal static void LogException(LoggerFunc logger, string location, Exception exception) { if (logger == null) { Debug.WriteLine(exception); } else { logger(TraceEventType.Error, 0, location, exception, LogStateAndError); } }
internal static void LogInfo(LoggerFunc logger, string data) { if (logger == null) { Debug.WriteLine(data); } else { logger(TraceEventType.Information, 0, data, null, LogState); } }
private static void DetectWebSocketSupport(IDictionary <string, object> properties) { // There is no explicit API to detect server side websockets, just check for v4.5 / Win8. // Per request we can provide actual verification. if (Environment.OSVersion.Version >= new Version(6, 2)) { var capabilities = properties.Get <CapabilitiesDictionary>(Constants.ServerCapabilitiesKey); capabilities[Constants.WebSocketVersionKey] = Constants.WebSocketVersion; } else { var loggerFactory = properties.Get <LoggerFactoryFunc>(Constants.ServerLoggerFactoryKey); LoggerFunc logger = LogHelper.CreateLogger(loggerFactory, typeof(OwinServerFactory)); LogHelper.LogInfo(logger, "No WebSocket support detected, Windows 8 or later is required."); } }
internal DisconnectHandler(System.Net.HttpListener listener, LoggerFunc logger) { _connectionCancellationTokens = new ConcurrentDictionary <ulong, ConnectionCancellation>(); _listener = listener; _logger = logger; // Get the request queue handle so we can register for disconnect FieldInfo requestQueueHandleField = typeof(System.Net.HttpListener).GetField("m_RequestQueueHandle", BindingFlags.Instance | BindingFlags.NonPublic); // Get the connection id field info from the request object _connectionIdField = typeof(HttpListenerRequest).GetField("m_ConnectionId", BindingFlags.Instance | BindingFlags.NonPublic); if (requestQueueHandleField != null && requestQueueHandleField.FieldType == typeof(CriticalHandle)) { _requestQueueHandle = (CriticalHandle)requestQueueHandleField.GetValue(_listener); } if (_connectionIdField == null || _requestQueueHandle == null) { LogHelper.LogInfo(_logger, "Unable to resolve handles. Disconnect notifications will be ignored."); } }
internal DisconnectHandler(System.Net.HttpListener listener, LoggerFunc logger) { _connectionCancellationTokens = new ConcurrentDictionary<ulong, ConnectionCancellation>(); _listener = listener; _logger = logger; // Get the request queue handle so we can register for disconnect FieldInfo requestQueueHandleField = typeof(System.Net.HttpListener).GetField("m_RequestQueueHandle", BindingFlags.Instance | BindingFlags.NonPublic); // Get the connection id field info from the request object _connectionIdField = typeof(HttpListenerRequest).GetField("m_ConnectionId", BindingFlags.Instance | BindingFlags.NonPublic); if (requestQueueHandleField != null && requestQueueHandleField.FieldType == typeof(CriticalHandle)) { _requestQueueHandle = (CriticalHandle)requestQueueHandleField.GetValue(_listener); } if (_connectionIdField == null || _requestQueueHandle == null) { LogHelper.LogInfo(_logger, "Unable to resolve handles. Disconnect notifications will be ignored."); } }
public static void Main(string[] args) { // Build the chain of responsibility Logger Logger, LoggerFunc, LoggerWarnErr; Logger = new ConsoleLogger(LogLevel.ALL); LoggerFunc = Logger.SetNext(new EmailLogger(LogLevel.FUNCTIONAL_ERR | LogLevel.FUNCTIONAL_MSG)); LoggerWarnErr = LoggerFunc.SetNext(new FileLogger(LogLevel.WARN | LogLevel.ERR)); // Handled by ConsoleLogger since the console has a loglevel of all Logger.Message("Entering function", LogLevel.DBG); Logger.Message("Data retrieved", LogLevel.INFO); // Handled by ConsoleLogger and FileLogger - Warning & Error Logger.Message("Warning empty field", LogLevel.WARN); Logger.Message("Error getting data", LogLevel.ERR); // Handled by ConsoleLogger and EmailLogger - functional error Logger.Message("Error calculating events", LogLevel.FUNCTIONAL_ERR); // Handled by ConsoleLogger and EmailLogger Logger.Message("Date is not valid", LogLevel.FUNCTIONAL_MSG); }
public YogaConfig(LoggerFunc logger = null) { Logger = logger ?? LogToConsole; }
public static void YGConfigSetLogger(YogaConfig config, LoggerFunc logger) => config.LoggerFunc = logger;
/// <summary> /// Starts the listener and request processing threads. /// </summary> internal void Start(System.Net.HttpListener listener, AppFunc appFunc, IList<IDictionary<string, object>> addresses, IDictionary<string, object> capabilities, LoggerFactoryFunc loggerFactory) { Contract.Assert(_appFunc == null); // Start should only be called once Contract.Assert(listener != null); Contract.Assert(appFunc != null); Contract.Assert(addresses != null); _listener = listener; _appFunc = appFunc; _loggerFactory = loggerFactory; if (_loggerFactory != null) { _logger = _loggerFactory(typeof(OwinHttpListener).FullName); } _basePaths = new List<string>(); foreach (var address in addresses) { // build url from parts string scheme = address.Get<string>("scheme") ?? Uri.UriSchemeHttp; string host = address.Get<string>("host") ?? "localhost"; string port = address.Get<string>("port") ?? "5000"; string path = address.Get<string>("path") ?? string.Empty; // if port is present, add delimiter to value before concatenation if (!string.IsNullOrWhiteSpace(port)) { port = ":" + port; } // Assume http(s)://+:9090/BasePath/, including the first path slash. May be empty. Must end with a slash. if (!path.EndsWith("/", StringComparison.Ordinal)) { // Http.Sys requires that the URL end in a slash path += "/"; } _basePaths.Add(path); // add a server for each url string url = scheme + "://" + host + port + path; _listener.Prefixes.Add(url); } _capabilities = capabilities; _disconnectHandler = new DisconnectHandler(_listener); if (!_listener.IsListening) { _listener.Start(); _disconnectHandler.Initialize(); } OffloadStartNextRequest(); }