diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliConsts.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliConsts.cs index ac4747de5d..1c0cd3ace4 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliConsts.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliConsts.cs @@ -1,11 +1,4 @@ -using System.Collections.Generic; -using System.Security.Policy; -using Volo.Abp.Cli.ProjectBuilding.Templates.App; -using Volo.Abp.Cli.ProjectBuilding.Templates.Microservice; -using Volo.Abp.Cli.ProjectBuilding.Templates.Module; -using Volo.Abp.Cli.ProjectBuilding.Templates.MvcModule; - -namespace Volo.Abp.Cli; +namespace Volo.Abp.Cli; public static class CliConsts { @@ -24,4 +17,9 @@ public static class CliConsts public const string AppSettingsJsonFileName = "appsettings.json"; public const string AppSettingsSecretJsonFileName = "appsettings.secrets.json"; + + public static class MemoryKeys + { + public const string LatestCliVersionCheckDate = "LatestCliVersionCheckDate"; + } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs index e4cec4e2c4..99ba8fbe7e 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs @@ -10,6 +10,7 @@ public static class CliPaths public static string Log => Path.Combine(AbpRootPath, "cli", "logs"); public static string Root => Path.Combine(AbpRootPath, "cli"); public static string AccessToken => Path.Combine(AbpRootPath, "cli", "access-token.bin"); + public static string Memory => Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)!, "memory.bin"); public static string Build => Path.Combine(AbpRootPath, "build"); public static string Lic => Path.Combine(Path.GetTempPath(), Encoding.ASCII.GetString(new byte[] { 65, 98, 112, 76, 105, 99, 101, 110, 115, 101, 46, 98, 105, 110 })); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs index f03ae851c1..9444381a0d 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging.Abstractions; using NuGet.Versioning; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -11,14 +12,17 @@ using System.Text; using System.Threading.Tasks; using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Commands; +using Volo.Abp.Cli.Memory; using Volo.Abp.Cli.NuGet; using Volo.Abp.Cli.Utils; using Volo.Abp.DependencyInjection; +using Volo.Abp.IO; namespace Volo.Abp.Cli; public class CliService : ITransientDependency { + private readonly MemoryService _memoryService; public ILogger Logger { get; set; } protected ICommandLineArgumentParser CommandLineArgumentParser { get; } protected ICommandSelector CommandSelector { get; } @@ -31,8 +35,10 @@ public class CliService : ITransientDependency ICommandSelector commandSelector, IServiceScopeFactory serviceScopeFactory, NuGetService nugetService, - ICmdHelper cmdHelper) + ICmdHelper cmdHelper, + MemoryService memoryService) { + _memoryService = memoryService; CommandLineArgumentParser = commandLineArgumentParser; CommandSelector = commandSelector; ServiceScopeFactory = serviceScopeFactory; @@ -164,6 +170,11 @@ public class CliService : ITransientDependency private async Task CheckCliVersionAsync() { + if (!await IsLatestVersionCheckExpiredAsync()) + { + return; + } + var assembly = typeof(CliService).Assembly; var toolPath = GetToolPath(assembly); var currentCliVersion = await GetCurrentCliVersionInternalAsync(assembly); @@ -187,6 +198,27 @@ public class CliService : ITransientDependency } } + private async Task IsLatestVersionCheckExpiredAsync() + { + try + { + var latestTime = await _memoryService.GetAsync(CliConsts.MemoryKeys.LatestCliVersionCheckDate); + + if (latestTime != null && DateTime.Now - DateTime.Parse(latestTime, CultureInfo.InvariantCulture) < TimeSpan.FromDays(1)) + { + return false; + } + + await _memoryService.SetAsync(CliConsts.MemoryKeys.LatestCliVersionCheckDate, DateTime.Now.ToString(CultureInfo.InvariantCulture)); + + return true; + } + catch (Exception) + { + return true; + } + } + private string GetToolPath(Assembly assembly) { if (!assembly.Location.Contains(".store")) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs index 1cccf87f7b..82f5bd11ba 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs @@ -39,13 +39,8 @@ public class GetSourceCommand : IConsoleCommand, ITransientDependency } var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long); - if (version != null) - { - Logger.LogInformation("Version: " + version); - } var outputFolder = GetOutPutFolder(commandLineArgs); - Logger.LogInformation("Output folder: " + outputFolder); var gitHubAbpLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubAbpLocalRepositoryPath.Long); if (gitHubAbpLocalRepositoryPath != null) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SourceCodeDownloadService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SourceCodeDownloadService.cs index c9a4a7098b..bee03b9c1f 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SourceCodeDownloadService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SourceCodeDownloadService.cs @@ -33,8 +33,7 @@ public class SourceCodeDownloadService : ITransientDependency public async Task DownloadModuleAsync(string moduleName, string outputFolder, string version, string gitHubAbpLocalRepositoryPath, string gitHubVoloLocalRepositoryPath, AbpCommandLineOptions options) { - Logger.LogInformation("Downloading source code of " + moduleName); - Logger.LogInformation("Version: " + (version ?? "Latest")); + Logger.LogInformation($"Downloading source code of {moduleName} (v{version ?? "Latest"})"); Logger.LogInformation("Output folder: " + outputFolder); var result = await ModuleProjectBuilder.BuildAsync( diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Memory/MemoryService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Memory/MemoryService.cs new file mode 100644 index 0000000000..5f8b18cf99 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Memory/MemoryService.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp.DependencyInjection; +using Volo.Abp.IO; + +namespace Volo.Abp.Cli.Memory; + +public class MemoryService : ITransientDependency +{ + private const string KeyValueSeparator = "|||"; + + [ItemCanBeNull] + public async Task GetAsync(string key) + { + if (!File.Exists(CliPaths.Memory)) + { + return null; + } + + return (await FileHelper.ReadAllTextAsync(CliPaths.Memory)) + .Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None) + .FirstOrDefault(x => x.StartsWith($"{key} "))?.Split(KeyValueSeparator).Last().Trim(); + } + + public async Task SetAsync(string key, string value) + { + if (!File.Exists(CliPaths.Memory)) + { + File.WriteAllText(CliPaths.Memory, + $"{key} {KeyValueSeparator} {value}" + ); + return; + } + + var memoryContentLines = (await FileHelper.ReadAllTextAsync(CliPaths.Memory)) + .Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None) + .ToList(); + + memoryContentLines.RemoveAll(x => x.StartsWith(key)); + memoryContentLines.Add($"{key} {KeyValueSeparator} {value}"); + + File.WriteAllText(CliPaths.Memory, + memoryContentLines.JoinAsString(Environment.NewLine) + ); + } +} \ No newline at end of file