chore 优化代码
This commit is contained in:
		| @ -5,4 +5,4 @@ namespace KonSoft.Report.Data; | ||||
| public interface IReportDbSchemaMigrator | ||||
| { | ||||
|     Task MigrateAsync(); | ||||
| } | ||||
| } | ||||
| @ -12,4 +12,4 @@ public class NullReportDbSchemaMigrator : IReportDbSchemaMigrator, ITransientDep | ||||
|     { | ||||
|         return Task.CompletedTask; | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -17,12 +17,11 @@ namespace KonSoft.Report.Data; | ||||
|  | ||||
| public class ReportDbMigrationService : ITransientDependency | ||||
| { | ||||
|     public ILogger<ReportDbMigrationService> Logger { get; set; } | ||||
|     private readonly ICurrentTenant _currentTenant; | ||||
|  | ||||
|     private readonly IDataSeeder _dataSeeder; | ||||
|     private readonly IEnumerable<IReportDbSchemaMigrator> _dbSchemaMigrators; | ||||
|     private readonly ITenantRepository _tenantRepository; | ||||
|     private readonly ICurrentTenant _currentTenant; | ||||
|  | ||||
|     public ReportDbMigrationService( | ||||
|         IDataSeeder dataSeeder, | ||||
| @ -38,6 +37,8 @@ public class ReportDbMigrationService : ITransientDependency | ||||
|         Logger = NullLogger<ReportDbMigrationService>.Instance; | ||||
|     } | ||||
|  | ||||
|     public ILogger<ReportDbMigrationService> Logger { get; set; } | ||||
|  | ||||
|     public async Task MigrateAsync() | ||||
|     { | ||||
|         var initialMigrationAdded = AddInitialMigrationIfNotExist(); | ||||
| @ -52,7 +53,7 @@ public class ReportDbMigrationService : ITransientDependency | ||||
|         await MigrateDatabaseSchemaAsync(); | ||||
|         await SeedDataAsync(); | ||||
|  | ||||
|         Logger.LogInformation($"Successfully completed host database migrations."); | ||||
|         Logger.LogInformation("Successfully completed host database migrations."); | ||||
|  | ||||
|         var tenants = await _tenantRepository.GetListAsync(includeDetails: true); | ||||
|  | ||||
| @ -101,8 +102,10 @@ public class ReportDbMigrationService : ITransientDependency | ||||
|         Logger.LogInformation($"Executing {(tenant == null ? "host" : tenant.Name + " tenant")} database seed..."); | ||||
|  | ||||
|         await _dataSeeder.SeedAsync(new DataSeedContext(tenant?.Id) | ||||
|             .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, IdentityDataSeedContributor.AdminEmailDefaultValue) | ||||
|             .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, IdentityDataSeedContributor.AdminPasswordDefaultValue) | ||||
|             .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, | ||||
|                 IdentityDataSeedContributor.AdminEmailDefaultValue) | ||||
|             .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, | ||||
|                 IdentityDataSeedContributor.AdminPasswordDefaultValue) | ||||
|         ); | ||||
|     } | ||||
|  | ||||
| @ -127,10 +130,8 @@ public class ReportDbMigrationService : ITransientDependency | ||||
|                 AddInitialMigration(); | ||||
|                 return true; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
| @ -149,7 +150,8 @@ public class ReportDbMigrationService : ITransientDependency | ||||
|     private bool MigrationsFolderExists() | ||||
|     { | ||||
|         var dbMigrationsProjectFolder = GetEntityFrameworkCoreProjectFolderPath(); | ||||
|         return dbMigrationsProjectFolder != null && Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "Migrations")); | ||||
|         return dbMigrationsProjectFolder != null && | ||||
|                Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "Migrations")); | ||||
|     } | ||||
|  | ||||
|     private void AddInitialMigration() | ||||
| @ -207,7 +209,8 @@ public class ReportDbMigrationService : ITransientDependency | ||||
|         { | ||||
|             currentDirectory = Directory.GetParent(currentDirectory.FullName); | ||||
|  | ||||
|             if (currentDirectory != null && Directory.GetFiles(currentDirectory.FullName).FirstOrDefault(f => f.EndsWith(".sln")) != null) | ||||
|             if (currentDirectory != null && | ||||
|                 Directory.GetFiles(currentDirectory.FullName).FirstOrDefault(f => f.EndsWith(".sln")) != null) | ||||
|             { | ||||
|                 return currentDirectory.FullName; | ||||
|             } | ||||
| @ -215,4 +218,4 @@ public class ReportDbMigrationService : ITransientDependency | ||||
|  | ||||
|         return null; | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -23,12 +23,12 @@ namespace KonSoft.Report.OpenIddict; | ||||
|  */ | ||||
| public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDependency | ||||
| { | ||||
|     private readonly IAbpApplicationManager _applicationManager; | ||||
|     private readonly IConfiguration _configuration; | ||||
|     private readonly IOpenIddictApplicationRepository _openIddictApplicationRepository; | ||||
|     private readonly IAbpApplicationManager _applicationManager; | ||||
|     private readonly IOpenIddictScopeRepository _openIddictScopeRepository; | ||||
|     private readonly IOpenIddictScopeManager _scopeManager; | ||||
|     private readonly IPermissionDataSeeder _permissionDataSeeder; | ||||
|     private readonly IOpenIddictScopeManager _scopeManager; | ||||
|     private readonly IStringLocalizer<OpenIddictResponse> L; | ||||
|  | ||||
|     public OpenIddictDataSeedContributor( | ||||
| @ -38,7 +38,7 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|         IOpenIddictScopeRepository openIddictScopeRepository, | ||||
|         IOpenIddictScopeManager scopeManager, | ||||
|         IPermissionDataSeeder permissionDataSeeder, | ||||
|         IStringLocalizer<OpenIddictResponse> l ) | ||||
|         IStringLocalizer<OpenIddictResponse> l) | ||||
|     { | ||||
|         _configuration = configuration; | ||||
|         _openIddictApplicationRepository = openIddictApplicationRepository; | ||||
| @ -60,7 +60,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|     { | ||||
|         if (await _openIddictScopeRepository.FindByNameAsync("Report") == null) | ||||
|         { | ||||
|             await _scopeManager.CreateAsync(new OpenIddictScopeDescriptor { | ||||
|             await _scopeManager.CreateAsync(new OpenIddictScopeDescriptor | ||||
|             { | ||||
|                 Name = "Report", DisplayName = "Report API", Resources = { "Report" } | ||||
|             }); | ||||
|         } | ||||
| @ -68,7 +69,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|  | ||||
|     private async Task CreateApplicationsAsync() | ||||
|     { | ||||
|         var commonScopes = new List<string> { | ||||
|         var commonScopes = new List<string> | ||||
|         { | ||||
|             OpenIddictConstants.Permissions.Scopes.Address, | ||||
|             OpenIddictConstants.Permissions.Scopes.Email, | ||||
|             OpenIddictConstants.Permissions.Scopes.Phone, | ||||
| @ -80,10 +82,6 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|         var configurationSection = _configuration.GetSection("OpenIddict:Applications"); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|         // Swagger Client | ||||
|         var swaggerClientId = configurationSection["Report_Swagger:ClientId"]; | ||||
|         if (!swaggerClientId.IsNullOrWhiteSpace()) | ||||
| @ -91,13 +89,13 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|             var swaggerRootUrl = configurationSection["Report_Swagger:RootUrl"]?.TrimEnd('/'); | ||||
|  | ||||
|             await CreateApplicationAsync( | ||||
|                 name: swaggerClientId!, | ||||
|                 type: OpenIddictConstants.ClientTypes.Public, | ||||
|                 consentType: OpenIddictConstants.ConsentTypes.Implicit, | ||||
|                 displayName: "Swagger Application", | ||||
|                 secret: null, | ||||
|                 grantTypes: [OpenIddictConstants.GrantTypes.AuthorizationCode], | ||||
|                 scopes: commonScopes, | ||||
|                 swaggerClientId!, | ||||
|                 OpenIddictConstants.ClientTypes.Public, | ||||
|                 OpenIddictConstants.ConsentTypes.Implicit, | ||||
|                 "Swagger Application", | ||||
|                 null, | ||||
|                 [OpenIddictConstants.GrantTypes.AuthorizationCode], | ||||
|                 commonScopes, | ||||
|                 redirectUri: $"{swaggerRootUrl}/swagger/oauth2-redirect.html", | ||||
|                 clientUri: swaggerRootUrl | ||||
|             ); | ||||
| @ -131,13 +129,14 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|  | ||||
|         var client = await _openIddictApplicationRepository.FindByClientIdAsync(name); | ||||
|  | ||||
|         var application = new AbpApplicationDescriptor { | ||||
|         var application = new AbpApplicationDescriptor | ||||
|         { | ||||
|             ClientId = name, | ||||
|             ClientType = type, | ||||
|             ClientSecret = secret, | ||||
|             ConsentType = consentType, | ||||
|             DisplayName = displayName, | ||||
|             ClientUri = clientUri, | ||||
|             ClientUri = clientUri | ||||
|         }; | ||||
|  | ||||
|         Check.NotNullOrEmpty(grantTypes, nameof(grantTypes)); | ||||
| @ -160,7 +159,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|             application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Logout); | ||||
|         } | ||||
|  | ||||
|         var buildInGrantTypes = new[] { | ||||
|         var buildInGrantTypes = new[] | ||||
|         { | ||||
|             OpenIddictConstants.GrantTypes.Implicit, OpenIddictConstants.GrantTypes.Password, | ||||
|             OpenIddictConstants.GrantTypes.AuthorizationCode, OpenIddictConstants.GrantTypes.ClientCredentials, | ||||
|             OpenIddictConstants.GrantTypes.DeviceCode, OpenIddictConstants.GrantTypes.RefreshToken | ||||
| @ -233,7 +233,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         var buildInScopes = new[] { | ||||
|         var buildInScopes = new[] | ||||
|         { | ||||
|             OpenIddictConstants.Permissions.Scopes.Address, OpenIddictConstants.Permissions.Scopes.Email, | ||||
|             OpenIddictConstants.Permissions.Scopes.Phone, OpenIddictConstants.Permissions.Scopes.Profile, | ||||
|             OpenIddictConstants.Permissions.Scopes.Roles | ||||
| @ -289,8 +290,7 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|             await _permissionDataSeeder.SeedAsync( | ||||
|                 ClientPermissionValueProvider.ProviderName, | ||||
|                 name, | ||||
|                 permissions, | ||||
|                 null | ||||
|                 permissions | ||||
|             ); | ||||
|         } | ||||
|  | ||||
| @ -302,8 +302,10 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|  | ||||
|         if (!HasSameRedirectUris(client, application)) | ||||
|         { | ||||
|             client.RedirectUris = JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/'))); | ||||
|             client.PostLogoutRedirectUris = JsonSerializer.Serialize(application.PostLogoutRedirectUris.Select(q => q.ToString().TrimEnd('/'))); | ||||
|             client.RedirectUris = | ||||
|                 JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/'))); | ||||
|             client.PostLogoutRedirectUris = | ||||
|                 JsonSerializer.Serialize(application.PostLogoutRedirectUris.Select(q => q.ToString().TrimEnd('/'))); | ||||
|  | ||||
|             await _applicationManager.UpdateAsync(client.ToModel()); | ||||
|         } | ||||
| @ -317,11 +319,13 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep | ||||
|  | ||||
|     private bool HasSameRedirectUris(OpenIddictApplication existingClient, AbpApplicationDescriptor application) | ||||
|     { | ||||
|         return existingClient.RedirectUris == JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/'))); | ||||
|         return existingClient.RedirectUris == | ||||
|                JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/'))); | ||||
|     } | ||||
|  | ||||
|     private bool HasSameScopes(OpenIddictApplication existingClient, AbpApplicationDescriptor application) | ||||
|     { | ||||
|         return existingClient.Permissions == JsonSerializer.Serialize(application.Permissions.Select(q => q.ToString().TrimEnd('/'))); | ||||
|         return existingClient.Permissions == | ||||
|                JsonSerializer.Serialize(application.Permissions.Select(q => q.ToString().TrimEnd('/'))); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -1,3 +1,4 @@ | ||||
| using System.Runtime.CompilerServices; | ||||
| [assembly:InternalsVisibleToAttribute("KonSoft.Report.Domain.Tests")] | ||||
| [assembly:InternalsVisibleToAttribute("KonSoft.Report.TestBase")] | ||||
|  | ||||
| [assembly: InternalsVisibleToAttribute("KonSoft.Report.Domain.Tests")] | ||||
| [assembly: InternalsVisibleToAttribute("KonSoft.Report.TestBase")] | ||||
| @ -5,4 +5,4 @@ public static class ReportConsts | ||||
|     public const string DbTablePrefix = "App"; | ||||
|  | ||||
|     public const string DbSchema = null; | ||||
| } | ||||
| } | ||||
| @ -1,6 +1,6 @@ | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using KonSoft.Report.MultiTenancy; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using Microsoft.Extensions.DependencyInjection.Extensions; | ||||
| using KonSoft.Report.MultiTenancy; | ||||
| using Volo.Abp.AuditLogging; | ||||
| using Volo.Abp.BackgroundJobs; | ||||
| using Volo.Abp.Emailing; | ||||
| @ -56,13 +56,10 @@ public class ReportDomainModule : AbpModule | ||||
|             options.Languages.Add(new LanguageInfo("es", "es", "Español")); | ||||
|         }); | ||||
|  | ||||
|         Configure<AbpMultiTenancyOptions>(options => | ||||
|         { | ||||
|             options.IsEnabled = MultiTenancyConsts.IsEnabled; | ||||
|         }); | ||||
|         Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = MultiTenancyConsts.IsEnabled; }); | ||||
|  | ||||
| #if DEBUG | ||||
|         context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>()); | ||||
| #endif | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -9,4 +9,4 @@ public class ReportSettingDefinitionProvider : SettingDefinitionProvider | ||||
|         //Define your own settings here. Example: | ||||
|         //context.Add(new SettingDefinition(ReportSettings.MySetting1)); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -6,4 +6,4 @@ public static class ReportSettings | ||||
|  | ||||
|     //Add your own setting names here. Example: | ||||
|     //public const string MySetting1 = Prefix + ".MySetting1"; | ||||
| } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user