Ejemplo n.º 1
0
 public void ConfigureWebHost(IWebModule module, IHostBuilder builder, IEnumerable <IWebModuleWebHostBuilderFilter> filters)
 {
     builder.ConfigureWebHost(webHostBuilder =>
     {
         Filters.BuildFilterPipeline(filters, (_, __) => { })(module, webHostBuilder);
     });
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers an instance of a web module. Only 1 instance per type is allowed.
        /// </summary>
        /// <param name="module">The module.</param>
        public void RegisterModule(IWebModule module)
        {
            if (module == null)
            {
                return;
            }
            var existingModule = Module(module.GetType());

            if (existingModule == null)
            {
                module.Server = this;
                _modules.Add(module);

                var webModule = module as ISessionWebModule;

                if (webModule != null)
                {
                    SessionModule = webModule;
                }
            }
            else
            {
                Log.WarnFormat("Failed to register module '{0}' because a module with the same type already exists.",
                               module.GetType());
            }
        }
Ejemplo n.º 3
0
 private static Map GetHandlerFromPath(HttpListenerContext context, IWebModule module)
 => module.Handlers.FirstOrDefault(x =>
                                   string.Equals(
                                       x.Path,
                                       x.Path == ModuleMap.AnyPath ? ModuleMap.AnyPath : context.RequestPath(),
                                       StringComparison.OrdinalIgnoreCase) &&
                                   x.Verb == (x.Verb == HttpVerbs.Any ? HttpVerbs.Any : context.RequestVerb()));
Ejemplo n.º 4
0
        private Map GetHandlerFromWildcardPath(IWebModule module)
        {
            var path = _context.RequestWilcardPath(module.Handlers
                                                   .Where(k => k.Path.Contains(ModuleMap.AnyPathRoute))
                                                   .Select(s => s.Path.ToLowerInvariant()));

            return(module.Handlers
                   .FirstOrDefault(x =>
                                   (x.Path == ModuleMap.AnyPath || x.Path == path) &&
                                   (x.Verb == HttpVerbs.Any || x.Verb == _context.RequestVerb())));
        }
Ejemplo n.º 5
0
        private static Map GetHandlerFromWildcardPath(HttpListenerContext context, IWebModule module)
        {
            var path = context.RequestWilcardPath(module.Handlers
                                                  .Where(k => k.Path.Contains("/" + ModuleMap.AnyPath))
                                                  .Select(s => s.Path.ToLowerInvariant())
                                                  .ToArray());

            return(module.Handlers.FirstOrDefault(x =>
                                                  (x.Path == ModuleMap.AnyPath || x.Path == path) &&
                                                  (x.Verb == HttpVerbs.Any || x.Verb == context.RequestVerb())));
        }
Ejemplo n.º 6
0
        public void controllers_are_registered()
        {
            // set-up
            IWebModule webModule = A.Fake <IWebModule>();
            IEnumerable <IWebModule> webModules = new[] { webModule };

            // call
            _webModule.OnStart(_httpConfiguration, _containerBuilder, webModules);

            // assert
            _containerBuilder.Build().IsRegistered <IEntityController>().MustBeTrue();
        }
        private IWebModule CreateFolderModule(string location, string baseRoute, string missingFolderErrorMessage)
        {
            IWebModule module = null;

            if (!Directory.Exists(location))
            {
                _logger.Log(missingFolderErrorMessage, LogLevel.Warning);
                module = new ActionModule(baseRoute, HttpVerbs.Any, c =>
                {
                    c.Response.StatusCode = 500;
                    return(c.SendStringAsync(missingFolderErrorMessage, "text", Encoding.UTF8));
                });
            }

            return(module ?? new FileModule(baseRoute, new FileSystemProvider(location, false)).WithDirectoryLister(DirectoryLister.Html));
        }
Ejemplo n.º 8
0
        private Map GetHandler(HttpListenerContext context, IWebModule module)
        {
            switch (RoutingStrategy)
            {
            case RoutingStrategy.Wildcard:
                return(GetHandlerFromWildcardPath(context, module));

            case RoutingStrategy.Regex:
                return(GetHandlerFromRegexPath(context, module));

            case RoutingStrategy.Simple:
                return(GetHandlerFromPath(context, module));

            default:
                throw new ArgumentOutOfRangeException(nameof(RoutingStrategy));
            }
        }
Ejemplo n.º 9
0
        private WebHandler GetHandler(IWebModule module)
        {
            Map handler;

            switch (_context.WebServer.RoutingStrategy)
            {
            case RoutingStrategy.Wildcard:
                handler = GetHandlerFromWildcardPath(module);
                break;

            case RoutingStrategy.Regex:
                handler = GetHandlerFromRegexPath(module);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(RoutingStrategy));
            }

            return(handler?.ResponseHandler);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Registers an instance of a web module. Only 1 instance per type is allowed.
        /// </summary>
        /// <param name="module">The module.</param>
        public void RegisterModule(IWebModule module)
        {
            if (module == null)
            {
                return;
            }
            var existingModule = Module(module.GetType());

            if (existingModule == null)
            {
                module.Server = this;
                _modules.Add(module);

                if (module is ISessionWebModule webModule)
                {
                    SessionModule = webModule;
                }
            }
            else
            {
                $"Failed to register module '{module.GetType()}' because a module with the same type already exists.".Warn(nameof(WebServer));
            }
        }
Ejemplo n.º 11
0
        private Func <IHttpContext, CancellationToken, Task <bool> > GetHandler(IWebModule module)
        {
            Map handler;

            switch (_context.WebServer.RoutingStrategy)
            {
            case RoutingStrategy.Wildcard:
                handler = GetHandlerFromWildcardPath(module);
                break;

            case RoutingStrategy.Regex:
                handler = GetHandlerFromRegexPath(module);
                break;

            case RoutingStrategy.Simple:
                handler = GetHandlerFromPath(module);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(RoutingStrategy));
            }

            return(handler?.ResponseHandler);
        }
