Ejemplo n.º 1
0
 public LogDashboardContext(HttpContext httpContext, LogDashboardRoute route, LogDashboardOptions options)
 {
     StaticOptions = options;
     Route         = route ?? throw new ArgumentNullException(nameof(route));
     HttpContext   = httpContext ?? throw new ArgumentNullException(nameof(httpContext));
     Options       = options;
 }
Ejemplo n.º 2
0
 public LogDashboardContext(IOwinContext httpContext, LogDashboardRoute route, IRazorLightEngine engine, LogDashboardOptions options)
 {
     StaticOptions = options;
     Route         = route ?? throw new ArgumentNullException(nameof(route));
     HttpContext   = httpContext ?? throw new ArgumentNullException(nameof(httpContext));
     Engine        = engine ?? throw new ArgumentNullException(nameof(engine));
     Options       = options;
 }
Ejemplo n.º 3
0
        private static void RegisterHandle(IServiceCollection services, LogDashboardOptions opts)
        {
            var handles = Assembly.GetAssembly(typeof(LogDashboardRoute)).GetTypes()
                          .Where(x => typeof(LogDashboardHandleBase).IsAssignableFrom(x) && x != typeof(LogDashboardHandleBase));

            foreach (var handle in handles)
            {
                services.AddTransient(handle.MakeGenericType(opts.LogModelType));
            }
        }
Ejemplo n.º 4
0
        private static void RegisterServices(IServiceCollection services, Action <LogDashboardOptions> func = null, Assembly currentAssembly = null)
        {
            // razor
            var razorBuilder = new RazorLightEngineBuilder();

            if (currentAssembly != null)
            {
                razorBuilder = razorBuilder.SetOperatingAssembly(currentAssembly);
            }

            services.AddSingleton <IRazorLightEngine>(razorBuilder
                                                      .UseEmbeddedResourcesProject(typeof(LogDashboardMiddleware))
                                                      .UseMemoryCachingProvider()
                                                      .Build());

            services.AddSingleton(typeof(ILogDashboardCacheManager <>), typeof(InMemoryLogDashboardCacheManager <>));

            // options
            var options = new LogDashboardOptions();

            func?.Invoke(options);

            services.AddSingleton(options);

            if (options.DatabaseSource)
            {
                DapperExtensions.DapperAsyncExtensions.DefaultMapper = typeof(LogModelMapper <>);
                DapperExtensions.DapperExtensions.DefaultMapper      = typeof(LogModelMapper <>);

                if (string.IsNullOrWhiteSpace(options.ConnectionString))
                {
                    throw new ArgumentNullException(nameof(options.ConnectionString));
                }

                services.AddTransient(provider => new SqlConnection(options.ConnectionString));

                services.AddTransient(typeof(IRepository <>), typeof(DapperRepository <>));

                services.AddScoped <IUnitOfWork, DapperUnitOfWork>();
            }
            else
            {
                services.AddTransient(typeof(IRepository <>), typeof(FileRepository <>));;

                services.AddScoped(typeof(IUnitOfWork), typeof(FileUnitOfWork <>).MakeGenericType(options.LogModelType));
            }


            //register Handle
            RegisterHandle(services, options);
        }
        private static void RegisterServices(IServiceCollection services, Action <LogDashboardOptions> func = null, Assembly currentAssembly = null)
        {
            services.AddSingleton(typeof(ILogDashboardCacheManager <>), typeof(InMemoryLogDashboardCacheManager <>));

            // options
            var options = new LogDashboardOptions();

            func?.Invoke(options);

            services.AddSingleton(options);

            if (options.DatabaseSource)
            {
                DapperExtensions.DapperAsyncExtensions.DefaultMapper = typeof(LogModelMapper <>);
                DapperExtensions.DapperExtensions.DefaultMapper      = typeof(LogModelMapper <>);
                DapperExtensions.DapperAsyncExtensions.SqlDialect    = options.SqlDialect;
                DapperExtensions.DapperExtensions.SqlDialect         = options.SqlDialect;

                if (options.DbConnectionFactory == null)
                {
                    throw new ArgumentNullException(nameof(options.DbConnectionFactory));
                }

                services.AddTransient(typeof(DbConnection), provider => options.DbConnectionFactory.Invoke());

                services.AddTransient(typeof(IRepository <>), typeof(DapperRepository <>));

                services.AddScoped <IUnitOfWork, DapperUnitOfWork>();
            }
            else
            {
                services.AddTransient(typeof(IRepository <>), typeof(FileRepository <>));;

                services.AddScoped(typeof(IUnitOfWork), typeof(FileUnitOfWork <>).MakeGenericType(options.LogModelType));
            }


            //register Handle
            RegisterHandle(services, options);

            //register Views
            RegisterViews(services);
        }
Ejemplo n.º 6
0
        public static ILogDashboardBuilder AddLogDashboard(this IServiceCollection services, Action <LogDashboardOptions> func = null)
        {
            var builder = new DefaultLogDashboardBuilder(services);

            services.AddSingleton <IRazorLightEngine>(new RazorLightEngineBuilder()
                                                      .UseEmbeddedResourcesProject(typeof(LogDashboardMiddleware))
                                                      .UseMemoryCachingProvider()
                                                      .Build());

            var options = new LogDashboardOptions();

            func?.Invoke(options);

            services.AddSingleton(options);

            if (options.DatabaseSource)
            {
                DapperExtensions.DapperExtensions.DefaultMapper = typeof(LogModelMapper <>);

                if (string.IsNullOrWhiteSpace(options.ConnectionString))
                {
                    throw new ArgumentNullException("ConnectionString Cannot be Null");
                }

                services.AddTransient(provider => new SqlConnection(options.ConnectionString));

                builder.Services.AddTransient(typeof(IRepository <>), typeof(DapperRepository <>));

                builder.Services.AddScoped <IUnitOfWork, DapperUnitOfWork>();
            }
            else
            {
                builder.Services.AddTransient(typeof(IRepository <>), typeof(FileRepository <>));;

                builder.Services.AddScoped(typeof(IUnitOfWork), typeof(FileUnitOfWork <>).MakeGenericType(options.LogModelType));
            }


            RegisterHandle(services, options);

            return(builder);
        }