Beispiel #1
0
        public static ILogDashboardBuilder AddLogDashboard(this IServiceCollection services, Action <LogDashboardOptions> func = null)
        {
            var builder = new DefaultLogDashboardBuilder(services);

            RegisterServices(services, func);

            return(builder);
        }
Beispiel #2
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);
        }
        public static IDispatchBuilder AddDispatch(this IServiceCollection services, 
            Action<DispatchOptions> func = null)
        {
            var builder = new DefaultLogDashboardBuilder()
            {
                Services = services,
                DispatchOptions = new DispatchOptions()
            };
            func?.Invoke(builder.DispatchOptions);
            //RegisterServices(services, func);
            //var builder = new QuartzOptionsBuilder
            //{
            //    Services = services,
            //    Properties = new NameValueCollection { { "quartz.jobStore.useProperties", "true" } }
            //};
            //func.

            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            //if (func == null)
            //{
            //    throw new ArgumentNullException(nameof(func));
            //}


            

            services.Configure(func);

            //加载默认html页
            



            //services.AddTransient<Jobs.HttpJob>();
            services.AddSingleton<ISchedulerService, SchedulerService>();
            services.AddSingleton<IHttpService, HttpClientService>();
            services.AddSingleton<IJobFactory, JobFactory>();


            
            services.AddSingleton<ISchedulerFactory>(provider => new StdSchedulerFactory(UseSqlite()));
            //func = func ?? ((o) => {

            if(builder.DispatchOptions.IsStaticFile)
                services.ConfigureOptions(typeof(UIConfigureOptions));


            if (builder.DispatchOptions.ListDll != null && builder.DispatchOptions.ListDll.Count > 0)
            {
                foreach (var item in builder.DispatchOptions.ListDll)
                {
                    //Assembly asm1 = Assembly.LoadFile(fileName1);
                    IocJob(services, Assembly.Load(item));//
                }
            }
            var asmlWooDispatch = Assembly.GetExecutingAssembly();
            IocJob(services, asmlWooDispatch);//

            var asmlThat = Assembly.GetEntryAssembly();
            IocJob(services, asmlThat);//
            //});
            //if (func == null) RDisOps(services, new DispatchOptions());
            //else
            //{
            //    func((o)=> { })
            //    RDisOps(services, new DispatchOptions());
            //}
            //if (IsStaticFile)
            //    services.ConfigureOptions(typeof(UIConfigureOptions));


            return builder;
        }