Ejemplo n.º 12
0
 private Map GetHandlerFromRegexPath(IWebModule module)
 => module.Handlers.FirstOrDefault(x =>
                                   (x.Path == ModuleMap.AnyPath || _context.RequestRegexUrlParams(x.Path) != null) &&
                                   (x.Verb == HttpVerbs.Any || x.Verb == _context.RequestVerb()));
Ejemplo n.º 13
0
 /// <summary>
 /// <para>Gets the underlying <see cref="IWebModuleImpl"/> interface of an <see cref="IWebModule"/>.</para>
 /// <para>This API mainly supports the EmbedIO infrastructure; it is not intended to be used directly from your code,
 /// unless to fulfill very specific needs in the development of plug-ins (modules, etc.) for EmbedIO.</para>
 /// </summary>
 /// <param name="this">The <see cref="IWebModule"/> interface on which this method is called.</param>
 /// <returns>The underlying <see cref="IWebModuleImpl"/> interface representing
 /// the web module implementation.</returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="this"/> is <see langword="null"/>.
 /// </exception>
 /// <exception cref="InternalErrorException">
 /// <paramref name="this"/> does not implement <see cref="IWebModuleImpl"/>.
 /// </exception>
 public static IWebModuleImpl GetImplementation(this IWebModule @this)
 => Validate.NotNull(nameof(@this), @this) as IWebModuleImpl
 ?? throw SelfCheck.Failure($"{@this.GetType().FullName} does not implement {nameof(IWebModuleImpl)}.");
 public static void Populate(this IAutofacDependencyInjectionContainerBuilder self, IWebModule webModule)
 {
     self.Builder.Populate(webModule);
 }
Ejemplo n.º 15
0
 public IWebHostBuilder CreateWebHost(IWebModule module) => _creatorFunc();
Ejemplo n.º 16
0
 private static Map GetHandlerFromRegexPath(HttpListenerContext context, IWebModule module)
 {
     return(module.Handlers.FirstOrDefault(x =>
                                           (x.Path == ModuleMap.AnyPath || context.RequestRegexUrlParams(x.Path) != null) &&
                                           (x.Verb == HttpVerbs.Any || x.Verb == context.RequestVerb())));
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Adds the specified <paramref name="module"/> to a module container, without giving it a name.
 /// </summary>
 /// <typeparam name="TContainer">The type of the module container.</typeparam>
 /// <param name="this">The <typeparamref name="TContainer"/> on which this method is called.</param>
 /// <param name="module">The module.</param>
 /// <returns><paramref name="this"/> with <paramref name="module"/> added.</returns>
 /// <exception cref="NullReferenceException"><paramref name="this"/> is <see langword="null"/>.</exception>
 /// <seealso cref="IWebModuleContainer.Modules"/>
 /// <seealso cref="IComponentCollection{T}.Add"/>
 public static TContainer WithModule <TContainer>(this TContainer @this, IWebModule module)
     where TContainer : class, IWebModuleContainer
 => WithModule(@this, null, module);
Ejemplo n.º 18
0
 public void RegisterModule(IWebModule module) => _modules.RegisterModule(module, this);
Ejemplo n.º 19
0
 /// <summary>
 /// Adds the specified <paramref name="module"/> to a module container,
 /// giving it the specified <paramref name="name"/> if not <see langword="null"/>.
 /// </summary>
 /// <typeparam name="TContainer">The type of the module container.</typeparam>
 /// <param name="this">The <typeparamref name="TContainer"/> on which this method is called.</param>
 /// <param name="name">The name.</param>
 /// <param name="module">The module.</param>
 /// <returns><paramref name="this"/> with <paramref name="module"/> added.</returns>
 /// <exception cref="NullReferenceException"><paramref name="this"/> is <see langword="null"/>.</exception>
 /// <seealso cref="IWebModuleContainer.Modules"/>
 /// <seealso cref="IComponentCollection{T}.Add"/>
 public static TContainer WithModule <TContainer>(this TContainer @this, string?name, IWebModule module)
     where TContainer : class, IWebModuleContainer
 {
     @this.Modules.Add(name, module);
     return(@this);
 }