Browse Source

Reduce AsyncHelper.RunSync usage

pull/1467/head
Halil İbrahim Kalkan 7 years ago
parent
commit
62183a9ce4
  1. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs
  2. 18
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs

8
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,7 +84,7 @@ 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;

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

Loading…
Cancel
Save