示例#1
0
        public static IServiceCollection AddAiursoftSDK(this IServiceCollection services,
                                                        Assembly assembly = null,
                                                        params Type[] abstracts)
        {
            services.AddHttpClient();
            services.AddMemoryCache();
            var abstractsArray = abstracts
                                 .AddWith(typeof(IHostedService))
                                 .AddWith(typeof(ISeeder))
                                 .ToArray();

            if (EntryExtends.IsProgramEntry())
            {
                // Program is starting itself.
                services.AddScannedDependencies(abstractsArray);
            }
            else if (assembly != null)
            {
                // Program is started in UT or EF. Method called from extension.
                services.AddAssemblyDependencies(assembly, abstractsArray);
            }
            else
            {
                // Program is started in UT or EF. Method called from web project.
                services.AddAssemblyDependencies(Assembly.GetCallingAssembly(), abstractsArray);
            }
            return(services);
        }
示例#2
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     if (_env.IsDevelopment() || !EntryExtends.IsProgramEntry())
     {
         _logger.LogInformation("Skip cleaner in development environment.");
         return(Task.CompletedTask);
     }
     _logger.LogInformation("Timed Background Service is starting.");
     _timer = new Timer(DoWork, null, TimeSpan.FromSeconds(30), TimeSpan.FromMinutes(15));
     return(Task.CompletedTask);
 }
示例#3
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     if (_env.IsDevelopment() || !EntryExtends.IsProgramEntry())
     {
         _logger.LogInformation("Skip cleaner in development environment.");
         return(Task.CompletedTask);
     }
     _logger.LogInformation("Timed Background Service is starting.");
     // Start cleaner after one day.
     // Because when stargate starts, all channels are treated dead.
     _timer = new Timer(DoWork, null, TimeSpan.FromDays(1), TimeSpan.FromMinutes(10));
     return(Task.CompletedTask);
 }
示例#4
0
 public static IApplicationBuilder UseAiurAPIHandler(this IApplicationBuilder app, bool isDevelopment)
 {
     if (isDevelopment || !EntryExtends.IsProgramEntry())
     {
         app.UseDeveloperExceptionPage();
     }
     else
     {
         app.UseMiddleware <HandleRobotsMiddleware>();
         app.UseForwardedHeaders(new ForwardedHeadersOptions
         {
             ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
         });
         app.UseMiddleware <EnforceHttpsMiddleware>();
         app.UseMiddleware <APIFriendlyServerExceptionMiddleware>();
     }
     return(app);
 }
示例#5
0
        public static IServiceCollection AddAiursoftSDK(this IServiceCollection services,
                                                        Assembly assembly = null,
                                                        params Type[] abstracts)
        {
            services.AddHttpClient();
            services.AddMemoryCache();
            var abstractsArray = abstracts.AddWith(typeof(IHostedService)).ToArray();

            if (EntryExtends.IsProgramEntry())
            {
                services.AddScannedDependencies(abstractsArray);
            }
            else if (assembly != null)
            {
                services.AddAssemblyDependencies(assembly, abstractsArray);
            }
            else
            {
                services.AddAssemblyDependencies(Assembly.GetCallingAssembly(), abstractsArray);
            }
            return(services);
        }