Beispiel #1
0
        public void DashPathMustStartWithSlash()
        {
            var options = new AutoPocoOptions
            {
                DashboardPath = "dash"
            };

            builder.UseAutoPoco(config, options);
        }
Beispiel #2
0
        public void DashPathMustBeMore1Char()
        {
            var options = new AutoPocoOptions
            {
                DashboardPath = "a"
            };

            builder.UseAutoPoco(config, options);
        }
Beispiel #3
0
        public void DashPathMustBeMore1Char()
        {
            var options = new AutoPocoOptions
            {
                DashboardPath = "a"
            };

            builder = c => c.UseAutoPoco(options);
            _       = new TestServer(hostBuilder);
        }
Beispiel #4
0
        public void DashPathMustStartWithSlash()
        {
            var options = new AutoPocoOptions
            {
                DashboardPath = "dash"
            };

            builder = c => c.UseAutoPoco(options);
            _       = new TestServer(hostBuilder);
        }
Beispiel #5
0
        public void UseDashboardSetsPathToDashPath()
        {
            var options = new AutoPocoOptions
            {
                DashboardPath = "/dashPath123"
            };

            builder.UseAutoPoco(config, options);
            Assert.AreEqual("dashPath123", AutoPocoConfiguration.DashboardPathPrefix);
        }
Beispiel #6
0
        public void UseDashboardSetsPathToDashPath()
        {
            var options = new AutoPocoOptions
            {
                DashboardPath = "/dashPath123"
            };

            builder = c => c.UseAutoPoco(options);
            _       = new TestServer(hostBuilder);
            Assert.AreEqual("dashPath123", AutoPocoConfiguration.DashboardPathPrefix);
        }
Beispiel #7
0
        /// <summary>
        /// Set up dashboard with a basic license
        /// </summary>
        /// <param name="builder">The builder being used to configure the context.</param>
        /// <param name="options">Dashboard setup options</param>
        /// <param name="config">Current Httpconfiguration</param>
        /// <returns>The options builder so that further configuration can be chained.</returns>

        public static IAppBuilder UseAutoPoco(this IAppBuilder builder, HttpConfiguration config, AutoPocoOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (options.DashboardPath.Length <= 1 || options.DashboardPath[0] != '/')
            {
                throw new ArgumentException(ExceptionMessages.MiddlewarePath, nameof(options));
            }

            //Set dashboard path prefix for api routes
            AutoPocoConfiguration.DashboardPathPrefix = options.DashboardPath.Trim('/');

            config.MapHttpAttributeRoutes();
            SwaggerConfig.Register(config, options.DashboardPath);

            //Common items
            config.EnableDependencyInjection();
            config.Count().Filter().OrderBy().Expand().Select().MaxTop(1000);


            builder.UseWithDependencyInjection <LoggingMiddleware.LogRequestAndResponseMiddleware>(config);

            if (options.UseDashboard)
            {
                builder.UseWithDependencyInjection <DashboardMiddleware>(config);
            }

            builder.UseWebApi(config);

            //Migrate and set up encrption
            var dbSetupService = config.DependencyResolver.GetRequiredService <IAppDatabaseSetupService>();

            if (!string.IsNullOrEmpty(options.SaltVector) || !string.IsNullOrEmpty(options.SecretKey))
            {
                dbSetupService.SetupEncryption(options.SaltVector, options.SecretKey, options.CacheTimeoutMinutes);
            }

            dbSetupService.Migrate();

            return(builder);
        }
Beispiel #8
0
        /// <summary>
        /// Default dashboard set up for with default settings
        /// </summary>
        /// <param name="builder">The builder being used to configure the context.</param>
        /// <param name="options">Dashboard setup options</param>
        /// <param name="descriptors">List of services to register with the AutoPocoIO IOC container.</param>
        /// <returns>The options builder so that further configuration can be chained.</returns>
        public static IAppBuilder UseAutoPoco(this IAppBuilder builder, AutoPocoOptions options, IEnumerable <ServiceDescriptor> descriptors)
        {
            HttpConfiguration config = builder.ConfigureIOCContainer(descriptors);

            return(builder.UseAutoPoco(config, options));
        }
Beispiel #9
0
        /// <summary>
        /// Set up the dashboard
        /// </summary>
        /// <param name="builder">The builder being used to configure the context.</param>
        /// <param name="options">Dashboard setup options</param>
        /// <returns>The options builder so that further configuration can be chained.</returns>

        public static IApplicationBuilder UseAutoPoco(this IApplicationBuilder builder, AutoPocoOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (options.DashboardPath.Length <= 1 || options.DashboardPath[0] != '/')
            {
                throw new ArgumentException(ExceptionMessages.MiddlewarePath, nameof(options));
            }

            //Set dashboard path prefix for api routes
            AutoPocoConfiguration.DashboardPathPrefix = options.DashboardPath.Trim('/');
            string dashPath = "/" + AutoPocoConfiguration.DashboardPathPrefix;

#if NETCORE2_2
            // builder.UseEndpointRouting();
#else
            builder.UseRouting();
#endif

            builder.UseSwagger(SwaggerConfig.SwaggerAppBuilderFunc(dashPath));
            builder.UseSwaggerUI(SwaggerConfig.SwaggerUIAppBuilderFunc(dashPath));

            //Log All Api Request
            builder.UseMiddleware <LogRequestAndResponseMiddleware>();



            //Map Dashboard routes
            if (options.UseDashboard)
            {
                builder.UseMiddlewareWhen <AspNetCoreDashboardMiddleware>(dashPath);
            }

            //Enable OData
#if NETCORE2_2
            builder.UseMvc(routeBuilder =>
            {
                routeBuilder.EnableDependencyInjection();
                routeBuilder.Count().Filter().OrderBy().Expand().Select().MaxTop(1000);
            });
#else
            builder.UseEndpoints(routeBuilder =>
            {
                routeBuilder.MapControllers();
                routeBuilder.EnableDependencyInjection();
                routeBuilder.Count().Filter().OrderBy().Expand().Select().MaxTop(1000);
            });
#endif

            var scopeFactory = builder.ApplicationServices.GetRequiredService <IServiceScopeFactory>();
            using (var scope = scopeFactory.CreateScope())
            {
                var provider       = scope.ServiceProvider;
                var dbSetupService = provider.GetRequiredService <IAppDatabaseSetupService>();

                if (!string.IsNullOrEmpty(options.SaltVector) || !string.IsNullOrEmpty(options.SecretKey))
                {
                    dbSetupService.SetupEncryption(options.SaltVector, options.SecretKey, options.CacheTimeoutMinutes);
                }

                dbSetupService.Migrate();
            }

            return(builder);
        }
Beispiel #10
0
        public void UseDashboardChecksForConfig()
        {
            var options = new AutoPocoOptions();

            builder.UseAutoPoco(null, options);
        }