Browse Source

dotnetcore.cap 添加基于内存

 es日志可选
 添加 UserDataSeedContributor
pull/10/head
王军 5 years ago
parent
commit
d2756a9b07
  1. 1
      aspnet-core/Directory.Build.props
  2. 7
      aspnet-core/frameworks/CAP/src/CompanyName.ProjectName.CAP/CompanyName.ProjectName.CAP.csproj
  3. 22
      aspnet-core/modules/QueryManagement/src/CompanyName.ProjectName.QueryManagement.Application/ElasticSearchs/LogAppService.cs
  4. 3
      aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/CompanyName.ProjectName.HttpApi.Host.csproj
  5. 16
      aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/Extensions/Filters/HiddenAbpDefaultApiFilter.cs
  6. 28
      aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs
  7. 11
      aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/appsettings.Development.json
  8. 36
      aspnet-core/services/src/CompanyName.ProjectName.Domain/Users/UserDataSeedContributor.cs
  9. 2
      vben271/.env.production
  10. 4
      vben271/_nginx/default.conf
  11. 11
      vben271/_nginx/nginx.conf

1
aspnet-core/Directory.Build.props

@ -2,6 +2,7 @@
<PropertyGroup>
<AbpPackageVersion>4.4.0</AbpPackageVersion>
<DotNetCoreCAP>5.1.4</DotNetCoreCAP>
</PropertyGroup>
</Project>

7
aspnet-core/frameworks/CAP/src/CompanyName.ProjectName.CAP/CompanyName.ProjectName.CAP.csproj

@ -5,9 +5,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetCore.CAP" Version="5.1.3" />
<PackageReference Include="Savorboard.CAP.InMemoryMessageQueue" Version="5.1.1" />
<PackageReference Include="Volo.Abp.Core" Version="$(AbpPackageVersion)" />
<PackageReference Include="Volo.Abp.EventBus" Version="$(AbpPackageVersion)" />
<PackageReference Include="DotNetCore.CAP" Version="$(DotNetCoreCAP)" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="$(DotNetCoreCAP)" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="$(DotNetCoreCAP)" />
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="$(DotNetCoreCAP)" />
<PackageReference Include="DotNetCore.CAP.InMemoryStorage" Version="$(DotNetCoreCAP)" />
</ItemGroup>
</Project>

22
aspnet-core/modules/QueryManagement/src/CompanyName.ProjectName.QueryManagement.Application/ElasticSearchs/LogAppService.cs

@ -1,21 +1,35 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
using CompanyName.ProjectName.Extensions.Customs.Dtos;
using CompanyName.ProjectName.QueryManagement.ElasticSearchs.Dtos;
using Microsoft.Extensions.Configuration;
namespace CompanyName.ProjectName.QueryManagement.ElasticSearchs
{
public class LogAppService : QueryManagementAppService, ILogAppService
{
private readonly ICompanyNameProjectNameLogRepository _companyNameProjectNameLogRepository;
private readonly IConfiguration _configuration;
public LogAppService(ICompanyNameProjectNameLogRepository companyNameProjectNameLogRepository)
public LogAppService(
ICompanyNameProjectNameLogRepository companyNameProjectNameLogRepository,
IConfiguration configuration)
{
_companyNameProjectNameLogRepository = companyNameProjectNameLogRepository;
_configuration = configuration;
}
public Task<CustomePagedResultDto<PagingElasticSearchLogOutput>> PaingLogAsync(PagingElasticSearchLogInput input)
public async Task<CustomePagedResultDto<PagingElasticSearchLogOutput>> PaingLogAsync(PagingElasticSearchLogInput input)
{
return _companyNameProjectNameLogRepository.PaingAsync(input);
var enabled = _configuration.GetValue<bool>("LogToElasticSearch:Enabled", false);
if (enabled)
{
return await _companyNameProjectNameLogRepository.PaingAsync(input);
}
else
{
return new CustomePagedResultDto<PagingElasticSearchLogOutput>(0, new List<PagingElasticSearchLogOutput>());
}
}
}
}

3
aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/CompanyName.ProjectName.HttpApi.Host.csproj

@ -34,9 +34,6 @@
<PackageReference Include="AspNetCore.HealthChecks.MySql" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.Redis" Version="5.0.2" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="5.0.7" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="5.1.1" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="5.1.1" />
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="5.1.1" />
</ItemGroup>
<ItemGroup>

16
aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/Extensions/Filters/HiddenAbpDefaultApiFilter.cs

@ -42,14 +42,14 @@ namespace CompanyName.ProjectName.Extensions.Filters
private List<string> GetHiddenAbpDefaultApiList()
{
return new List<string>() {
"/api/abp/multi-tenancy/tenants",
"/api/account",
"/api/feature-management/features",
"/api/permission-management/permissions",
"/api/identity/my-profile",
"/api/identity",
"/api/multi-tenancy/tenants",
"/api/setting-management/emailing"
// "/api/abp/multi-tenancy/tenants",
// "/api/account",
// "/api/feature-management/features",
// "/api/permission-management/permissions",
// "/api/identity/my-profile",
// "/api/identity",
// "/api/multi-tenancy/tenants",
// "/api/setting-management/emailing"
};
}
}

28
aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs

