diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClientExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClientExtensions.cs deleted file mode 100644 index 601a2d1088..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClientExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; -using Volo.Abp.Threading; - -namespace Volo.Abp.AspNetCore.Mvc.Client -{ - public static class CachedApplicationConfigurationClientExtensions - { - public static ApplicationConfigurationDto Get(this ICachedApplicationConfigurationClient client) - { - return AsyncHelper.RunSync(client.GetAsync); - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs index d994a84335..79033f3679 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Localization; +using Volo.Abp.Threading; namespace Volo.Abp.AspNetCore.Mvc.Client { @@ -54,8 +55,11 @@ namespace Volo.Abp.AspNetCore.Mvc.Client private Dictionary GetResourceOrNull() { - var resource = _applicationConfigurationClient - .Get() + var applicationConfigurationDto = AsyncHelper.RunSync( + () => _applicationConfigurationClient.GetAsync() + ); + + var resource = applicationConfigurationDto .Localization.Values .GetOrDefault(_resource.ResourceName); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Toolbars/BasicThemeMainTopToolbarContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Toolbars/BasicThemeMainTopToolbarContributor.cs index e0738d424f..1ed1d2d5d3 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Toolbars/BasicThemeMainTopToolbarContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Toolbars/BasicThemeMainTopToolbarContributor.cs @@ -10,22 +10,23 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Toolbars { public class BasicThemeMainTopToolbarContributor : IToolbarContributor { - public Task ConfigureToolbarAsync(IToolbarConfigurationContext context) + public async Task ConfigureToolbarAsync(IToolbarConfigurationContext context) { if (context.Toolbar.Name != StandardToolbars.Main) { - return Task.CompletedTask; + return; } if (!(context.Theme is BasicTheme)) { - return Task.CompletedTask; + return; } var languageProvider = context.ServiceProvider.GetService(); //TODO: This duplicates GetLanguages() usage. Can we eleminate this? - if (languageProvider.GetLanguages().Count > 1) + var languages = await languageProvider.GetLanguagesAsync(); + if (languages.Count > 1) { context.Toolbar.Items.Add(new ToolbarItem(typeof(LanguageSwitchViewComponent))); } @@ -34,8 +35,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Toolbars { context.Toolbar.Items.Add(new ToolbarItem(typeof(UserMenuViewComponent))); } - - return Task.CompletedTask; } } } diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs index 25a9d38d06..c139c49ba1 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs @@ -56,10 +56,10 @@ namespace Microsoft.AspNetCore.Builder using (var scope = app.ApplicationServices.CreateScope()) { var languageProvider = scope.ServiceProvider.GetRequiredService(); - languages = languageProvider.GetLanguages(); + languages = AsyncHelper.RunSync(() => languageProvider.GetLanguagesAsync()); var settingProvider = scope.ServiceProvider.GetRequiredService(); - defaultLanguage = settingProvider.GetOrNull(LocalizationSettingNames.DefaultLanguage); + defaultLanguage = AsyncHelper.RunSync(() => settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage)); } var options = !languages.Any() diff --git a/framework/src/Volo.Abp.Authorization/Microsoft/AspNetCore/Authorization/AbpAuthorizationServiceExtensions.cs b/framework/src/Volo.Abp.Authorization/Microsoft/AspNetCore/Authorization/AbpAuthorizationServiceExtensions.cs index a4cbb27da5..9d16a6a55c 100644 --- a/framework/src/Volo.Abp.Authorization/Microsoft/AspNetCore/Authorization/AbpAuthorizationServiceExtensions.cs +++ b/framework/src/Volo.Abp.Authorization/Microsoft/AspNetCore/Authorization/AbpAuthorizationServiceExtensions.cs @@ -1,25 +1,12 @@ using System.Collections.Generic; -using System.Security.Claims; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Authorization; -using Volo.Abp.Threading; namespace Microsoft.AspNetCore.Authorization { - // TODO: Complete all Sync extension methods! public static class AbpAuthorizationServiceExtensions { - public static AuthorizationResult Authorize(this IAuthorizationService authorizationService, ClaimsPrincipal user, object resource, string policyName) - { - return AsyncHelper.RunSync(() => authorizationService.AuthorizeAsync(user, resource, policyName)); - } - - public static AuthorizationResult Authorize(this IAuthorizationService authorizationService, ClaimsPrincipal user, object resource, IEnumerable requirements) - { - return AsyncHelper.RunSync(() => authorizationService.AuthorizeAsync(user, resource, requirements)); - } - public static Task AuthorizeAsync(this IAuthorizationService authorizationService, string policyName) { return AuthorizeAsync( @@ -29,15 +16,6 @@ namespace Microsoft.AspNetCore.Authorization ); } - public static AuthorizationResult Authorize(this IAuthorizationService authorizationService, string policyName) - { - return Authorize( - authorizationService, - authorizationService.AsAbpAuthorizationService().CurrentPrincipal, - policyName - ); - } - public static Task AuthorizeAsync(this IAuthorizationService authorizationService, object resource, IAuthorizationRequirement requirement) { return authorizationService.AuthorizeAsync( @@ -81,25 +59,11 @@ namespace Microsoft.AspNetCore.Authorization ); } - public static AuthorizationResult Authorize(this IAuthorizationService authorizationService, object resource, string policyName) - { - return authorizationService.Authorize( - authorizationService.AsAbpAuthorizationService().CurrentPrincipal, - resource, - policyName - ); - } - public static async Task IsGrantedAsync(this IAuthorizationService authorizationService, string policyName) { return (await authorizationService.AuthorizeAsync(policyName)).Succeeded; } - public static bool IsGranted(this IAuthorizationService authorizationService, string policyName) - { - return authorizationService.Authorize(policyName).Succeeded; - } - public static async Task IsGrantedAsync(this IAuthorizationService authorizationService, object resource, IAuthorizationRequirement requirement) { return (await authorizationService.AuthorizeAsync(resource, requirement)).Succeeded; @@ -133,11 +97,6 @@ namespace Microsoft.AspNetCore.Authorization } } - public static void Check(this IAuthorizationService authorizationService, string policyName) - { - AsyncHelper.RunSync(() => authorizationService.CheckAsync(policyName)); - } - public static async Task CheckAsync(this IAuthorizationService authorizationService, object resource, IAuthorizationRequirement requirement) { if (!await authorizationService.IsGrantedAsync(resource, requirement)) diff --git a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AuthorizationInterceptor.cs b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AuthorizationInterceptor.cs index 7c89bcbe11..45cb2ec39d 100644 --- a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AuthorizationInterceptor.cs +++ b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AuthorizationInterceptor.cs @@ -39,9 +39,9 @@ namespace Volo.Abp.Authorization await invocation.ProceedAsync(); } - protected virtual Task AuthorizeAsync(IAbpMethodInvocation invocation) + protected virtual async Task AuthorizeAsync(IAbpMethodInvocation invocation) { - return _methodInvocationAuthorizationService.CheckAsync( + await _methodInvocationAuthorizationService.CheckAsync( new MethodInvocationAuthorizationContext( invocation.Method ) diff --git a/framework/src/Volo.Abp.BackgroundJobs.Abstractions/Volo/Abp/BackgroundJobs/BackgroundJobManagerExtensions.cs b/framework/src/Volo.Abp.BackgroundJobs.Abstractions/Volo/Abp/BackgroundJobs/BackgroundJobManagerExtensions.cs index 4cc93fa533..774bccf2c6 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.Abstractions/Volo/Abp/BackgroundJobs/BackgroundJobManagerExtensions.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.Abstractions/Volo/Abp/BackgroundJobs/BackgroundJobManagerExtensions.cs @@ -1,6 +1,4 @@ -using System; -using Volo.Abp.DynamicProxy; -using Volo.Abp.Threading; +using Volo.Abp.DynamicProxy; namespace Volo.Abp.BackgroundJobs { @@ -9,19 +7,6 @@ namespace Volo.Abp.BackgroundJobs /// public static class BackgroundJobManagerExtensions { - /// - /// Enqueues a job to be executed. - /// - /// Type of the arguments of job. - /// Background job manager reference - /// Job arguments. - /// Job priority. - /// Job delay (wait duration before first try). - public static string Enqueue(this IBackgroundJobManager backgroundJobManager, TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null) - { - return AsyncHelper.RunSync(() => backgroundJobManager.EnqueueAsync(args, priority, delay)); - } - /// /// Checks if background job system has a real implementation. /// It returns false if the current implementation is . diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/AbpBackgroundJobsRabbitMqModule.cs b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/AbpBackgroundJobsRabbitMqModule.cs index da18cdc8f3..21751435a7 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/AbpBackgroundJobsRabbitMqModule.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/AbpBackgroundJobsRabbitMqModule.cs @@ -29,16 +29,20 @@ namespace Volo.Abp.BackgroundJobs.RabbitMQ private static void StartJobQueueManager(ApplicationInitializationContext context) { - context.ServiceProvider - .GetRequiredService() - .Start(); + AsyncHelper.RunSync( + () => context.ServiceProvider + .GetRequiredService() + .StartAsync() + ); } private static void StopJobQueueManager(ApplicationShutdownContext context) { - context.ServiceProvider - .GetRequiredService() - .Stop(); + AsyncHelper.RunSync( + () => context.ServiceProvider + .GetRequiredService() + .StopAsync() + ); } } } diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueManager.cs b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueManager.cs index 266c9c5d8e..7ffe9ec82a 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueManager.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueManager.cs @@ -61,7 +61,7 @@ namespace Volo.Abp.BackgroundJobs.RabbitMQ .GetRequiredService(typeof(IJobQueue<>) .MakeGenericType(typeof(TArgs))); - jobQueue.Start(); + AsyncHelper.RunSync(() => jobQueue.StartAsync()); return jobQueue; }); diff --git a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs index b2a66f6fc4..4c9efbe6d8 100644 --- a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs +++ b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs @@ -36,9 +36,7 @@ namespace Volo.Abp.BackgroundJobs { var store = scope.ServiceProvider.GetRequiredService(); - var waitingJobs = AsyncHelper.RunSync( - () => store.GetWaitingJobsAsync(WorkerOptions.MaxJobFetchCount) - ); + var waitingJobs = store.GetWaitingJobs(WorkerOptions.MaxJobFetchCount); if (!waitingJobs.Any()) { @@ -64,7 +62,7 @@ namespace Volo.Abp.BackgroundJobs { jobExecuter.Execute(context); - AsyncHelper.RunSync(() => store.DeleteAsync(jobInfo.Id)); + store.Delete(jobInfo.Id); } catch (BackgroundJobExecutionException) { @@ -96,7 +94,7 @@ namespace Volo.Abp.BackgroundJobs { try { - store.UpdateAsync(jobInfo); + store.Update(jobInfo); } catch (Exception updateEx) { @@ -107,9 +105,8 @@ namespace Volo.Abp.BackgroundJobs protected virtual DateTime? CalculateNextTryTime(BackgroundJobInfo jobInfo, IClock clock) { var nextWaitDuration = WorkerOptions.DefaultFirstWaitDuration * (Math.Pow(WorkerOptions.DefaultWaitFactor, jobInfo.TryCount - 1)); - var nextTryDate = jobInfo.LastTryTime.HasValue - ? jobInfo.LastTryTime.Value.AddSeconds(nextWaitDuration) - : clock.Now.AddSeconds(nextWaitDuration); + var nextTryDate = jobInfo.LastTryTime?.AddSeconds(nextWaitDuration) ?? + clock.Now.AddSeconds(nextWaitDuration); if (nextTryDate.Subtract(jobInfo.CreationTime).TotalSeconds > WorkerOptions.DefaultTimeout) { diff --git a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/IBackgroundJobStore.cs b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/IBackgroundJobStore.cs index 839156c225..f909b3846d 100644 --- a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/IBackgroundJobStore.cs +++ b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/IBackgroundJobStore.cs @@ -9,6 +9,13 @@ namespace Volo.Abp.BackgroundJobs /// public interface IBackgroundJobStore { + /// + /// Gets a BackgroundJobInfo based on the given jobId. + /// + /// The Job Unique Identifier. + /// The BackgroundJobInfo object. + BackgroundJobInfo Find(Guid jobId); + /// /// Gets a BackgroundJobInfo based on the given jobId. /// @@ -16,12 +23,27 @@ namespace Volo.Abp.BackgroundJobs /// The BackgroundJobInfo object. Task FindAsync(Guid jobId); + /// + /// Inserts a background job. + /// + /// Job information. + void Insert(BackgroundJobInfo jobInfo); + /// /// Inserts a background job. /// /// Job information. Task InsertAsync(BackgroundJobInfo jobInfo); + /// + /// Gets waiting jobs. It should get jobs based on these: + /// Conditions: !IsAbandoned And NextTryTime <= Clock.Now. + /// Order by: Priority DESC, TryCount ASC, NextTryTime ASC. + /// Maximum result: . + /// + /// Maximum result count. + List GetWaitingJobs(int maxResultCount); + /// /// Gets waiting jobs. It should get jobs based on these: /// Conditions: !IsAbandoned And NextTryTime <= Clock.Now. @@ -31,12 +53,24 @@ namespace Volo.Abp.BackgroundJobs /// Maximum result count. Task> GetWaitingJobsAsync(int maxResultCount); + /// + /// Deletes a job. + /// + /// The Job Unique Identifier. + void Delete(Guid jobId); + /// /// Deletes a job. /// /// The Job Unique Identifier. Task DeleteAsync(Guid jobId); + /// + /// Updates a job. + /// + /// Job information. + void Update(BackgroundJobInfo jobInfo); + /// /// Updates a job. /// diff --git a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/InMemoryBackgroundJobStore.cs b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/InMemoryBackgroundJobStore.cs index 1dc6d7c700..30dd7fe090 100644 --- a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/InMemoryBackgroundJobStore.cs +++ b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/InMemoryBackgroundJobStore.cs @@ -23,11 +23,21 @@ namespace Volo.Abp.BackgroundJobs _jobs = new ConcurrentDictionary(); } + public BackgroundJobInfo Find(Guid jobId) + { + return _jobs.GetOrDefault(jobId); + } + public virtual Task FindAsync(Guid jobId) { return Task.FromResult(_jobs.GetOrDefault(jobId)); } - + + public void Insert(BackgroundJobInfo jobInfo) + { + _jobs[jobInfo.Id] = jobInfo; + } + public virtual Task InsertAsync(BackgroundJobInfo jobInfo) { _jobs[jobInfo.Id] = jobInfo; @@ -35,6 +45,17 @@ namespace Volo.Abp.BackgroundJobs return Task.FromResult(0); } + public List GetWaitingJobs(int maxResultCount) + { + return _jobs.Values + .Where(t => !t.IsAbandoned && t.NextTryTime <= Clock.Now) + .OrderByDescending(t => t.Priority) + .ThenBy(t => t.TryCount) + .ThenBy(t => t.NextTryTime) + .Take(maxResultCount) + .ToList(); + } + public virtual Task> GetWaitingJobsAsync(int maxResultCount) { var waitingJobs = _jobs.Values @@ -48,6 +69,11 @@ namespace Volo.Abp.BackgroundJobs return Task.FromResult(waitingJobs); } + public void Delete(Guid jobId) + { + _jobs.TryRemove(jobId, out _); + } + public virtual Task DeleteAsync(Guid jobId) { _jobs.TryRemove(jobId, out _); @@ -55,6 +81,14 @@ namespace Volo.Abp.BackgroundJobs return Task.FromResult(0); } + public void Update(BackgroundJobInfo jobInfo) + { + if (jobInfo.IsAbandoned) + { + DeleteAsync(jobInfo.Id); + } + } + public virtual Task UpdateAsync(BackgroundJobInfo jobInfo) { if (jobInfo.IsAbandoned) diff --git a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/AbpBackgroundWorkersModule.cs b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/AbpBackgroundWorkersModule.cs index 1ed2a7f78a..425ffaece0 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/AbpBackgroundWorkersModule.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/AbpBackgroundWorkersModule.cs @@ -15,9 +15,11 @@ namespace Volo.Abp.BackgroundWorkers var options = context.ServiceProvider.GetRequiredService>().Value; if (options.IsEnabled) { - context.ServiceProvider - .GetRequiredService() - .Start(); + AsyncHelper.RunSync( + () => context.ServiceProvider + .GetRequiredService() + .StartAsync() + ); } } @@ -26,9 +28,11 @@ namespace Volo.Abp.BackgroundWorkers var options = context.ServiceProvider.GetRequiredService>().Value; if (options.IsEnabled) { - context.ServiceProvider - .GetRequiredService() - .Stop(); + AsyncHelper.RunSync( + () => context.ServiceProvider + .GetRequiredService() + .StopAsync() + ); } } } diff --git a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerManager.cs b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerManager.cs index 6f8d57ed5c..a8b884e096 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerManager.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerManager.cs @@ -32,7 +32,9 @@ namespace Volo.Abp.BackgroundWorkers if (IsRunning) { - worker.Start(); + AsyncHelper.RunSync( + () => worker.StartAsync() + ); } } diff --git a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/PeriodicBackgroundWorkerBase.cs b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/PeriodicBackgroundWorkerBase.cs index 49773826a7..e699e4cbc8 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/PeriodicBackgroundWorkerBase.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/PeriodicBackgroundWorkerBase.cs @@ -26,12 +26,12 @@ namespace Volo.Abp.BackgroundWorkers public override async Task StartAsync(CancellationToken cancellationToken = default) { await base.StartAsync(cancellationToken); - await Timer.StartAsync(cancellationToken); + Timer.Start(cancellationToken); } public override async Task StopAsync(CancellationToken cancellationToken = default) { - await Timer.StopAsync(cancellationToken); + Timer.Stop(cancellationToken); await base.StopAsync(cancellationToken); } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs index 8d406feab3..42bc75c864 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs @@ -27,7 +27,11 @@ namespace Volo.Abp.Cli.Commands { if (commandLineArgs.Target == null) { - throw new CliUsageException("Module name is missing!" + Environment.NewLine + Environment.NewLine + await GetUsageInfo()); + throw new CliUsageException( + "Module name is missing!" + + Environment.NewLine + Environment.NewLine + + GetUsageInfo() + ); } var skipDbMigrations = Convert.ToBoolean( @@ -40,7 +44,7 @@ namespace Volo.Abp.Cli.Commands ); } - public Task GetUsageInfo() + public string GetUsageInfo() { var sb = new StringBuilder(); @@ -61,14 +65,14 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(" abp add-module Volo.Blogging -s Acme.BookStore --skip-db-migrations false Adds the module to the given solution but doesn't create a database migration."); sb.AppendLine(""); - return Task.FromResult(sb.ToString()); + return sb.ToString(); } - public Task GetShortDescriptionAsync() + public string GetShortDescription() { - return Task.FromResult("Adds a multi-package module to a solution by finding all packages of the module, " + - "finding related projects in the solution and adding each package to the" + - " corresponding project in the solution."); + return "Adds a multi-package module to a solution by finding all packages of the module, " + + "finding related projects in the solution and adding each package to the" + + " corresponding project in the solution."; } protected virtual string GetSolutionFile(CommandLineArgs commandLineArgs) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs index c7922cbc33..3b1153eade 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs @@ -27,7 +27,11 @@ namespace Volo.Abp.Cli.Commands { if (commandLineArgs.Target == null) { - throw new CliUsageException("Package name is missing!" + Environment.NewLine + Environment.NewLine + await GetUsageInfo()); + throw new CliUsageException( + "Package name is missing!" + + Environment.NewLine + Environment.NewLine + + GetUsageInfo() + ); } await ProjectNugetPackageAdder.AddAsync( @@ -36,7 +40,7 @@ namespace Volo.Abp.Cli.Commands ); } - public Task GetUsageInfo() + public string GetUsageInfo() { var sb = new StringBuilder(); @@ -55,14 +59,14 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(" abp add-package Volo.Abp.FluentValidation -p Acme.BookStore.Application Adds the package to the given project."); sb.AppendLine(""); - return Task.FromResult(sb.ToString()); + return sb.ToString(); } - public Task GetShortDescriptionAsync() + public string GetShortDescription() { - return Task.FromResult("Adds a new ABP package to a project by adding related nuget package" + - " as a dependency to the project and adding [DependsOn(...)] attribute to" + - " the module class in the project."); + return "Adds a new ABP package to a project by adding related nuget package" + + " as a dependency to the project and adding [DependsOn(...)] attribute to" + + " the module class in the project."; } protected virtual string GetProjectFile(CommandLineArgs commandLineArgs) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs index fe574c2112..c9046f44fb 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs @@ -28,7 +28,7 @@ namespace Volo.Abp.Cli.Commands { if (string.IsNullOrWhiteSpace(commandLineArgs.Target)) { - Logger.LogInformation(await GetUsageInfo()); + Logger.LogInformation(GetUsageInfo()); return; } @@ -37,11 +37,11 @@ namespace Volo.Abp.Cli.Commands using (var scope = ServiceScopeFactory.CreateScope()) { var command = (IConsoleCommand) scope.ServiceProvider.GetRequiredService(commandType); - Logger.LogInformation(await command.GetUsageInfo()); + Logger.LogInformation(command.GetUsageInfo()); } } - public async Task GetUsageInfo() + public string GetUsageInfo() { var sb = new StringBuilder(); @@ -58,8 +58,8 @@ namespace Volo.Abp.Cli.Commands using (var scope = ServiceScopeFactory.CreateScope()) { - shortDescription = await ((IConsoleCommand)scope.ServiceProvider.GetRequiredService(command.Value)) - .GetShortDescriptionAsync(); + shortDescription = ((IConsoleCommand) scope.ServiceProvider + .GetRequiredService(command.Value)).GetShortDescription(); } sb.Append(" >"); @@ -74,9 +74,9 @@ namespace Volo.Abp.Cli.Commands return sb.ToString(); } - public Task GetShortDescriptionAsync() + public string GetShortDescription() { - return Task.FromResult(""); + return string.Empty; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/IConsoleCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/IConsoleCommand.cs index b9fb34210b..92d57cce8b 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/IConsoleCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/IConsoleCommand.cs @@ -7,8 +7,8 @@ namespace Volo.Abp.Cli.Commands { Task ExecuteAsync(CommandLineArgs commandLineArgs); - Task GetUsageInfo(); + string GetUsageInfo(); - Task GetShortDescriptionAsync(); + string GetShortDescription(); } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs index 1828035fa1..631756c1e0 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs @@ -26,14 +26,22 @@ namespace Volo.Abp.Cli.Commands { if (commandLineArgs.Target.IsNullOrEmpty()) { - throw new CliUsageException("Username name is missing!" + Environment.NewLine + Environment.NewLine + await GetUsageInfo()); + throw new CliUsageException( + "Username name is missing!" + + Environment.NewLine + Environment.NewLine + + GetUsageInfo() + ); } Console.Write("Password: "); var password = ConsoleHelper.ReadSecret(); if (password.IsNullOrWhiteSpace()) { - throw new CliUsageException("Password name is missing!" + Environment.NewLine + Environment.NewLine + await GetUsageInfo()); + throw new CliUsageException( + "Password name is missing!" + + Environment.NewLine + Environment.NewLine + + GetUsageInfo() + ); } await AuthService.LoginAsync(commandLineArgs.Target, password); @@ -41,7 +49,7 @@ namespace Volo.Abp.Cli.Commands Logger.LogInformation($"Successfully logged in as '{commandLineArgs.Target}'"); } - public Task GetUsageInfo() + public string GetUsageInfo() { var sb = new StringBuilder(); @@ -52,12 +60,12 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine("Example:"); sb.AppendLine(" abp login john"); - return Task.FromResult(sb.ToString()); + return sb.ToString(); } - public Task GetShortDescriptionAsync() + public string GetShortDescription() { - return Task.FromResult(""); + return string.Empty; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs index 22d30367e6..d3024635fb 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs @@ -24,14 +24,14 @@ namespace Volo.Abp.Cli.Commands return AuthService.LogoutAsync(); } - public Task GetUsageInfo() + public string GetUsageInfo() { - return Task.FromResult(""); + return string.Empty; } - public Task GetShortDescriptionAsync() + public string GetShortDescription() { - return Task.FromResult(""); + return string.Empty; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs index c2e6816b86..3f2456e81b 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs @@ -30,7 +30,11 @@ namespace Volo.Abp.Cli.Commands { if (commandLineArgs.Target == null) { - throw new CliUsageException("Project name is missing!" + Environment.NewLine + Environment.NewLine + await GetUsageInfo()); + throw new CliUsageException( + "Project name is missing!" + + Environment.NewLine + Environment.NewLine + + GetUsageInfo() + ); } Logger.LogInformation("Creating a new project..."); @@ -98,7 +102,7 @@ namespace Volo.Abp.Cli.Commands Logger.LogInformation($"The output folder is: '{outputFolder}'"); } - public Task GetUsageInfo() + public string GetUsageInfo() { var sb = new StringBuilder(); @@ -124,12 +128,12 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(""); sb.AppendLine("See the documentation for more info."); - return Task.FromResult(sb.ToString()); + return sb.ToString(); } - public Task GetShortDescriptionAsync() + public string GetShortDescription() { - return Task.FromResult("Generates a new solution based on the ABP startup templates."); + return "Generates a new solution based on the ABP startup templates."; } protected virtual DatabaseProvider GetDatabaseProviderOrNull(CommandLineArgs commandLineArgs) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs index f0b00b913b..7ab17d608d 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs @@ -43,7 +43,7 @@ namespace Volo.Abp.Cli.Commands public async Task ExecuteAsync(CommandLineArgs commandLineArgs) { - UpdateNugetPackages(commandLineArgs); + await UpdateNugetPackages(commandLineArgs); UpdateNpmPackages(); var options = commandLineArgs.Options @@ -61,7 +61,7 @@ namespace Volo.Abp.Cli.Commands _npmPackagesUpdater.Update(Directory.GetCurrentDirectory()); } - private void UpdateNugetPackages(CommandLineArgs commandLineArgs) + private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs) { var includePreviews = commandLineArgs.Options.GetOrNull(Options.IncludePreviews.Short, Options.IncludePreviews.Long) != null; @@ -72,7 +72,7 @@ namespace Volo.Abp.Cli.Commands { var solutionName = Path.GetFileName(solution).RemovePostFix(".sln"); - _nugetPackagesVersionUpdater.UpdateSolution(solution, includePreviews); + await _nugetPackagesVersionUpdater.UpdateSolutionAsync(solution, includePreviews); Logger.LogInformation($"Volo packages are updated in {solutionName} solution."); return; @@ -84,17 +84,20 @@ namespace Volo.Abp.Cli.Commands { var projectName = Path.GetFileName(project).RemovePostFix(".csproj"); - _nugetPackagesVersionUpdater.UpdateProject(project, includePreviews); + await _nugetPackagesVersionUpdater.UpdateProjectAsync(project, includePreviews); Logger.LogInformation($"Volo packages are updated in {projectName} project."); return; } - throw new CliUsageException("No solution or project found in this directory." + Environment.NewLine + - Environment.NewLine + AsyncHelper.RunSync(GetUsageInfo)); + throw new CliUsageException( + "No solution or project found in this directory." + + Environment.NewLine + Environment.NewLine + + GetUsageInfo() + ); } - public Task GetUsageInfo() + public string GetUsageInfo() { var sb = new StringBuilder(); @@ -111,13 +114,13 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(""); sb.AppendLine("See the documentation for more info."); - return Task.FromResult(sb.ToString()); + return sb.ToString(); } - public Task GetShortDescriptionAsync() + public string GetShortDescription() { - return Task.FromResult("Automatically updates all ABP related NuGet packages and NPM packages in a" + - " solution or project to the latest versions"); + return "Automatically updates all ABP related NuGet packages and NPM packages in a" + + " solution or project to the latest versions"; } public static class Options diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs index 193106edbf..9f6b80b792 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs @@ -1,9 +1,9 @@ using NuGet.Versioning; using System.IO; +using System.Threading.Tasks; using System.Xml; using Volo.Abp.Cli.NuGet; using Volo.Abp.DependencyInjection; -using Volo.Abp.Threading; namespace Volo.Abp.Cli.ProjectModification { @@ -16,29 +16,29 @@ namespace Volo.Abp.Cli.ProjectModification _nuGetService = nuGetService; } - public void UpdateSolution(string solutionPath, bool includePreviews) + public async Task UpdateSolutionAsync(string solutionPath, bool includePreviews) { var projectPaths = ProjectFinder.GetProjectFiles(solutionPath); foreach (var filePath in projectPaths) { - UpdateInternal(filePath, includePreviews); + await UpdateInternalAsync(filePath, includePreviews); } } - public void UpdateProject(string projectPath, bool includePreviews) + public async Task UpdateProjectAsync(string projectPath, bool includePreviews) { - UpdateInternal(projectPath, includePreviews); + await UpdateInternalAsync(projectPath, includePreviews); } - protected virtual void UpdateInternal(string projectPath, bool includePreviews) + protected virtual async Task UpdateInternalAsync(string projectPath, bool includePreviews) { var fileContent = File.ReadAllText(projectPath); - File.WriteAllText(projectPath, UpdateVoloPackages(fileContent, includePreviews)); + File.WriteAllText(projectPath, await UpdateVoloPackagesAsync(fileContent, includePreviews)); } - private string UpdateVoloPackages(string content, bool includePreviews) + private async Task UpdateVoloPackagesAsync(string content, bool includePreviews) { var doc = new XmlDocument() { PreserveWhitespace = true }; doc.LoadXml(content); @@ -49,7 +49,7 @@ namespace Volo.Abp.Cli.ProjectModification var packageId = package.Attributes["Include"].Value; var packageVersion = SemanticVersion.Parse(versionAttribute.Value); - var latestVersion = AsyncHelper.RunSync(() => _nuGetService.GetLatestVersionOrNullAsync(packageId, includePreviews)); + var latestVersion = await _nuGetService.GetLatestVersionOrNullAsync(packageId, includePreviews); if (latestVersion != null && packageVersion < latestVersion) { diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs index 909ad40940..698f2c0ea3 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs @@ -124,20 +124,5 @@ namespace Volo.Abp.Application.Services await AuthorizationService.CheckAsync(policyName); } - - /// - /// Checks for given . - /// Throws if given policy has not been granted. - /// - /// The policy name. This method does nothing if given is null or empty. - protected virtual void CheckPolicy([CanBeNull] string policyName) - { - if (string.IsNullOrEmpty(policyName)) - { - return; - } - - AuthorizationService.Check(policyName); - } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AsyncCrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AsyncCrudAppService.cs deleted file mode 100644 index 055de921ee..0000000000 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AsyncCrudAppService.cs +++ /dev/null @@ -1,168 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Volo.Abp.Application.Dtos; -using Volo.Abp.Domain.Entities; -using Volo.Abp.Domain.Repositories; -using Volo.Abp.Linq; -using Volo.Abp.MultiTenancy; - -namespace Volo.Abp.Application.Services -{ - public abstract class AsyncCrudAppService - : AsyncCrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto - { - protected AsyncCrudAppService(IRepository repository) - : base(repository) - { - - } - } - - public abstract class AsyncCrudAppService - : AsyncCrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto - { - protected AsyncCrudAppService(IRepository repository) - : base(repository) - { - - } - } - - public abstract class AsyncCrudAppService - : AsyncCrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto - { - protected AsyncCrudAppService(IRepository repository) - : base(repository) - { - - } - } - - public abstract class AsyncCrudAppService - : AsyncCrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto - { - protected AsyncCrudAppService(IRepository repository) - : base(repository) - { - - } - - protected override TEntityDto MapToGetListOutputDto(TEntity entity) - { - return MapToGetOutputDto(entity); - } - } - - public abstract class AsyncCrudAppService - : CrudAppServiceBase, - IAsyncCrudAppService - where TEntity : class, IEntity - where TGetOutputDto : IEntityDto - where TGetListOutputDto : IEntityDto - { - public IAsyncQueryableExecuter AsyncQueryableExecuter { get; set; } - - protected AsyncCrudAppService(IRepository repository) - : base(repository) - { - AsyncQueryableExecuter = DefaultAsyncQueryableExecuter.Instance; - } - - public virtual async Task GetAsync(TKey id) - { - await CheckGetPolicyAsync(); - - var entity = await GetEntityByIdAsync(id); - return MapToGetOutputDto(entity); - } - - public virtual async Task> GetListAsync(TGetListInput input) - { - await CheckGetListPolicyAsync(); - - var query = CreateFilteredQuery(input); - - var totalCount = await AsyncQueryableExecuter.CountAsync(query); - - query = ApplySorting(query, input); - query = ApplyPaging(query, input); - - var entities = await AsyncQueryableExecuter.ToListAsync(query); - - return new PagedResultDto( - totalCount, - entities.Select(MapToGetListOutputDto).ToList() - ); - } - - public virtual async Task CreateAsync(TCreateInput input) - { - await CheckCreatePolicyAsync(); - - var entity = MapToEntity(input); - - TryToSetTenantId(entity); - - await Repository.InsertAsync(entity, autoSave: true); - - return MapToGetOutputDto(entity); - } - - public virtual async Task UpdateAsync(TKey id, TUpdateInput input) - { - await CheckUpdatePolicyAsync(); - - var entity = await GetEntityByIdAsync(id); - //TODO: Check if input has id different than given id and normalize if it's default value, throw ex otherwise - MapToEntity(input, entity); - await Repository.UpdateAsync(entity, autoSave: true); - - return MapToGetOutputDto(entity); - } - - public virtual async Task DeleteAsync(TKey id) - { - await CheckDeletePolicyAsync(); - - await Repository.DeleteAsync(id); - } - - protected virtual Task GetEntityByIdAsync(TKey id) - { - return Repository.GetAsync(id); - } - - protected virtual async Task CheckGetPolicyAsync() - { - await CheckPolicyAsync(GetPolicyName); - } - - protected virtual async Task CheckGetListPolicyAsync() - { - await CheckPolicyAsync(GetListPolicyName); - } - - protected virtual async Task CheckCreatePolicyAsync() - { - await CheckPolicyAsync(CreatePolicyName); - } - - protected virtual async Task CheckUpdatePolicyAsync() - { - await CheckPolicyAsync(UpdatePolicyName); - } - - protected virtual async Task CheckDeletePolicyAsync() - { - await CheckPolicyAsync(DeletePolicyName); - } - } -} diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs index e11df56056..3a64760a0f 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs @@ -1,8 +1,13 @@ -using System.Linq; +using System; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; +using Volo.Abp.Linq; using Volo.Abp.MultiTenancy; +using Volo.Abp.ObjectMapping; namespace Volo.Abp.Application.Services { @@ -34,7 +39,6 @@ namespace Volo.Abp.Application.Services : CrudAppService where TEntity : class, IEntity where TEntityDto : IEntityDto - where TCreateInput : IEntityDto { protected CrudAppService(IRepository repository) : base(repository) @@ -44,9 +48,9 @@ namespace Volo.Abp.Application.Services } public abstract class CrudAppService - : CrudAppService - where TEntity : class, IEntity - where TEntityDto : IEntityDto + : CrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto { protected CrudAppService(IRepository repository) : base(repository) @@ -61,38 +65,52 @@ namespace Volo.Abp.Application.Services } public abstract class CrudAppService - : CrudAppServiceBase, + : ApplicationService, ICrudAppService where TEntity : class, IEntity - where TGetOutputDto : IEntityDto - where TGetListOutputDto : IEntityDto + where TGetOutputDto : IEntityDto + where TGetListOutputDto : IEntityDto { + public IAsyncQueryableExecuter AsyncQueryableExecuter { get; set; } + + protected IRepository Repository { get; } + + protected virtual string GetPolicyName { get; set; } + + protected virtual string GetListPolicyName { get; set; } + + protected virtual string CreatePolicyName { get; set; } + + protected virtual string UpdatePolicyName { get; set; } + + protected virtual string DeletePolicyName { get; set; } + protected CrudAppService(IRepository repository) - : base(repository) { - + Repository = repository; + AsyncQueryableExecuter = DefaultAsyncQueryableExecuter.Instance; } - public virtual TGetOutputDto Get(TKey id) + public virtual async Task GetAsync(TKey id) { - CheckGetPolicy(); + await CheckGetPolicyAsync(); - var entity = GetEntityById(id); + var entity = await GetEntityByIdAsync(id); return MapToGetOutputDto(entity); } - public virtual PagedResultDto GetList(TGetListInput input) + public virtual async Task> GetListAsync(TGetListInput input) { - CheckGetListPolicy(); + await CheckGetListPolicyAsync(); var query = CreateFilteredQuery(input); - var totalCount = query.Count(); + var totalCount = await AsyncQueryableExecuter.CountAsync(query); query = ApplySorting(query, input); query = ApplyPaging(query, input); - var entities = query.ToList(); + var entities = await AsyncQueryableExecuter.ToListAsync(query); return new PagedResultDto( totalCount, @@ -100,65 +118,218 @@ namespace Volo.Abp.Application.Services ); } - public virtual TGetOutputDto Create(TCreateInput input) + public virtual async Task CreateAsync(TCreateInput input) { - CheckCreatePolicy(); + await CheckCreatePolicyAsync(); var entity = MapToEntity(input); TryToSetTenantId(entity); - Repository.Insert(entity, autoSave: true); + await Repository.InsertAsync(entity, autoSave: true); return MapToGetOutputDto(entity); } - public virtual TGetOutputDto Update(TKey id, TUpdateInput input) + public virtual async Task UpdateAsync(TKey id, TUpdateInput input) { - CheckUpdatePolicy(); + await CheckUpdatePolicyAsync(); - var entity = GetEntityById(id); + var entity = await GetEntityByIdAsync(id); + //TODO: Check if input has id different than given id and normalize if it's default value, throw ex otherwise MapToEntity(input, entity); - Repository.Update(entity, autoSave: true); + await Repository.UpdateAsync(entity, autoSave: true); return MapToGetOutputDto(entity); } - public virtual void Delete(TKey id) + public virtual async Task DeleteAsync(TKey id) { - CheckDeletePolicy(); + await CheckDeletePolicyAsync(); - Repository.Delete(id); + await Repository.DeleteAsync(id); } - protected virtual TEntity GetEntityById(TKey id) + protected virtual Task GetEntityByIdAsync(TKey id) { - return Repository.Get(id); + return Repository.GetAsync(id); } - protected virtual void CheckGetPolicy() + protected virtual async Task CheckGetPolicyAsync() { - CheckPolicy(GetPolicyName); + await CheckPolicyAsync(GetPolicyName); } - protected virtual void CheckGetListPolicy() + protected virtual async Task CheckGetListPolicyAsync() { - CheckPolicy(GetListPolicyName); + await CheckPolicyAsync(GetListPolicyName); } - protected virtual void CheckCreatePolicy() + protected virtual async Task CheckCreatePolicyAsync() { - CheckPolicy(CreatePolicyName); + await CheckPolicyAsync(CreatePolicyName); + } + + protected virtual async Task CheckUpdatePolicyAsync() + { + await CheckPolicyAsync(UpdatePolicyName); + } + + protected virtual async Task CheckDeletePolicyAsync() + { + await CheckPolicyAsync(DeletePolicyName); + } + + /// + /// Should apply sorting if needed. + /// + /// The query. + /// The input. + protected virtual IQueryable ApplySorting(IQueryable query, TGetListInput input) + { + //Try to sort query if available + var sortInput = input as ISortedResultRequest; + if (sortInput != null) + { + if (!sortInput.Sorting.IsNullOrWhiteSpace()) + { + return query.OrderBy(sortInput.Sorting); + } + } + + //IQueryable.Task requires sorting, so we should sort if Take will be used. + if (input is ILimitedResultRequest) + { + return query.OrderByDescending(e => e.Id); + } + + //No sorting + return query; + } + + /// + /// Should apply paging if needed. + /// + /// The query. + /// The input. + protected virtual IQueryable ApplyPaging(IQueryable query, TGetListInput input) + { + //Try to use paging if available + var pagedInput = input as IPagedResultRequest; + if (pagedInput != null) + { + return query.PageBy(pagedInput); + } + + //Try to limit query result if available + var limitedInput = input as ILimitedResultRequest; + if (limitedInput != null) + { + return query.Take(limitedInput.MaxResultCount); + } + + //No paging + return query; + } + + /// + /// This method should create based on given input. + /// It should filter query if needed, but should not do sorting or paging. + /// Sorting should be done in and paging should be done in + /// methods. + /// + /// The input. + protected virtual IQueryable CreateFilteredQuery(TGetListInput input) + { + return Repository; + } + + /// + /// Maps to . + /// It uses by default. + /// It can be overriden for custom mapping. + /// + protected virtual TGetOutputDto MapToGetOutputDto(TEntity entity) + { + return ObjectMapper.Map(entity); + } + + /// + /// Maps to . + /// It uses by default. + /// It can be overriden for custom mapping. + /// + protected virtual TGetListOutputDto MapToGetListOutputDto(TEntity entity) + { + return ObjectMapper.Map(entity); + } + + /// + /// Maps to to create a new entity. + /// It uses by default. + /// It can be overriden for custom mapping. + /// + protected virtual TEntity MapToEntity(TCreateInput createInput) + { + var entity = ObjectMapper.Map(createInput); + SetIdForGuids(entity); + return entity; + } + + /// + /// Sets Id value for the entity if is . + /// It's used while creating a new entity. + /// + protected virtual void SetIdForGuids(TEntity entity) + { + var entityWithGuidId = entity as IEntity; + + if (entityWithGuidId == null || entityWithGuidId.Id != Guid.Empty) + { + return; + } + + entityWithGuidId.Id = GuidGenerator.Create(); + } + + /// + /// Maps to to update the entity. + /// It uses by default. + /// It can be overriden for custom mapping. + /// + protected virtual void MapToEntity(TUpdateInput updateInput, TEntity entity) + { + if (updateInput is IEntityDto entityDto) + { + entityDto.Id = entity.Id; + } + + ObjectMapper.Map(updateInput, entity); } - protected virtual void CheckUpdatePolicy() + protected virtual void TryToSetTenantId(TEntity entity) { - CheckPolicy(UpdatePolicyName); + if (entity is IMultiTenant && HasTenantIdProperty(entity)) + { + var tenantId = CurrentTenant.Id; + + if (!tenantId.HasValue) + { + return; + } + + var propertyInfo = entity.GetType().GetProperty(nameof(IMultiTenant.TenantId)); + + if (propertyInfo != null && propertyInfo.GetSetMethod() != null) + { + propertyInfo.SetValue(entity, tenantId, null); + } + } } - protected virtual void CheckDeletePolicy() + protected virtual bool HasTenantIdProperty(TEntity entity) { - CheckPolicy(DeletePolicyName); + return entity.GetType().GetProperty(nameof(IMultiTenant.TenantId)) != null; } } } diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppServiceBase.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppServiceBase.cs deleted file mode 100644 index d504119a16..0000000000 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppServiceBase.cs +++ /dev/null @@ -1,191 +0,0 @@ -using System; -using System.Linq; -using System.Linq.Dynamic.Core; -using Volo.Abp.Application.Dtos; -using Volo.Abp.Domain.Entities; -using Volo.Abp.Domain.Repositories; -using Volo.Abp.MultiTenancy; -using Volo.Abp.ObjectMapping; - -namespace Volo.Abp.Application.Services -{ - /// - /// This is a common base class for CrudAppService and AsyncCrudAppService classes. - /// Inherit either from CrudAppService or AsyncCrudAppService, not from this class. - /// - public abstract class CrudAppServiceBase : - ApplicationService - where TEntity : class, IEntity - where TGetOutputDto : IEntityDto - where TGetListOutputDto : IEntityDto - { - protected IRepository Repository { get; } - - protected virtual string GetPolicyName { get; set; } - - protected virtual string GetListPolicyName { get; set; } - - protected virtual string CreatePolicyName { get; set; } - - protected virtual string UpdatePolicyName { get; set; } - - protected virtual string DeletePolicyName { get; set; } - - protected CrudAppServiceBase(IRepository repository) - { - Repository = repository; - } - - /// - /// Should apply sorting if needed. - /// - /// The query. - /// The input. - protected virtual IQueryable ApplySorting(IQueryable query, TGetListInput input) - { - //Try to sort query if available - var sortInput = input as ISortedResultRequest; - if (sortInput != null) - { - if (!sortInput.Sorting.IsNullOrWhiteSpace()) - { - return query.OrderBy(sortInput.Sorting); - } - } - - //IQueryable.Task requires sorting, so we should sort if Take will be used. - if (input is ILimitedResultRequest) - { - return query.OrderByDescending(e => e.Id); - } - - //No sorting - return query; - } - - /// - /// Should apply paging if needed. - /// - /// The query. - /// The input. - protected virtual IQueryable ApplyPaging(IQueryable query, TGetListInput input) - { - //Try to use paging if available - var pagedInput = input as IPagedResultRequest; - if (pagedInput != null) - { - return query.PageBy(pagedInput); - } - - //Try to limit query result if available - var limitedInput = input as ILimitedResultRequest; - if (limitedInput != null) - { - return query.Take(limitedInput.MaxResultCount); - } - - //No paging - return query; - } - - /// - /// This method should create based on given input. - /// It should filter query if needed, but should not do sorting or paging. - /// Sorting should be done in and paging should be done in - /// methods. - /// - /// The input. - protected virtual IQueryable CreateFilteredQuery(TGetListInput input) - { - return Repository; - } - - /// - /// Maps to . - /// It uses by default. - /// It can be overriden for custom mapping. - /// - protected virtual TGetOutputDto MapToGetOutputDto(TEntity entity) - { - return ObjectMapper.Map(entity); - } - - /// - /// Maps to . - /// It uses by default. - /// It can be overriden for custom mapping. - /// - protected virtual TGetListOutputDto MapToGetListOutputDto(TEntity entity) - { - return ObjectMapper.Map(entity); - } - - /// - /// Maps to to create a new entity. - /// It uses by default. - /// It can be overriden for custom mapping. - /// - protected virtual TEntity MapToEntity(TCreateInput createInput) - { - var entity = ObjectMapper.Map(createInput); - SetIdForGuids(entity); - return entity; - } - - /// - /// Sets Id value for the entity if is . - /// It's used while creating a new entity. - /// - protected virtual void SetIdForGuids(TEntity entity) - { - var entityWithGuidId = entity as IEntity; - - if (entityWithGuidId == null || entityWithGuidId.Id != Guid.Empty) - { - return; - } - - entityWithGuidId.Id = GuidGenerator.Create(); - } - - /// - /// Maps to to update the entity. - /// It uses by default. - /// It can be overriden for custom mapping. - /// - protected virtual void MapToEntity(TUpdateInput updateInput, TEntity entity) - { - if (updateInput is IEntityDto entityDto) - { - entityDto.Id = entity.Id; - } - - ObjectMapper.Map(updateInput, entity); - } - - protected virtual void TryToSetTenantId(TEntity entity) - { - if (entity is IMultiTenant && HasTenantIdProperty(entity)) - { - var tenantId = CurrentTenant.Id; - - if (!tenantId.HasValue) - { - return; - } - - var propertyInfo = entity.GetType().GetProperty(nameof(IMultiTenant.TenantId)); - - if (propertyInfo != null && propertyInfo.GetSetMethod() != null) - { - propertyInfo.SetValue(entity, tenantId, null); - } - } - } - - protected virtual bool HasTenantIdProperty(TEntity entity) - { - return entity.GetType().GetProperty(nameof(IMultiTenant.TenantId)) != null; - } - } -} diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IAsyncCrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IAsyncCrudAppService.cs deleted file mode 100644 index 8f07cb2412..0000000000 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IAsyncCrudAppService.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Threading.Tasks; -using Volo.Abp.Application.Dtos; - -namespace Volo.Abp.Application.Services -{ - public interface IAsyncCrudAppService - : IAsyncCrudAppService - where TEntityDto : IEntityDto - { - - } - - public interface IAsyncCrudAppService - : IAsyncCrudAppService - where TEntityDto : IEntityDto - { - - } - - public interface IAsyncCrudAppService - : IAsyncCrudAppService - where TEntityDto : IEntityDto - { - - } - - public interface IAsyncCrudAppService - : IAsyncCrudAppService - where TEntityDto : IEntityDto - { - - } - - public interface IAsyncCrudAppService - : IApplicationService - where TGetOutputDto : IEntityDto - where TGetListOutputDto : IEntityDto - { - Task GetAsync(TKey id); - - Task> GetListAsync(TGetListInput input); - - Task CreateAsync(TCreateInput input); - - Task UpdateAsync(TKey id, TUpdateInput input); - - Task DeleteAsync(TKey id); - } -} diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ICrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ICrudAppService.cs index 2f3b770849..7816bd20eb 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ICrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ICrudAppService.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Volo.Abp.Application.Dtos; namespace Volo.Abp.Application.Services @@ -24,7 +25,7 @@ namespace Volo.Abp.Application.Services } public interface ICrudAppService - : ICrudAppService + : ICrudAppService where TEntityDto : IEntityDto { @@ -35,14 +36,14 @@ namespace Volo.Abp.Application.Services where TGetOutputDto : IEntityDto where TGetListOutputDto : IEntityDto { - TGetOutputDto Get(TKey id); + Task GetAsync(TKey id); - PagedResultDto GetList(TGetListInput input); + Task> GetListAsync(TGetListInput input); - TGetOutputDto Create(TCreateInput input); + Task CreateAsync(TCreateInput input); - TGetOutputDto Update(TKey id, TUpdateInput input); + Task UpdateAsync(TKey id, TUpdateInput input); - void Delete(TKey id); + Task DeleteAsync(TKey id); } } diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs index 029ee5cd3c..40ebca015e 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs @@ -5,7 +5,6 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Entities; using Volo.Abp.DynamicProxy; -using Volo.Abp.Threading; namespace Volo.Abp.Domain.Repositories { @@ -27,17 +26,6 @@ namespace Volo.Abp.Domain.Repositories } } - public static void EnsureCollectionLoaded( - this IBasicRepository repository, - TEntity entity, - Expression>> propertyExpression - ) - where TEntity : class, IEntity - where TProperty : class - { - AsyncHelper.RunSync(() => repository.EnsureCollectionLoadedAsync(entity, propertyExpression)); - } - public static async Task EnsurePropertyLoadedAsync( this IBasicRepository repository, TEntity entity, @@ -53,16 +41,5 @@ namespace Volo.Abp.Domain.Repositories await repo.EnsurePropertyLoadedAsync(entity, propertyExpression, cancellationToken); } } - - public static void EnsurePropertyLoaded( - this IBasicRepository repository, - TEntity entity, - Expression> propertyExpression - ) - where TEntity : class, IEntity - where TProperty : class - { - AsyncHelper.RunSync(() => repository.EnsurePropertyLoadedAsync(entity, propertyExpression)); - } } } diff --git a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/BackgroundEmailSendingJob.cs b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/BackgroundEmailSendingJob.cs index 6aca2403cc..f471fecaa1 100644 --- a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/BackgroundEmailSendingJob.cs +++ b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/BackgroundEmailSendingJob.cs @@ -1,5 +1,6 @@ using Volo.Abp.BackgroundJobs; using Volo.Abp.DependencyInjection; +using Volo.Abp.Threading; namespace Volo.Abp.Emailing { @@ -14,7 +15,7 @@ namespace Volo.Abp.Emailing public override void Execute(BackgroundEmailSendingJobArgs args) { - EmailSender.Send(args.To, args.Subject, args.Body, args.IsBodyHtml); + AsyncHelper.RunSync(() => EmailSender.SendAsync(args.To, args.Subject, args.Body, args.IsBodyHtml)); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/EmailSenderBase.cs b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/EmailSenderBase.cs index 8ae737043b..f6588de9fb 100644 --- a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/EmailSenderBase.cs +++ b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/EmailSenderBase.cs @@ -3,7 +3,6 @@ using System.Net.Mail; using System.Text; using System.Threading.Tasks; using Volo.Abp.BackgroundJobs; -using Volo.Abp.Threading; namespace Volo.Abp.Emailing { @@ -36,27 +35,11 @@ namespace Volo.Abp.Emailing }); } - public virtual void Send(string to, string subject, string body, bool isBodyHtml = true) - { - Send(new MailMessage - { - To = { to }, - Subject = subject, - Body = body, - IsBodyHtml = isBodyHtml - }); - } - public virtual async Task SendAsync(string from, string to, string subject, string body, bool isBodyHtml = true) { await SendAsync(new MailMessage(from, to, subject, body) { IsBodyHtml = isBodyHtml }); } - public virtual void Send(string from, string to, string subject, string body, bool isBodyHtml = true) - { - Send(new MailMessage(from, to, subject, body) { IsBodyHtml = isBodyHtml }); - } - public virtual async Task SendAsync(MailMessage mail, bool normalize = true) { if (normalize) @@ -86,28 +69,12 @@ namespace Volo.Abp.Emailing ); } - public virtual void Send(MailMessage mail, bool normalize = true) - { - if (normalize) - { - AsyncHelper.RunSync(() => NormalizeMailAsync(mail)); - } - - SendEmail(mail); - } - /// /// Should implement this method to send email in derived classes. /// /// Mail to be sent protected abstract Task SendEmailAsync(MailMessage mail); - /// - /// Should implement this method to send email in derived classes. - /// - /// Mail to be sent - protected abstract void SendEmail(MailMessage mail); - /// /// Normalizes given email. /// Fills if it's not filled before. diff --git a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/IEmailSender.cs b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/IEmailSender.cs index 999469ce0c..612d8f078c 100644 --- a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/IEmailSender.cs +++ b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/IEmailSender.cs @@ -13,31 +13,11 @@ namespace Volo.Abp.Emailing /// Task SendAsync(string to, string subject, string body, bool isBodyHtml = true); - /// - /// Sends an email. - /// - void Send(string to, string subject, string body, bool isBodyHtml = true); - /// /// Sends an email. /// Task SendAsync(string from, string to, string subject, string body, bool isBodyHtml = true); - /// - /// Sends an email. - /// - void Send(string from, string to, string subject, string body, bool isBodyHtml = true); - - /// - /// Sends an email. - /// - /// Mail to be sent - /// - /// Should normalize email? - /// If true, it sets sender address/name if it's not set before and makes mail encoding UTF-8. - /// - void Send(MailMessage mail, bool normalize = true); - /// /// Sends an email. /// diff --git a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/NullEmailSender.cs b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/NullEmailSender.cs index 1a2949c148..f0f7238484 100644 --- a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/NullEmailSender.cs +++ b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/NullEmailSender.cs @@ -31,13 +31,6 @@ namespace Volo.Abp.Emailing return Task.FromResult(0); } - protected override void SendEmail(MailMessage mail) - { - Logger.LogWarning("USING NullEmailSender!"); - Logger.LogWarning("SendEmail:"); - LogEmail(mail); - } - private void LogEmail(MailMessage mail) { Logger.LogDebug(mail.To.ToString()); diff --git a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/Smtp/SmtpEmailSender.cs b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/Smtp/SmtpEmailSender.cs index f7f431eaca..f97fd57b18 100644 --- a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/Smtp/SmtpEmailSender.cs +++ b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/Smtp/SmtpEmailSender.cs @@ -75,13 +75,5 @@ namespace Volo.Abp.Emailing.Smtp await smtpClient.SendMailAsync(mail); } } - - protected override void SendEmail(MailMessage mail) - { - using (var smtpClient = AsyncHelper.RunSync(BuildClientAsync)) - { - smtpClient.Send(mail); - } - } } } diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusExtensions.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusExtensions.cs deleted file mode 100644 index 5139e1cbcb..0000000000 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusExtensions.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using JetBrains.Annotations; -using Volo.Abp.Threading; - -namespace Volo.Abp.EventBus -{ - public static class EventBusExtensions - { - /// - /// Triggers an event. - /// - /// Event type - /// Event bus instance - /// Related data for the event - public static void Publish([NotNull] this IEventBus eventBus, [NotNull] TEvent eventData) - where TEvent : class - { - Check.NotNull(eventBus, nameof(eventBus)); - - AsyncHelper.RunSync(() => eventBus.PublishAsync(eventData)); - } - - /// - /// Triggers an event. - /// - /// Event bus instance - /// Event type - /// Related data for the event - public static void Publish([NotNull] this IEventBus eventBus, [NotNull] Type eventType, [NotNull] object eventData) - { - Check.NotNull(eventBus, nameof(eventBus)); - - AsyncHelper.RunSync(() => eventBus.PublishAsync(eventType, eventData)); - } - } -} diff --git a/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureCheckerExtensions.cs b/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureCheckerExtensions.cs index 9d7f608c4b..8850408df0 100644 --- a/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureCheckerExtensions.cs +++ b/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureCheckerExtensions.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using JetBrains.Annotations; using Volo.Abp.Authorization; -using Volo.Abp.Threading; namespace Volo.Abp.Features { @@ -22,30 +21,6 @@ namespace Volo.Abp.Features return value?.To() ?? defaultValue; } - public static string GetOrNull( - [NotNull] this IFeatureChecker featureChecker, - [NotNull] string name) - { - Check.NotNull(featureChecker, nameof(featureChecker)); - return AsyncHelper.RunSync(() => featureChecker.GetOrNullAsync(name)); - } - - public static T Get( - [NotNull] this IFeatureChecker featureChecker, - [NotNull] string name, - T defaultValue = default) - where T : struct - { - return AsyncHelper.RunSync(() => featureChecker.GetAsync(name, defaultValue)); - } - - public static bool IsEnabled( - [NotNull] this IFeatureChecker featureChecker, - [NotNull] string name) - { - return AsyncHelper.RunSync(() => featureChecker.IsEnabledAsync(name)); - } - public static async Task IsEnabledAsync(this IFeatureChecker featureChecker, bool requiresAll, params string[] featureNames) { if (featureNames.IsNullOrEmpty()) @@ -77,11 +52,6 @@ namespace Volo.Abp.Features return false; } - public static bool IsEnabled(this IFeatureChecker featureChecker, bool requiresAll, params string[] featureNames) - { - return AsyncHelper.RunSync(() => featureChecker.IsEnabledAsync(requiresAll, featureNames)); - } - public static async Task CheckEnabledAsync(this IFeatureChecker featureChecker, string featureName) { if (!(await featureChecker.IsEnabledAsync(featureName))) @@ -89,15 +59,7 @@ namespace Volo.Abp.Features throw new AbpAuthorizationException("Feature is not enabled: " + featureName); } } - - public static void CheckEnabled(this IFeatureChecker featureChecker, string featureName) - { - if (!featureChecker.IsEnabled(featureName)) - { - throw new AbpAuthorizationException("Feature is not enabled: " + featureName); - } - } - + public static async Task CheckEnabledAsync(this IFeatureChecker featureChecker, bool requiresAll, params string[] featureNames) { if (featureNames.IsNullOrEmpty()) @@ -134,10 +96,5 @@ namespace Volo.Abp.Features ); } } - - public static void CheckEnabled(this IFeatureChecker featureChecker, bool requiresAll, params string[] featureNames) - { - AsyncHelper.RunSync(() => featureChecker.CheckEnabledAsync(requiresAll, featureNames)); - } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureInterceptor.cs b/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureInterceptor.cs index a0b15674f6..5fb7c54293 100644 --- a/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureInterceptor.cs +++ b/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureInterceptor.cs @@ -18,9 +18,7 @@ namespace Volo.Abp.Features public override void Intercept(IAbpMethodInvocation invocation) { - if (AbpCrossCuttingConcerns.IsApplied( - invocation.TargetObject, - AbpCrossCuttingConcerns.FeatureChecking)) + if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.FeatureChecking)) { invocation.Proceed(); return; @@ -32,21 +30,19 @@ namespace Volo.Abp.Features public override async Task InterceptAsync(IAbpMethodInvocation invocation) { - if (AbpCrossCuttingConcerns.IsApplied( - invocation.TargetObject, - AbpCrossCuttingConcerns.FeatureChecking)) + if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.FeatureChecking)) { await invocation.ProceedAsync(); return; } - AsyncHelper.RunSync(() => CheckFeaturesAsync(invocation)); + await CheckFeaturesAsync(invocation); await invocation.ProceedAsync(); } - protected virtual Task CheckFeaturesAsync(IAbpMethodInvocation invocation) + protected virtual async Task CheckFeaturesAsync(IAbpMethodInvocation invocation) { - return _methodInvocationFeatureCheckerService.CheckAsync( + await _methodInvocationFeatureCheckerService.CheckAsync( new MethodInvocationFeatureCheckerContext( invocation.Method ) diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IRemoteServiceHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IRemoteServiceHttpClientAuthenticator.cs index 920d38f2e6..480ba049e6 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IRemoteServiceHttpClientAuthenticator.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IRemoteServiceHttpClientAuthenticator.cs @@ -4,6 +4,6 @@ namespace Volo.Abp.Http.Client.Authentication { public interface IRemoteServiceHttpClientAuthenticator { - Task Authenticate(RemoteServiceHttpClientAuthenticateContext context); + Task Authenticate(RemoteServiceHttpClientAuthenticateContext context); //TODO: Rename to AuthenticateAsync } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/LanguageProviderExtensions.cs b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/LanguageProviderExtensions.cs deleted file mode 100644 index 951292ac66..0000000000 --- a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/LanguageProviderExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; -using Volo.Abp.Threading; - -namespace Volo.Abp.Localization -{ - public static class LanguageProviderExtensions - { - public static IReadOnlyList GetLanguages(this ILanguageProvider languageProvider) - { - return AsyncHelper.RunSync(languageProvider.GetLanguagesAsync); - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 2e993ebecb..cddebd253d 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -88,11 +88,11 @@ namespace Volo.Abp.Domain.Repositories.MongoDB if (entity is ISoftDelete softDeleteEntity && softDeleteEntity.IsDeleted) { SetDeletionAuditProperties(entity); - AsyncHelper.RunSync(() => TriggerEntityDeleteEvents(entity)); + AsyncHelper.RunSync(() => TriggerEntityDeleteEventsAsync(entity)); } else { - AsyncHelper.RunSync(() => TriggerEntityUpdateEvents(entity)); + AsyncHelper.RunSync(() => TriggerEntityUpdateEventsAsync(entity)); } AsyncHelper.RunSync(() => TriggerDomainEventsAsync(entity)); @@ -122,11 +122,11 @@ namespace Volo.Abp.Domain.Repositories.MongoDB if (entity is ISoftDelete softDeleteEntity && softDeleteEntity.IsDeleted) { SetDeletionAuditProperties(entity); - await TriggerEntityDeleteEvents(entity); + await TriggerEntityDeleteEventsAsync(entity); } else { - await TriggerEntityUpdateEvents(entity); + await TriggerEntityUpdateEventsAsync(entity); } await TriggerDomainEventsAsync(entity); @@ -294,7 +294,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB await EntityChangeEventHelper.TriggerEntityCreatingEventAsync(entity); } - protected virtual async Task TriggerEntityUpdateEvents(TEntity entity) + protected virtual async Task TriggerEntityUpdateEventsAsync(TEntity entity) { await EntityChangeEventHelper.TriggerEntityUpdatedEventOnUowCompletedAsync(entity); await EntityChangeEventHelper.TriggerEntityUpdatingEventAsync(entity); @@ -303,11 +303,11 @@ namespace Volo.Abp.Domain.Repositories.MongoDB protected virtual async Task ApplyAbpConceptsForDeletedEntityAsync(TEntity entity) { SetDeletionAuditProperties(entity); - await TriggerEntityDeleteEvents(entity); + await TriggerEntityDeleteEventsAsync(entity); await TriggerDomainEventsAsync(entity); } - protected virtual async Task TriggerEntityDeleteEvents(TEntity entity) + protected virtual async Task TriggerEntityDeleteEventsAsync(TEntity entity) { await EntityChangeEventHelper.TriggerEntityDeletedEventOnUowCompletedAsync(entity); await EntityChangeEventHelper.TriggerEntityDeletingEventAsync(entity); diff --git a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ConfigurationStore/DefaultTenantStore.cs b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ConfigurationStore/DefaultTenantStore.cs index 3e6ea4167a..edecf22b65 100644 --- a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ConfigurationStore/DefaultTenantStore.cs +++ b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ConfigurationStore/DefaultTenantStore.cs @@ -18,12 +18,22 @@ namespace Volo.Abp.MultiTenancy.ConfigurationStore public Task FindAsync(string name) { - return Task.FromResult(_options.Tenants?.FirstOrDefault(t => t.Name == name)); + return Task.FromResult(Find(name)); } public Task FindAsync(Guid id) { - return Task.FromResult(_options.Tenants?.FirstOrDefault(t => t.Id == id)); + return Task.FromResult(Find(id)); + } + + public TenantConfiguration Find(string name) + { + return _options.Tenants?.FirstOrDefault(t => t.Name == name); + } + + public TenantConfiguration Find(Guid id) + { + return _options.Tenants?.FirstOrDefault(t => t.Id == id); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantStore.cs b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantStore.cs index b1c8f97f1a..7125a97405 100644 --- a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantStore.cs +++ b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantStore.cs @@ -8,5 +8,9 @@ namespace Volo.Abp.MultiTenancy Task FindAsync(string name); Task FindAsync(Guid id); + + TenantConfiguration Find(string name); + + TenantConfiguration Find(Guid id); } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantConnectionStringResolver.cs b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantConnectionStringResolver.cs index af5674a9b4..fe061d0b8d 100644 --- a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantConnectionStringResolver.cs +++ b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantConnectionStringResolver.cs @@ -4,7 +4,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; -using Volo.Abp.Threading; namespace Volo.Abp.MultiTenancy { @@ -38,7 +37,7 @@ namespace Volo.Abp.MultiTenancy .ServiceProvider .GetRequiredService(); - var tenant = AsyncHelper.RunSync(() => tenantStore.FindAsync(_currentTenant.Id.Value)); //TODO: Can we avoid from RunSync? + var tenant = tenantStore.Find(_currentTenant.Id.Value); if (tenant?.ConnectionStrings == null) { diff --git a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantStoreExtensions.cs b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantStoreExtensions.cs deleted file mode 100644 index 290c683d95..0000000000 --- a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantStoreExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using JetBrains.Annotations; -using Volo.Abp.Threading; - -namespace Volo.Abp.MultiTenancy -{ - public static class TenantStoreExtensions - { - [CanBeNull] - public static TenantConfiguration Find(this ITenantStore tenantStore, string name) - { - return AsyncHelper.RunSync(() => tenantStore.FindAsync(name)); - } - - [CanBeNull] - public static TenantConfiguration Find(this ITenantStore tenantStore, Guid id) - { - return AsyncHelper.RunSync(() => tenantStore.FindAsync(id)); - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs index a56fc2491a..1214a82a99 100644 --- a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs +++ b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/RabbitMqMessageConsumer.cs @@ -72,7 +72,7 @@ namespace Volo.Abp.RabbitMQ await TrySendQueueBindCommandsAsync(); } - protected virtual Task TrySendQueueBindCommandsAsync() + protected virtual void TrySendQueueBindCommands() { try { @@ -80,7 +80,7 @@ namespace Volo.Abp.RabbitMQ { if (Channel == null || Channel.IsClosed) { - return Task.CompletedTask; + return; } lock (ChannelSendSyncLock) @@ -115,7 +115,11 @@ namespace Volo.Abp.RabbitMQ { Logger.LogException(ex, LogLevel.Warning); } + } + protected virtual Task TrySendQueueBindCommandsAsync() + { + TrySendQueueBindCommands(); return Task.CompletedTask; } @@ -129,7 +133,7 @@ namespace Volo.Abp.RabbitMQ if (Channel == null || Channel.IsOpen == false) { TryCreateChannel(); - AsyncHelper.RunSync(TrySendQueueBindCommandsAsync); + TrySendQueueBindCommands(); } } diff --git a/framework/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingProviderExtensions.cs b/framework/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingProviderExtensions.cs index d3f372baca..fb67c4ae77 100644 --- a/framework/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingProviderExtensions.cs +++ b/framework/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingProviderExtensions.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; using JetBrains.Annotations; -using Volo.Abp.Threading; namespace Volo.Abp.Settings { @@ -29,28 +27,5 @@ namespace Volo.Abp.Settings var value = await settingProvider.GetOrNullAsync(name); return value?.To() ?? defaultValue; } - - public static string GetOrNull([NotNull] this ISettingProvider settingProvider, [NotNull] string name) - { - Check.NotNull(settingProvider, nameof(settingProvider)); - return AsyncHelper.RunSync(() => settingProvider.GetOrNullAsync(name)); - } - - public static List GetAll([NotNull] this ISettingProvider settingProvider) - { - Check.NotNull(settingProvider, nameof(settingProvider)); - return AsyncHelper.RunSync(settingProvider.GetAllAsync); - } - - public static T Get([NotNull] this ISettingProvider settingProvider, [NotNull] string name, T defaultValue = default) - where T : struct - { - return AsyncHelper.RunSync(() => settingProvider.GetAsync(name, defaultValue)); - } - - public static bool IsTrue([NotNull] this ISettingProvider settingProvider, [NotNull] string name) - { - return AsyncHelper.RunSync(() => settingProvider.IsTrueAsync(name)); - } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AbpTimer.cs b/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AbpTimer.cs index 4733ce01e2..cae8ac984f 100644 --- a/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AbpTimer.cs +++ b/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AbpTimer.cs @@ -1,6 +1,5 @@ using System; using System.Threading; -using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.DependencyInjection; @@ -10,7 +9,7 @@ namespace Volo.Abp.Threading /// /// A roboust timer implementation that ensures no overlapping occurs. It waits exactly specified between ticks. /// - public class AbpTimer : IRunnable, ITransientDependency + public class AbpTimer : ITransientDependency { /// /// This event is raised periodically according to Period of Timer. @@ -41,7 +40,7 @@ namespace Volo.Abp.Threading _taskTimer = new Timer(TimerCallBack, null, Timeout.Infinite, Timeout.Infinite); } - public Task StartAsync(CancellationToken cancellationToken = default) + public void Start(CancellationToken cancellationToken = default) { if (Period <= 0) { @@ -53,11 +52,9 @@ namespace Volo.Abp.Threading _taskTimer.Change(RunOnStart ? 0 : Period, Timeout.Infinite); _isRunning = true; } - - return Task.CompletedTask; } - public Task StopAsync(CancellationToken cancellationToken = default) + public void Stop(CancellationToken cancellationToken = default) { lock (_taskTimer) { @@ -69,8 +66,6 @@ namespace Volo.Abp.Threading _isRunning = false; } - - return Task.CompletedTask; } /// diff --git a/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/RunnableExtensions.cs b/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/RunnableExtensions.cs deleted file mode 100644 index 0fec7986fb..0000000000 --- a/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/RunnableExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -using JetBrains.Annotations; - -namespace Volo.Abp.Threading -{ - public static class RunnableExtensions - { - public static void Start([NotNull] this IRunnable runnable) - { - Check.NotNull(runnable, nameof(runnable)); - - AsyncHelper.RunSync(() => runnable.StartAsync()); - } - - public static void Stop([NotNull] this IRunnable runnable) - { - Check.NotNull(runnable, nameof(runnable)); - - AsyncHelper.RunSync(() => runnable.StopAsync()); - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuItem.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuItem.cs index d3ed32be85..d4960c883e 100644 --- a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuItem.cs +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuItem.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using JetBrains.Annotations; -using Volo.Abp.UI.Navigation; namespace Volo.Abp.UI.Navigation { diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/ValidationInterceptor.cs b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/ValidationInterceptor.cs index c7fedec8db..594a19535e 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/ValidationInterceptor.cs +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/ValidationInterceptor.cs @@ -1,7 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Volo.Abp.Aspects; using Volo.Abp.DependencyInjection; using Volo.Abp.DynamicProxy; diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs index 6317d7d8ce..cf2393869d 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs @@ -6,7 +6,7 @@ using Volo.Abp.TestApp.Application.Dto; namespace Volo.Abp.TestApp.Application { - public interface IPeopleAppService : IAsyncCrudAppService + public interface IPeopleAppService : ICrudAppService { Task> GetPhones(Guid id, GetPersonPhonesFilter filter); diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs index ef76becbc5..e21cc14d08 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs @@ -10,7 +10,7 @@ using Volo.Abp.TestApp.Application.Dto; namespace Volo.Abp.TestApp.Application { - public class PeopleAppService : AsyncCrudAppService, IPeopleAppService + public class PeopleAppService : CrudAppService, IPeopleAppService { public PeopleAppService(IRepository repository) : base(repository) diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs index fed3718f85..eda224153f 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs @@ -19,6 +19,13 @@ namespace Volo.Abp.BackgroundJobs BackgroundJobRepository = backgroundJobRepository; } + public BackgroundJobInfo Find(Guid jobId) + { + return ObjectMapper.Map( + BackgroundJobRepository.Find(jobId) + ); + } + public virtual async Task FindAsync(Guid jobId) { return ObjectMapper.Map( @@ -26,6 +33,13 @@ namespace Volo.Abp.BackgroundJobs ); } + public void Insert(BackgroundJobInfo jobInfo) + { + BackgroundJobRepository.Insert( + ObjectMapper.Map(jobInfo) + ); + } + public virtual async Task InsertAsync(BackgroundJobInfo jobInfo) { await BackgroundJobRepository.InsertAsync( @@ -33,6 +47,13 @@ namespace Volo.Abp.BackgroundJobs ); } + public List GetWaitingJobs(int maxResultCount) + { + return ObjectMapper.Map, List>( + BackgroundJobRepository.GetWaitingList(maxResultCount) + ); + } + public virtual async Task> GetWaitingJobsAsync(int maxResultCount) { return ObjectMapper.Map, List>( @@ -40,11 +61,23 @@ namespace Volo.Abp.BackgroundJobs ); } + public void Delete(Guid jobId) + { + BackgroundJobRepository.Delete(jobId); + } + public virtual async Task DeleteAsync(Guid jobId) { await BackgroundJobRepository.DeleteAsync(jobId); } + public void Update(BackgroundJobInfo jobInfo) + { + BackgroundJobRepository.Update( + ObjectMapper.Map(jobInfo) + ); + } + public virtual async Task UpdateAsync(BackgroundJobInfo jobInfo) { await BackgroundJobRepository.UpdateAsync( diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs index e12aeff70a..a34cbd6abb 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs @@ -7,6 +7,8 @@ namespace Volo.Abp.BackgroundJobs { public interface IBackgroundJobRepository : IBasicRepository { + List GetWaitingList(int maxResultCount); + Task> GetWaitingListAsync(int maxResultCount); } } \ No newline at end of file diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs index 28d86f589a..8128d18bfb 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs @@ -21,16 +21,27 @@ namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore Clock = clock; } + public List GetWaitingList(int maxResultCount) + { + return GetWaitingListQuery(maxResultCount) + .ToList(); + } + public async Task> GetWaitingListAsync(int maxResultCount) + { + return await GetWaitingListQuery(maxResultCount) + .ToListAsync(); + } + + private IQueryable GetWaitingListQuery(int maxResultCount) { var now = Clock.Now; - return await DbSet + return DbSet .Where(t => !t.IsAbandoned && t.NextTryTime <= now) .OrderByDescending(t => t.Priority) .ThenBy(t => t.TryCount) .ThenBy(t => t.NextTryTime) - .Take(maxResultCount) - .ToListAsync(); + .Take(maxResultCount); } } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs index 78a1238aa8..fe3ffa7e07 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs @@ -21,16 +21,27 @@ namespace Volo.Abp.BackgroundJobs.MongoDB Clock = clock; } + public List GetWaitingList(int maxResultCount) + { + return GetWaitingListQuery(maxResultCount) + .ToList(); + } + public async Task> GetWaitingListAsync(int maxResultCount) + { + return await GetWaitingListQuery(maxResultCount) + .ToListAsync(); + } + + private IMongoQueryable GetWaitingListQuery(int maxResultCount) { var now = Clock.Now; - return await GetMongoQueryable() + return GetMongoQueryable() .Where(t => !t.IsAbandoned && t.NextTryTime <= now) .OrderByDescending(t => t.Priority) .ThenBy(t => t.TryCount) .ThenBy(t => t.NextTryTime) - .Take(maxResultCount) - .ToListAsync(); + .Take(maxResultCount); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityRoleAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityRoleAppService.cs index cc72600e16..0d8f19f796 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityRoleAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityRoleAppService.cs @@ -5,7 +5,7 @@ using Volo.Abp.Application.Services; namespace Volo.Abp.Identity { - public interface IIdentityRoleAppService : IAsyncCrudAppService + public interface IIdentityRoleAppService : ICrudAppService { //TODO: remove after a better design Task> GetAllListAsync(); diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs index f3e342503c..a68552d653 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs @@ -5,7 +5,7 @@ using Volo.Abp.Application.Services; namespace Volo.Abp.Identity { - public interface IIdentityUserAppService : IAsyncCrudAppService + public interface IIdentityUserAppService : ICrudAppService { Task> GetRolesAsync(Guid id); diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/ITenantAppService.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/ITenantAppService.cs index 637134abb3..cd5f0697f7 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/ITenantAppService.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/ITenantAppService.cs @@ -4,7 +4,7 @@ using Volo.Abp.Application.Services; namespace Volo.Abp.TenantManagement { - public interface ITenantAppService : IAsyncCrudAppService + public interface ITenantAppService : ICrudAppService { Task GetDefaultConnectionStringAsync(Guid id); diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/ITenantRepository.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/ITenantRepository.cs index 7b1c7e15f1..59f9aedc85 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/ITenantRepository.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/ITenantRepository.cs @@ -13,6 +13,11 @@ namespace Volo.Abp.TenantManagement bool includeDetails = true, CancellationToken cancellationToken = default); + Tenant FindByName( + string name, + bool includeDetails = true + ); + Task> GetListAsync( string sorting = null, int maxResultCount = int.MaxValue, diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantStore.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantStore.cs index 1a32c4a64d..1cd1c60c0a 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantStore.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantStore.cs @@ -51,5 +51,33 @@ namespace Volo.Abp.TenantManagement return _objectMapper.Map(tenant); } } + + public TenantConfiguration Find(string name) + { + using (_currentTenant.Change(null)) //TODO: No need this if we can implement to define host side (or tenant-independent) entities! + { + var tenant = _tenantRepository.FindByName(name); + if (tenant == null) + { + return null; + } + + return _objectMapper.Map(tenant); + } + } + + public TenantConfiguration Find(Guid id) + { + using (_currentTenant.Change(null)) //TODO: No need this if we can implement to define host side (or tenant-independent) entities! + { + var tenant = _tenantRepository.Find(id); + if (tenant == null) + { + return null; + } + + return _objectMapper.Map(tenant); + } + } } } diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.EntityFrameworkCore/Volo/Abp/TenantManagement/EntityFrameworkCore/EfCoreTenantRepository.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.EntityFrameworkCore/Volo/Abp/TenantManagement/EntityFrameworkCore/EfCoreTenantRepository.cs index d2859f29a1..c1d9a3c556 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.EntityFrameworkCore/Volo/Abp/TenantManagement/EntityFrameworkCore/EfCoreTenantRepository.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.EntityFrameworkCore/Volo/Abp/TenantManagement/EntityFrameworkCore/EfCoreTenantRepository.cs @@ -25,7 +25,14 @@ namespace Volo.Abp.TenantManagement.EntityFrameworkCore { return await DbSet .IncludeDetails(includeDetails) - .FirstOrDefaultAsync(t => t.Name == name, cancellationToken); + .FirstOrDefaultAsync(t => t.Name == name, GetCancellationToken(cancellationToken)); + } + + public Tenant FindByName(string name, bool includeDetails = true) + { + return DbSet + .IncludeDetails(includeDetails) + .FirstOrDefault(t => t.Name == name); } public virtual async Task> GetListAsync( @@ -45,7 +52,7 @@ namespace Volo.Abp.TenantManagement.EntityFrameworkCore ) .OrderBy(sorting ?? nameof(Tenant.Name)) .PageBy(skipCount, maxResultCount) - .ToListAsync(cancellationToken); + .ToListAsync(GetCancellationToken(cancellationToken)); } public override IQueryable WithDetails() diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/MongoTenantRepository.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/MongoTenantRepository.cs index 0ee8c54744..aba3385cfd 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/MongoTenantRepository.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/MongoTenantRepository.cs @@ -25,7 +25,13 @@ namespace Volo.Abp.TenantManagement.MongoDB CancellationToken cancellationToken = default) { return await GetMongoQueryable() - .FirstOrDefaultAsync(t => t.Name == name, cancellationToken); + .FirstOrDefaultAsync(t => t.Name == name, GetCancellationToken(cancellationToken)); + } + + public Tenant FindByName(string name, bool includeDetails = true) + { + return GetMongoQueryable() + .FirstOrDefault(t => t.Name == name); } public virtual async Task> GetListAsync( @@ -45,7 +51,7 @@ namespace Volo.Abp.TenantManagement.MongoDB .OrderBy(sorting ?? nameof(Tenant.Name)) .As>() .PageBy>(skipCount, maxResultCount) - .ToListAsync(cancellationToken); + .ToListAsync(GetCancellationToken(cancellationToken)); } } } \ No newline at end of file