Esempio n. 1
0
        private async void Process(HttpListenerContext context)
        {
            try
            {
                var actions = HandleRequest?.GetInvocationList().Cast <Func <HttpListenerContext, bool> >();
                if (actions is object)
                {
                    foreach (var action in actions)
                    {
                        if (action.Invoke(context))
                        {
                            return;
                        }
                    }
                }

                await context.SetResponseTextAsync(null, null, 404).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                try
                {
                    Console.WriteLine(ex);
                    await context.SetResponseTextAsync(ex.ToString(), statusCode : 500).ConfigureAwait(false);
                }
                catch
                {
                }
            }
        }
Esempio n. 2
0
        internal bool Handler(HttpListenerContext context)
        {
            if (!context.Request.Url.AbsolutePath.StartsWith(_prefix))
            {
                return(false);
            }

            var uri = new UriBuilder(context.Request.Url)
            {
                Path = context.Request.Url.AbsolutePath.Substring(Prefix.Length)
            }.Uri;

            var actions = HandleRequest?.GetInvocationList().Cast <Func <HttpListenerContext, Uri, bool> >();

            if (actions is object)
            {
                foreach (var action in actions)
                {
                    if (action.Invoke(context, uri))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 3
0
        private bool LocalHandleRequest(ContextType context)
        {
            Delegate[] handlers = _handlers.GetInvocationList();

            for (int c1 = 0; c1 < handlers.Length; c1++)
            {
                if ((bool)handlers[c1].DynamicInvoke(new Object[] { context }))
                {
                    return(true);
                }
            }
            return(false);
        }