@ -47,6 +47,7 @@ using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.MultiTenancy;
using CompanyName.ProjectName.Extensions.Customs.Http;
using CompanyName.ProjectName.QueryManagement.ElasticSearch;
using Savorboard.CAP.InMemoryMessageQueue;
using Serilog;
using Volo.Abp.AspNetCore.ExceptionHandling;
@ -145,9 +146,8 @@ namespace CompanyName.ProjectName
private void ConfigureAbpExceptions(ServiceConfigurationContext context)
{
context.Services.Configure<AbpExceptionHandlingOptions>(options => { options.SendExceptionsDetailsToClients = true; });
}
public void ConfigureHangfireMysql(ServiceConfigurationContext context)
{
Configure<AbpBackgroundJobOptions>(options => { options.IsJobExecutionEnabled = true; });
@ -418,23 +418,35 @@ namespace CompanyName.ProjectName
private void ConfigurationCap(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var enabled = configuration.GetValue<bool>("Cap:Enabled", false);
if (enabled)
{
context.AddAbpCap(capOptions =>
{
capOptions.UseEntityFramework<ProjectNameDbContext>();
capOptions.UseRabbitMQ(option =>
{
option.HostName = configuration.GetValue<string>("RabbitMq:HostName");
option.UserName = configuration.GetValue<string>("RabbitMq:UserName");
option.Password = configuration.GetValue<string>("RabbitMq:Password");
option.HostName = configuration.GetValue<string>("Cap:RabbitMq:HostName");
option.UserName = configuration.GetValue<string>("Cap:RabbitMq:UserName");
option.Password = configuration.GetValue<string>("Cap:RabbitMq:Password");
});
var hostingEnvironment = context.Services.GetHostingEnvironment();
bool auth = !hostingEnvironment.IsDevelopment();
capOptions.UseDashboard(options =>
{
options.UseAuth = auth;
capOptions.UseDashboard(options => { options.UseAuth = auth; });
});
}
else
{
context.AddAbpCap(capOptions =>
{
capOptions.UseInMemoryStorage();
capOptions.UseInMemoryMessageQueue();
var hostingEnvironment = context.Services.GetHostingEnvironment();
bool auth = !hostingEnvironment.IsDevelopment();
capOptions.UseDashboard(options => { options.UseAuth = auth; });
});
}
}
}
}

11
aspnet-core/services/host/CompanyName.ProjectName.HttpApi.Host/appsettings.Development.json

@ -24,12 +24,6 @@
"DatabaseId": 0
}
},
"AuthServer": {
"Authority": "https://localhost:44354",
"RequireHttpsMetadata": "true",
"SwaggerClientId": "ProjectName_Swagger",
"SwaggerClientSecret": "1q2w3e*"
},
"StringEncryption": {
"DefaultPassPhrase": "YFLtqf75HkDnKR0n"
},
@ -42,13 +36,16 @@
"ExpirationTime": 24
// hour
},
"Cap": {
"Enabled": "false",
"RabbitMq": {
"HostName": "localhost",
"UserName": "admin",
"Password": "admin"
}
},
"LogToElasticSearch": {
"Enabled": "true",
"Enabled": "false",
"ElasticSearch": {
"Url": "http://es.cn",
"IndexFormat": "companyname.projectname.development",

36
aspnet-core/services/src/CompanyName.ProjectName.Domain/Users/UserDataSeedContributor.cs

@ -1,7 +1,39 @@
namespace CompanyName.ProjectName.Users
using System;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;
namespace CompanyName.ProjectName.Users
{
public class UserDataSeedContributor
public class UserDataSeedContributor : IDataSeedContributor, ITransientDependency
{
private readonly IdentityUserManager _userManager;
private readonly IdentityRoleManager _identityRoleManager;
public UserDataSeedContributor(
IdentityUserManager userManager,
IdentityRoleManager identityRoleManager)
{
_userManager = userManager;
_identityRoleManager = identityRoleManager;
}
public async Task SeedAsync(DataSeedContext context)
{
const string adminUserName = "admin";
var adminUser = await _userManager.FindByNameAsync(adminUserName);
if (adminUser != null)
{
await _userManager.SetLockoutEndDateAsync(adminUser, DateTimeOffset.UtcNow.AddDays(-1));
}
var role = await _identityRoleManager.FindByNameAsync(adminUserName);
if (role != null)
{
role.IsDefault = true;
await _identityRoleManager.UpdateAsync(role);
}
}
}
}

2
vben271/.env.production

@ -34,7 +34,7 @@ VITE_USE_PWA = false
# Is it compatible with older browsers
VITE_LEGACY = false
VITE_BUILD_COMPRESS = 'none'
VITE_BUILD_COMPRESS = 'gzip'
# 认证授权服务器地址
VITE_AUTH_URL='http://120.24.194.14:8013'

4
vben271/_nginx/default.conf

@ -11,6 +11,10 @@ server {
#access_log /var/log/nginx/host.access.log main;
location / {
if ($request_filename ~* .*\.html$) {
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;

11
vben271/_nginx/nginx.conf

@ -28,6 +28,15 @@ http {
keepalive_timeout 65;
send_timeout 600;
#gzip on;
# 开启gzip
gzip on;
# 开启gzip_static
# gzip_static 开启后可能会报错,需要安装相应的模块, 具体安装方式可以自行查询
# 只有这个开启,vue文件打包的.gz文件才会有效果,否则不需要开启gzip进行打包
gzip_static on;
gzip_proxied any;
gzip_min_length 1k;
gzip_buffers 4 16k;
include /etc/nginx/conf.d/*.conf;
}

Loading…
Cancel
Save