Browse Source

Reduce AsyncHelper.RunSync usage #1403

pull/1467/head
Halil İbrahim Kalkan 7 years ago
parent
commit
588dafe60c
  1. 13
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClientExtensions.cs
  2. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs
  3. 17
      framework/src/Volo.Abp.BackgroundJobs.Abstractions/Volo/Abp/BackgroundJobs/BackgroundJobManagerExtensions.cs
  4. 18
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs
  5. 18
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs
  6. 14
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs
  7. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/IConsoleCommand.cs
  8. 20
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs
  9. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs
  10. 14
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs
  11. 17
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs

13
framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClientExtensions.cs

@ -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);
}
}
}

8
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<string, string> GetResourceOrNull()
{
var resource = _applicationConfigurationClient
.Get()
var applicationConfigurationDto = AsyncHelper.RunSync(
() => _applicationConfigurationClient.GetAsync()
);
var resource = applicationConfigurationDto
.Localization.Values
.GetOrDefault(_resource.ResourceName);

17
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
/// </summary>
public static class BackgroundJobManagerExtensions
{
/// <summary>
/// Enqueues a job to be executed.
/// </summary>
/// <typeparam name="TArgs">Type of the arguments of job.</typeparam>
/// <param name="backgroundJobManager">Background job manager reference</param>
/// <param name="args">Job arguments.</param>
/// <param name="priority">Job priority.</param>
/// <param name="delay">Job delay (wait duration before first try).</param>
public static string Enqueue<TArgs>(this IBackgroundJobManager backgroundJobManager, TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null)
{
return AsyncHelper.RunSync(() => backgroundJobManager.EnqueueAsync<TArgs>(args, priority, delay));
}
/// <summary>
/// Checks if background job system has a real implementation.
/// It returns false if the current implementation is <see cref="NullBackgroundJobManager"/>.

18
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<string> 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<string> 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)

18
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<string> 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<string> 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)

14
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<string> 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<string> GetShortDescriptionAsync()
public string GetShortDescription()
{
return Task.FromResult("");
return string.Empty;
}
}
}

4
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<string> GetUsageInfo();
string GetUsageInfo();
Task<string> GetShortDescriptionAsync();
string GetShortDescription();
}
}

20
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<string> 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<string> GetShortDescriptionAsync()
public string GetShortDescription()
{
return Task.FromResult("");
return string.Empty;
}
}
}

8
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<string> GetUsageInfo()
public string GetUsageInfo()
{
return Task.FromResult("");
return string.Empty;
}
public Task<string> GetShortDescriptionAsync()
public string GetShortDescription()
{
return Task.FromResult("");
return string.Empty;
}
}
}

14
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<string> 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<string> 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)

17
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs

@ -90,11 +90,14 @@ namespace Volo.Abp.Cli.Commands
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<string> 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<string> 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

Loading…
Cancel
Save