优化结构
This commit is contained in:
parent
17e36f5a56
commit
17df6af4f0
@ -7,19 +7,17 @@ using System.Reflection;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Application;
|
using Volo.Abp.Application;
|
||||||
|
using Volo.Abp.AspNetCore.Mvc;
|
||||||
using Volo.Abp.AutoMapper;
|
using Volo.Abp.AutoMapper;
|
||||||
using Volo.Abp.BackgroundWorkers;
|
|
||||||
using Volo.Abp.BackgroundWorkers.Hangfire;
|
|
||||||
using Volo.Abp.Modularity;
|
using Volo.Abp.Modularity;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.Migration;
|
namespace JiShe.CollectBus.Migration;
|
||||||
|
|
||||||
[DependsOn(
|
[DependsOn(
|
||||||
typeof(CollectBusDomainModule),
|
typeof(CollectBusDomainModule),
|
||||||
typeof(CollectBusMigrationApplicationContractsModule),
|
typeof(CollectBusMigrationApplicationContractsModule),
|
||||||
typeof(AbpDddApplicationModule),
|
typeof(AbpDddApplicationModule),
|
||||||
typeof(AbpAutoMapperModule),
|
typeof(AbpAutoMapperModule),
|
||||||
typeof(AbpBackgroundWorkersHangfireModule),
|
|
||||||
typeof(CollectBusFreeRedisModule),
|
typeof(CollectBusFreeRedisModule),
|
||||||
typeof(CollectBusFreeSqlModule),
|
typeof(CollectBusFreeSqlModule),
|
||||||
typeof(CollectBusIoTDbModule)
|
typeof(CollectBusIoTDbModule)
|
||||||
@ -38,10 +36,10 @@ public class CollectBusMigrationApplicationModule : AbpModule
|
|||||||
public override async Task OnApplicationInitializationAsync(
|
public override async Task OnApplicationInitializationAsync(
|
||||||
ApplicationInitializationContext context)
|
ApplicationInitializationContext context)
|
||||||
{
|
{
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
//var assembly = Assembly.GetExecutingAssembly();
|
||||||
var types = assembly.GetTypes().Where(t => typeof(ICollectWorker).IsAssignableFrom(t) && !t.IsInterface)
|
//var types = assembly.GetTypes().Where(t => typeof(ICollectWorker).IsAssignableFrom(t) && !t.IsInterface)
|
||||||
.ToList();
|
// .ToList();
|
||||||
foreach (var type in types) await context.AddBackgroundWorkerAsync(type);
|
//foreach (var type in types) await context.AddBackgroundWorkerAsync(type);
|
||||||
|
|
||||||
//Task.Run(() =>
|
//Task.Run(() =>
|
||||||
//{
|
//{
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
|
||||||
|
namespace JiShe.CollectBus;
|
||||||
|
|
||||||
|
public class CollectBusMigrationlicationAutoMapperProfile : Profile
|
||||||
|
{
|
||||||
|
public CollectBusMigrationlicationAutoMapperProfile()
|
||||||
|
{
|
||||||
|
/* You can configure your AutoMapper mapping configuration here.
|
||||||
|
* Alternatively, you can split your mapping configurations
|
||||||
|
* into multiple profile classes for a better organization. */
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,11 @@
|
|||||||
using Hangfire;
|
//using Hangfire;
|
||||||
using Hangfire.Redis.StackExchange;
|
//using Hangfire.Redis.StackExchange;
|
||||||
using JiShe.CollectBus.Migration.Host.Hangfire;
|
using JiShe.CollectBus.Migration.Host.Hangfire;
|
||||||
|
using JiShe.CollectBus.Migration.Host.HealthChecks;
|
||||||
using JiShe.CollectBus.Migration.Host.Swaggers;
|
using JiShe.CollectBus.Migration.Host.Swaggers;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
@ -23,28 +25,28 @@ namespace JiShe.CollectBus.Migration.Host
|
|||||||
/// Configures the hangfire.
|
/// Configures the hangfire.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context">The context.</param>
|
/// <param name="context">The context.</param>
|
||||||
private void ConfigureHangfire(ServiceConfigurationContext context)
|
//private void ConfigureHangfire(ServiceConfigurationContext context)
|
||||||
{
|
//{
|
||||||
var redisStorageOptions = new RedisStorageOptions()
|
// var redisStorageOptions = new RedisStorageOptions()
|
||||||
{
|
// {
|
||||||
Db = context.Services.GetConfiguration().GetValue<int>("Redis:HangfireDB")
|
// Db = context.Services.GetConfiguration().GetValue<int>("Redis:HangfireDB")
|
||||||
};
|
// };
|
||||||
|
|
||||||
Configure<AbpBackgroundJobOptions>(options => { options.IsJobExecutionEnabled = false; });
|
// Configure<AbpBackgroundJobOptions>(options => { options.IsJobExecutionEnabled = false; });
|
||||||
|
|
||||||
context.Services.AddHangfire(config =>
|
// context.Services.AddHangfire(config =>
|
||||||
{
|
// {
|
||||||
config.UseRedisStorage(
|
// config.UseRedisStorage(
|
||||||
context.Services.GetConfiguration().GetValue<string>("Redis:Configuration"), redisStorageOptions)
|
// context.Services.GetConfiguration().GetValue<string>("Redis:Configuration"), redisStorageOptions)
|
||||||
.WithJobExpirationTimeout(TimeSpan.FromDays(7));
|
// .WithJobExpirationTimeout(TimeSpan.FromDays(7));
|
||||||
var delaysInSeconds = new[] { 10, 60, 60 * 3 }; // 重试时间间隔
|
// var delaysInSeconds = new[] { 10, 60, 60 * 3 }; // 重试时间间隔
|
||||||
const int Attempts = 3; // 重试次数
|
// const int Attempts = 3; // 重试次数
|
||||||
config.UseFilter(new AutomaticRetryAttribute() { Attempts = Attempts, DelaysInSeconds = delaysInSeconds });
|
// config.UseFilter(new AutomaticRetryAttribute() { Attempts = Attempts, DelaysInSeconds = delaysInSeconds });
|
||||||
//config.UseFilter(new AutoDeleteAfterSuccessAttribute(TimeSpan.FromDays(7)));
|
// //config.UseFilter(new AutoDeleteAfterSuccessAttribute(TimeSpan.FromDays(7)));
|
||||||
config.UseFilter(new JobRetryLastFilter(Attempts));
|
// config.UseFilter(new JobRetryLastFilter(Attempts));
|
||||||
});
|
// });
|
||||||
context.Services.AddHangfireServer();
|
// context.Services.AddHangfireServer();
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configures the JWT authentication.
|
/// Configures the JWT authentication.
|
||||||
@ -179,7 +181,7 @@ namespace JiShe.CollectBus.Migration.Host
|
|||||||
{
|
{
|
||||||
options.IsEnabled = true;
|
options.IsEnabled = true;
|
||||||
options.EntityHistorySelectors.AddAllEntities();
|
options.EntityHistorySelectors.AddAllEntities();
|
||||||
options.ApplicationName = "JiShe.CollectBus";
|
options.ApplicationName = "JiShe.CollectBus.Migration";
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -245,27 +247,18 @@ namespace JiShe.CollectBus.Migration.Host
|
|||||||
/// <param name="configuration"></param>
|
/// <param name="configuration"></param>
|
||||||
private void ConfigureHealthChecks(ServiceConfigurationContext context, IConfiguration configuration)
|
private void ConfigureHealthChecks(ServiceConfigurationContext context, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
//if (!configuration.GetValue<bool>("HealthChecks:IsEnable")) return;
|
if (!configuration.GetValue<bool>("HealthChecks:IsEnable")) return;
|
||||||
//var cassandraConfig = new CassandraConfig();
|
context.Services.AddHealthChecks()
|
||||||
//configuration.GetSection("Cassandra").Bind(cassandraConfig);
|
.AddRedis(configuration.GetValue<string>("Redis:Configuration") ?? string.Empty, "Redis",
|
||||||
//context.Services.AddHealthChecks()
|
HealthStatus.Unhealthy)
|
||||||
// .AddMongoDb(configuration.GetConnectionString("Default"), "MongoDB", HealthStatus.Unhealthy)
|
.AddCheck<IoTdbHealthCheck>("IoTDB");
|
||||||
// .AddRedis(configuration.GetValue<string>("Redis:Configuration") ?? string.Empty, "Redis",
|
|
||||||
// HealthStatus.Unhealthy)
|
|
||||||
// .AddKafka(new Confluent.Kafka.ProducerConfig
|
|
||||||
// {
|
|
||||||
// BootstrapServers = configuration.GetValue<string>("Kafka:BootstrapServers")
|
|
||||||
// }, "Kafka", failureStatus: HealthStatus.Unhealthy)
|
|
||||||
|
|
||||||
// //.AddCheck<CassandraHealthCheck>("Cassandra")
|
context.Services
|
||||||
// .AddCheck<IoTdbHealthCheck>("IoTDB");
|
.AddHealthChecksUI(options =>
|
||||||
|
{
|
||||||
//context.Services
|
options.AddHealthCheckEndpoint("JiSheCollectBusMigration", "/health"); // 映射本地端点
|
||||||
// .AddHealthChecksUI(options =>
|
})
|
||||||
// {
|
.AddInMemoryStorage();
|
||||||
// options.AddHealthCheckEndpoint("JiSheCollectBus", "/health"); // 映射本地端点
|
|
||||||
// })
|
|
||||||
// .AddInMemoryStorage();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -5,6 +5,7 @@ using JiShe.CollectBus.Migration.Host.Swaggers;
|
|||||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||||
using Swashbuckle.AspNetCore.SwaggerUI;
|
using Swashbuckle.AspNetCore.SwaggerUI;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
|
using Volo.Abp.AspNetCore;
|
||||||
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
|
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
|
||||||
using Volo.Abp.AspNetCore.Serilog;
|
using Volo.Abp.AspNetCore.Serilog;
|
||||||
using Volo.Abp.Autofac;
|
using Volo.Abp.Autofac;
|
||||||
@ -26,8 +27,7 @@ namespace JiShe.CollectBus.Migration.Host
|
|||||||
typeof(AbpSwashbuckleModule),
|
typeof(AbpSwashbuckleModule),
|
||||||
typeof(AbpTimingModule),
|
typeof(AbpTimingModule),
|
||||||
typeof(CollectBusMigrationApplicationModule),
|
typeof(CollectBusMigrationApplicationModule),
|
||||||
typeof(AbpCachingStackExchangeRedisModule),
|
typeof(AbpCachingStackExchangeRedisModule)
|
||||||
typeof(AbpBackgroundWorkersHangfireModule)
|
|
||||||
)]
|
)]
|
||||||
public partial class CollectBusMigrationHostModule : AbpModule
|
public partial class CollectBusMigrationHostModule : AbpModule
|
||||||
{
|
{
|
||||||
@ -40,12 +40,12 @@ namespace JiShe.CollectBus.Migration.Host
|
|||||||
var configuration = context.Services.GetConfiguration();
|
var configuration = context.Services.GetConfiguration();
|
||||||
ConfigureCache(context);
|
ConfigureCache(context);
|
||||||
ConfigureSwaggerServices(context, configuration);
|
ConfigureSwaggerServices(context, configuration);
|
||||||
ConfigureNetwork(context, configuration);
|
//ConfigureNetwork(context, configuration);
|
||||||
ConfigureJwtAuthentication(context, configuration);
|
ConfigureJwtAuthentication(context, configuration);
|
||||||
ConfigureHangfire(context);
|
//ConfigureHangfire(context);
|
||||||
ConfigureAuditLog(context);
|
ConfigureAuditLog(context);
|
||||||
ConfigureCustom(context, configuration);
|
ConfigureCustom(context, configuration);
|
||||||
//ConfigureHealthChecks(context, configuration);
|
ConfigureHealthChecks(context, configuration);
|
||||||
Configure<AbpClockOptions>(options => { options.Kind = DateTimeKind.Local; });
|
Configure<AbpClockOptions>(options => { options.Kind = DateTimeKind.Local; });
|
||||||
|
|
||||||
Configure<ServerApplicationOptions>(options =>
|
Configure<ServerApplicationOptions>(options =>
|
||||||
@ -84,13 +84,13 @@ namespace JiShe.CollectBus.Migration.Host
|
|||||||
options.DefaultModelsExpandDepth(-1);
|
options.DefaultModelsExpandDepth(-1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
app.UseAuditing();
|
//app.UseAuditing();
|
||||||
app.UseAbpSerilogEnrichers();
|
app.UseAbpSerilogEnrichers();
|
||||||
app.UseUnitOfWork();
|
app.UseUnitOfWork();
|
||||||
app.UseHangfireDashboard("/hangfire", new DashboardOptions
|
//app.UseHangfireDashboard("/hangfire", new DashboardOptions
|
||||||
{
|
//{
|
||||||
IgnoreAntiforgeryToken = true
|
// IgnoreAntiforgeryToken = true
|
||||||
});
|
//});
|
||||||
app.UseConfiguredEndpoints(endpoints =>
|
app.UseConfiguredEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
if (!configuration.GetValue<bool>("HealthChecks:IsEnable")) return;
|
if (!configuration.GetValue<bool>("HealthChecks:IsEnable")) return;
|
||||||
@ -27,7 +27,7 @@
|
|||||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
|
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="9.0.0" />
|
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="9.0.0" />
|
||||||
|
|
||||||
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.9.4" />
|
<!--<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.9.4" />-->
|
||||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="9.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="9.0.0" />
|
||||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||||
@ -43,7 +43,7 @@
|
|||||||
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="8.3.3" />
|
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="8.3.3" />
|
||||||
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="8.3.3" />
|
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="8.3.3" />
|
||||||
<PackageReference Include="Volo.Abp.Autofac" Version="8.3.3" />
|
<PackageReference Include="Volo.Abp.Autofac" Version="8.3.3" />
|
||||||
<PackageReference Include="Volo.Abp.BackgroundWorkers.Hangfire" Version="8.3.3" />
|
<!--<PackageReference Include="Volo.Abp.BackgroundWorkers.Hangfire" Version="8.3.3" />-->
|
||||||
|
|
||||||
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="8.3.3" />
|
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="8.3.3" />
|
||||||
<PackageReference Include="Volo.Abp.Swashbuckle" Version="8.3.3" />
|
<PackageReference Include="Volo.Abp.Swashbuckle" Version="8.3.3" />
|
||||||
|
|||||||
@ -16,6 +16,18 @@ public class Program
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task Main(string[] args)
|
public static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
|
//var builder = WebApplication.CreateBuilder(args);
|
||||||
|
//builder.Host
|
||||||
|
// .UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
// .UseSerilog((context, loggerConfiguration) =>
|
||||||
|
// {
|
||||||
|
// loggerConfiguration.ReadFrom.Configuration(context.Configuration);
|
||||||
|
// })
|
||||||
|
// .UseAutofac();
|
||||||
|
//var app = builder.Build();
|
||||||
|
//await app.InitializeApplicationAsync();
|
||||||
|
//await app.RunAsync();
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.Host.UseContentRoot(Directory.GetCurrentDirectory())
|
builder.Host.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
.UseSerilog((context, loggerConfiguration) =>
|
.UseSerilog((context, loggerConfiguration) =>
|
||||||
@ -24,6 +36,10 @@ public class Program
|
|||||||
})
|
})
|
||||||
.UseAutofac();
|
.UseAutofac();
|
||||||
var configuration = builder.Configuration;
|
var configuration = builder.Configuration;
|
||||||
|
await builder.AddApplicationAsync<CollectBusMigrationHostModule>(options =>
|
||||||
|
{
|
||||||
|
//options.PlugInSources.AddFolder((configuration["PlugInFolder"].IsNullOrWhiteSpace() ? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins") : configuration["PlugInFolder"]) ?? string.Empty);
|
||||||
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
await app.InitializeApplicationAsync();
|
await app.InitializeApplicationAsync();
|
||||||
await app.RunAsync();
|
await app.RunAsync();
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"JiShe.CollectBus.Host": {
|
"JiShe.CollectBus.Migration.Host": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"applicationUrl": "http://localhost:44316",
|
"applicationUrl": "http://localhost:44316",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user