From 1c377800d95c00c18784b9b2b56d89a3036c49a2 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 1 Aug 2024 17:58:27 +0800 Subject: [PATCH 1/3] Fix enum conversion method. --- .../Abp/Data/HasExtraPropertiesExtensions.cs | 2 +- .../Volo/Docs/Admin/Projects/ProjectDto.cs | 8 +-- .../Admin/Projects/ProjectAdminAppService.cs | 18 +++--- .../Pages/Docs/Admin/Projects/Edit.cshtml.cs | 17 +++--- .../Volo/Docs/Projects/ProjectDto.cs | 8 +-- .../Volo/Docs/Documents/DocumentAppService.cs | 39 ++++++------- .../Volo/Docs/Projects/ProjectAppService.cs | 19 +++---- .../Projects/ProjectFileSystemExtensions.cs | 7 ++- .../GitHub/Documents/GithubDocumentSource.cs | 17 +++--- .../Projects/ProjectGithubExtensions.cs | 16 +++--- .../Pages/Documents/Project/Index.cshtml.cs | 55 ++++++++++--------- .../Pages/Documents/Search.cshtml.cs | 19 ++++--- 12 files changed, 115 insertions(+), 110 deletions(-) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs index ede0c65861..75f5672a29 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs @@ -47,7 +47,7 @@ public static class HasExtraPropertiesExtensions if (conversionType.IsEnum) { - return (TProperty)value; + return (TProperty)Enum.Parse(conversionType, value.ToString()!); } return (TProperty)Convert.ChangeType(value, conversionType, CultureInfo.InvariantCulture); diff --git a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs index 8996426406..d8ff0ca651 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs +++ b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs @@ -1,12 +1,12 @@ using System; -using System.Collections.Generic; using Volo.Abp.Application.Dtos; +using Volo.Abp.Data; using Volo.Abp.Domain.Entities; namespace Volo.Docs.Admin.Projects { [Serializable] - public class ProjectDto : EntityDto, IHasConcurrencyStamp + public class ProjectDto : EntityDto, IHasConcurrencyStamp, IHasExtraProperties { public string Name { get; set; } @@ -28,8 +28,8 @@ namespace Volo.Docs.Admin.Projects public string DocumentStoreType { get; set; } - public Dictionary ExtraProperties { get; set; } - public string ConcurrencyStamp { get; set; } + + public ExtraPropertyDictionary ExtraProperties { get; set; } = new(); } } diff --git a/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Projects/ProjectAdminAppService.cs b/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Projects/ProjectAdminAppService.cs index 838e84f9ad..3142b821d2 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Projects/ProjectAdminAppService.cs +++ b/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Projects/ProjectAdminAppService.cs @@ -81,7 +81,7 @@ namespace Volo.Docs.Admin.Projects foreach (var extraProperty in input.ExtraProperties) { - project.ExtraProperties.Add(extraProperty.Key, extraProperty.Value); + project.SetProperty(extraProperty.Key, extraProperty.Value); } project = await _projectRepository.InsertAsync(project); @@ -106,7 +106,7 @@ namespace Volo.Docs.Admin.Projects foreach (var extraProperty in input.ExtraProperties) { - project.ExtraProperties[extraProperty.Key] = extraProperty.Value; + project.SetProperty(extraProperty.Key, extraProperty.Value); } project = await _projectRepository.UpdateAsync(project); @@ -134,18 +134,18 @@ namespace Volo.Docs.Admin.Projects { throw new Exception("Cannot find the project with the Id " + projectId); } - + await _elasticSearchService.DeleteAllByProjectIdAsync(project.Id); - + var docsCount = await _documentRepository.GetUniqueDocumentCountByProjectIdAsync(projectId); - + if (docsCount == 0) { return; } - + const int maxResultCount = 1000; - + var skipCount = 0; while(skipCount < docsCount) { @@ -164,13 +164,13 @@ namespace Volo.Docs.Admin.Projects { _elasticSearchService.ValidateElasticSearchEnabled(); var projects = await _projectRepository.GetListAsync(); - + foreach (var project in projects) { await ReindexProjectAsync(project.Id); } } - + public virtual async Task> GetListWithoutDetailsAsync() { var projects = await _projectRepository.GetListWithoutDetailsAsync(); diff --git a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs index ad9482578e..9a7d73e436 100644 --- a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc.Rendering; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using Volo.Abp.Data; using Volo.Abp.Domain.Entities; using Volo.Abp.Validation; using Volo.Docs.Admin.Projects; @@ -34,7 +35,7 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects public virtual async Task OnGetAsync(Guid id) { var project = await _projectAppService.GetAsync(id); - + if (project.DocumentStoreType == "GitHub") { SetGithubProjectFromDto(project); @@ -75,18 +76,18 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects { GithubProject = ObjectMapper.Map(dto); - GithubProject.GitHubAccessToken = (string) dto.ExtraProperties[nameof(GithubProject.GitHubAccessToken)]; - GithubProject.GitHubRootUrl = (string) dto.ExtraProperties[nameof(GithubProject.GitHubRootUrl)]; - GithubProject.GitHubUserAgent = (string) dto.ExtraProperties[nameof(GithubProject.GitHubUserAgent)]; + GithubProject.GitHubAccessToken = dto.GetProperty(nameof(GithubProject.GitHubAccessToken)); + GithubProject.GitHubRootUrl = dto.GetProperty(nameof(GithubProject.GitHubRootUrl)); + GithubProject.GitHubUserAgent = dto.GetProperty(nameof(GithubProject.GitHubUserAgent)); - if (dto.ExtraProperties.ContainsKey(nameof(GithubProject.GithubVersionProviderSource))) + if (dto.HasProperty(nameof(GithubProject.GithubVersionProviderSource))) { - GithubProject.GithubVersionProviderSource = (GithubVersionProviderSource) (long) dto.ExtraProperties[nameof(GithubProject.GithubVersionProviderSource)]; + GithubProject.GithubVersionProviderSource = dto.GetProperty(nameof(GithubProject.GithubVersionProviderSource)); } - if (dto.ExtraProperties.ContainsKey(nameof(GithubProject.VersionBranchPrefix))) + if (dto.HasProperty(nameof(GithubProject.VersionBranchPrefix))) { - GithubProject.VersionBranchPrefix = (string) dto.ExtraProperties[nameof(GithubProject.VersionBranchPrefix)]; + GithubProject.VersionBranchPrefix = dto.GetProperty(nameof(GithubProject.VersionBranchPrefix)); } } diff --git a/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/ProjectDto.cs b/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/ProjectDto.cs index 91f5c63a22..2861e60307 100644 --- a/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/ProjectDto.cs +++ b/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/ProjectDto.cs @@ -1,11 +1,11 @@ using System; -using System.Collections.Generic; using Volo.Abp.Application.Dtos; +using Volo.Abp.Data; namespace Volo.Docs.Projects { [Serializable] - public class ProjectDto : EntityDto + public class ProjectDto : EntityDto, IHasExtraProperties { public string Name { get; set; } @@ -25,6 +25,6 @@ namespace Volo.Docs.Projects public string DocumentStoreType { get; set; } - public Dictionary ExtraProperties { get; set; } + public ExtraPropertyDictionary ExtraProperties { get; set; } = new(); } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs index e6b10967af..c426afacbd 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs +++ b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.Options; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Caching; +using Volo.Abp.Data; using Volo.Docs.Caching; using Volo.Docs.Documents.FullSearch.Elastic; using Volo.Docs.Projects; @@ -69,7 +70,7 @@ namespace Volo.Docs.Documents var inputVersionStringBuilder = new StringBuilder(); input.Version = inputVersionStringBuilder.Append(GetProjectVersionPrefixIfExist(project)).Append(input.Version).ToString(); - + return await GetDocumentWithDetailsDtoAsync( project, input.Name, @@ -84,9 +85,9 @@ namespace Volo.Docs.Documents var sb = new StringBuilder(); input.Version = sb.Append(GetProjectVersionPrefixIfExist(project)).Append(input.Version).ToString(); - + sb.Clear(); - + return await GetDocumentWithDetailsDtoAsync( project, sb.Append(project.DefaultDocumentName).Append(".").Append(project.Format).ToString(), @@ -298,7 +299,7 @@ namespace Volo.Docs.Documents private string NormalizePath(string prefix, string path, string shortName, DocumentWithoutDetails document) { var pathWithoutFileExtension = RemoveFileExtensionFromPath(path, document.Format); - + var normalizedPathStringBuilder = new StringBuilder(); normalizedPathStringBuilder.Append(prefix).Append(document.LanguageCode).Append("/").Append(shortName) .Append("/").Append(document.Version).Append("/").Append(pathWithoutFileExtension); @@ -377,7 +378,7 @@ namespace Volo.Docs.Documents { return await GetDocumentAsync(documentName, project, languageCode, version); } - + var document = await _documentRepository.FindAsync(project.Id, GetPossibleNames(documentName, project.Format), languageCode, version); if (document == null) { @@ -417,7 +418,7 @@ namespace Volo.Docs.Documents string languageCode, string version, Document oldDocument = null) { Logger.LogInformation($"Not found in the cache. Requesting {documentName} from the source..."); - + var sourceDocument = await GetSourceDocument(project, documentName, languageCode, version, oldDocument); await _documentRepository.DeleteAsync(project.Id, sourceDocument.Name, sourceDocument.LanguageCode, sourceDocument.Version, autoSave: true); @@ -450,23 +451,23 @@ namespace Volo.Docs.Documents { return new List {originalDocumentName}; } - + var lowerCaseIndex = "index." + format; var titleCaseIndex = "Index." + format; var indexLength = lowerCaseIndex.Length; - + var possibleNames = new List {originalDocumentName}; if (originalDocumentName.EndsWith("/" + lowerCaseIndex, StringComparison.OrdinalIgnoreCase) || originalDocumentName.Equals(lowerCaseIndex, StringComparison.OrdinalIgnoreCase)) { var indexPart = originalDocumentName.Right(indexLength); - + var documentNameWithoutIndex = originalDocumentName.Left(originalDocumentName.Length - lowerCaseIndex.Length); - + if(indexPart != lowerCaseIndex) { possibleNames.Add(documentNameWithoutIndex + lowerCaseIndex); } - + if(indexPart != titleCaseIndex) { possibleNames.Add(documentNameWithoutIndex + titleCaseIndex); @@ -481,14 +482,14 @@ namespace Volo.Docs.Documents return possibleNames; } - + private async Task GetSourceDocument(Project project, string documentName, string languageCode, string version, Document oldDocument) { var source = _documentStoreFactory.Create(project.DocumentStoreType); - + Document sourceDocument = null; - + Exception firstException = null; foreach (var name in GetPossibleNames(documentName, project.Format)) { @@ -503,7 +504,7 @@ namespace Volo.Docs.Documents firstException ??= ex; } } - + if(sourceDocument == null) { throw firstException!; @@ -552,14 +553,14 @@ namespace Volo.Docs.Documents return string.Empty; } - return project.ExtraProperties["VersionBranchPrefix"].ToString(); + return project.GetProperty("VersionBranchPrefix"); } private GithubVersionProviderSource GetGithubVersionProviderSource(Project project) { - return project.ExtraProperties.ContainsKey("GithubVersionProviderSource") - ? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"] + return project.HasProperty("GithubVersionProviderSource") + ? project.GetProperty("GithubVersionProviderSource") : GithubVersionProviderSource.Releases; } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs index 869a0efa82..1cca1a102a 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs +++ b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Caching.Distributed; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Caching; +using Volo.Abp.Data; using Volo.Abp.Guids; using Volo.Docs.Caching; using Volo.Docs.Documents; @@ -41,7 +42,7 @@ namespace Volo.Docs.Projects return new ListResultDto( projectDtos.Select(p => HidePrivateProperties(p)).ToList() - ); + ); } public virtual async Task GetAsync(string shortName) @@ -136,30 +137,28 @@ namespace Volo.Docs.Projects return string.Empty; } - return project.ExtraProperties["VersionBranchPrefix"].ToString(); - + return project.GetProperty("VersionBranchPrefix"); } private GithubVersionProviderSource GetGithubVersionProviderSource(Project project) { - return project.ExtraProperties.ContainsKey("GithubVersionProviderSource") - ? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"] + return project.HasProperty("GithubVersionProviderSource") + ? project.GetProperty("GithubVersionProviderSource") : GithubVersionProviderSource.Releases; } private ProjectDto HidePrivateProperties(ProjectDto project) { - if (project.ExtraProperties.ContainsKey("GitHubAccessToken")) + if (project.HasProperty("GitHubAccessToken")) { - project.ExtraProperties["GitHubAccessToken"] = null; + project.SetProperty("GitHubAccessToken", null); } - if (project.ExtraProperties.ContainsKey("GitHubUserAgent")) + if (project.HasProperty("GitHubUserAgent")) { - project.ExtraProperties["GitHubUserAgent"] = null; + project.SetProperty("GitHubUserAgent", null); } - return project; } } diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Projects/ProjectFileSystemExtensions.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Projects/ProjectFileSystemExtensions.cs index f0fc44e39e..f7bc2076f2 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Projects/ProjectFileSystemExtensions.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Projects/ProjectFileSystemExtensions.cs @@ -1,6 +1,7 @@ using System; using JetBrains.Annotations; using Volo.Abp; +using Volo.Abp.Data; using Volo.Docs.FileSystem.Documents; using Volo.Docs.Projects; @@ -11,13 +12,13 @@ namespace Volo.Docs.FileSystem.Projects public static string GetFileSystemPath([NotNull] this Project project) { CheckFileSystemProject(project); - return project.ExtraProperties["Path"] as string; + return project.GetProperty("Path"); } public static void SetFileSystemPath([NotNull] this Project project, string value) { CheckFileSystemProject(project); - project.ExtraProperties["Path"] = value; + project.SetProperty("Path", value); } private static void CheckFileSystemProject(Project project) @@ -30,4 +31,4 @@ namespace Volo.Docs.FileSystem.Projects } } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs index 3698d5583e..8d301395c0 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs @@ -11,6 +11,7 @@ using Volo.Docs.GitHub.Projects; using Volo.Docs.Projects; using Octokit; using Volo.Abp; +using Volo.Abp.Data; using Volo.Docs.GitHub.Documents.Version; using Volo.Extensions; using Project = Volo.Docs.Projects.Project; @@ -29,8 +30,8 @@ namespace Volo.Docs.GitHub.Documents private readonly DocsGithubLanguageOptions _docsGithubLanguageOptions; public GithubDocumentSource( - IGithubRepositoryManager githubRepositoryManager, - IGithubPatchAnalyzer githubPatchAnalyzer, + IGithubRepositoryManager githubRepositoryManager, + IGithubPatchAnalyzer githubPatchAnalyzer, IDocumentRepository documentRepository, IOptions docsGithubLanguageOptions) { @@ -275,7 +276,7 @@ namespace Volo.Docs.GitHub.Documents if (githubVersionProviderSource == GithubVersionProviderSource.Branches && project.ExtraProperties.ContainsKey("VersionBranchPrefix")) { - var prefix = (string) project.ExtraProperties["VersionBranchPrefix"]; + var prefix = project.GetProperty("VersionBranchPrefix"); if (!string.IsNullOrEmpty(prefix)) { @@ -307,8 +308,8 @@ namespace Volo.Docs.GitHub.Documents private GithubVersionProviderSource GetGithubVersionProviderSource(Project project) { - return project.ExtraProperties.ContainsKey("GithubVersionProviderSource") - ? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"] + return project.HasProperty("GithubVersionProviderSource") + ? project.GetProperty("GithubVersionProviderSource") : GithubVersionProviderSource.Releases; } @@ -344,9 +345,9 @@ namespace Volo.Docs.GitHub.Documents } catch { - Logger.LogWarning("Could not retrieved language list from Github. Using the default language from DocsGithubLanguageOptions."); - - return new LanguageConfig + Logger.LogWarning("Could not retrieved language list from Github. Using the default language from DocsGithubLanguageOptions."); + + return new LanguageConfig { Languages = new List { _docsGithubLanguageOptions.DefaultLanguage } }; diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Projects/ProjectGithubExtensions.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Projects/ProjectGithubExtensions.cs index 4810f94ac4..005c826c45 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Projects/ProjectGithubExtensions.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Projects/ProjectGithubExtensions.cs @@ -1,6 +1,7 @@ using System; using JetBrains.Annotations; using Volo.Abp; +using Volo.Abp.Data; using Volo.Docs.GitHub.Documents; using Volo.Docs.Projects; @@ -11,13 +12,12 @@ namespace Volo.Docs.GitHub.Projects public static string GetGitHubUrl([NotNull] this Project project) { CheckGitHubProject(project); - return project.ExtraProperties["GitHubRootUrl"] as string; + return project.GetProperty("GitHubRootUrl"); } public static string GetGitHubInnerUrl([NotNull] this Project project, string languageCode, string documentName) { - return project - .GetGitHubUrl().Split("{version}")[1].EnsureEndsWith('/').TrimStart('/') + languageCode + '/' + documentName; + return project.GetGitHubUrl().Split("{version}")[1].EnsureEndsWith('/').TrimStart('/') + languageCode + '/' + documentName; } public static string GetGitHubUrl([NotNull] this Project project, string version) @@ -30,25 +30,25 @@ namespace Volo.Docs.GitHub.Projects public static void SetGitHubUrl([NotNull] this Project project, string value) { CheckGitHubProject(project); - project.ExtraProperties["GitHubRootUrl"] = value; + project.SetProperty("GitHubRootUrl", value); } public static string GetGitHubAccessTokenOrNull([NotNull] this Project project) { CheckGitHubProject(project); - return project.ExtraProperties["GitHubAccessToken"] as string; + return project.GetProperty("GitHubAccessToken"); } public static string GetGithubUserAgentOrNull([NotNull] this Project project) { CheckGitHubProject(project); - return project.ExtraProperties["GitHubUserAgent"] as string; + return project.GetProperty("GitHubUserAgent"); } public static void SetGitHubAccessToken([NotNull] this Project project, string value) { CheckGitHubProject(project); - project.ExtraProperties["GitHubAccessToken"] = value; + project.SetProperty("GitHubAccessToken", value); } private static void CheckGitHubProject(Project project) @@ -61,4 +61,4 @@ namespace Volo.Docs.GitHub.Projects } } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs index b544a18351..c3c1ae9643 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs @@ -14,6 +14,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using Volo.Abp.Data; using Volo.Abp.Domain.Entities; using Volo.Docs.Documents; using Volo.Docs.HtmlConverting; @@ -68,7 +69,7 @@ namespace Volo.Docs.Pages.Documents.Project public string DocumentsUrlPrefix { get; set; } public bool ShowProjectsCombobox { get; set; } - + public bool ShowProjectsComboboxLabel { get; set; } public bool IsVersionPreview { get; set; } @@ -83,8 +84,8 @@ namespace Volo.Docs.Pages.Documents.Project public bool FullSearchEnabled { get; set; } - public bool IsLatestVersion { get; private set; } - + public bool IsLatestVersion { get; private set; } + public DocumentNavigationsDto DocumentNavigationsDto { get; private set; } private const int MaxDescriptionMetaTagLength = 200; @@ -93,7 +94,7 @@ namespace Volo.Docs.Pages.Documents.Project private readonly IProjectAppService _projectAppService; private readonly IDocumentSectionRenderer _documentSectionRenderer; private readonly DocsUiOptions _uiOptions; - + protected IDocsLinkGenerator DocsLinkGenerator => LazyServiceProvider.LazyGetRequiredService(); public IndexModel( @@ -123,7 +124,7 @@ namespace Volo.Docs.Pages.Documents.Project { return Redirect(decodedUrl); } - + return await SetPageAsync(); } @@ -143,7 +144,7 @@ namespace Volo.Docs.Pages.Documents.Project Response.StatusCode = 404; return Page(); } - + } catch (EntityNotFoundException e) { @@ -168,7 +169,7 @@ namespace Volo.Docs.Pages.Documents.Project { return RedirectToDefaultDocument(); } - + var usingSingleLanguageMode = !_uiOptions.MultiLanguageMode && LanguageCode.IsNullOrWhiteSpace(); if (!usingSingleLanguageMode && !CheckLanguage()) @@ -220,14 +221,14 @@ namespace Volo.Docs.Pages.Documents.Project Project = await _projectAppService.GetAsync(ProjectName); return; } - + var singleProjectName = ProjectName ?? _uiOptions.SingleProjectMode.ProjectName; if (!singleProjectName.IsNullOrWhiteSpace()) { Project = await _projectAppService.GetAsync(singleProjectName); return; } - + var listResult = await _projectAppService.GetListAsync(); if (listResult.Items.Count == 1) { @@ -265,12 +266,12 @@ namespace Volo.Docs.Pages.Documents.Project { return Request.Scheme + Uri.SchemeDelimiter + Request.Host.Value + Request.PathBase + DocsLinkGenerator.GenerateLink(ProjectName, LanguageCode, DocsAppConsts.Latest, DocumentName); } - + public string CreateDocumentLink(string documentName) { return DocsLinkGenerator.GenerateLink(ProjectName, LanguageCode, LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version, documentName); } - + public string BuildDocumentUrl(string projectName, string languageCode, string version, string documentName) { return DocsLinkGenerator.GenerateLink(projectName, languageCode, version, documentName); @@ -279,13 +280,13 @@ namespace Volo.Docs.Pages.Documents.Project private IActionResult RedirectToDefaultLanguage() { return Redirect(DocsLinkGenerator.GenerateLink( - ProjectName, - DefaultLanguageCode, + ProjectName, + DefaultLanguageCode, LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version, DocumentName )); } - + private IActionResult RedirectToDefaultVersion() { return Redirect(DocsLinkGenerator.GenerateLink( @@ -301,7 +302,7 @@ namespace Volo.Docs.Pages.Documents.Project return Redirect(DocsLinkGenerator.GenerateLink ( ProjectName, DefaultLanguageCode, - LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version, + LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version, "" )); } @@ -374,7 +375,7 @@ namespace Volo.Docs.Pages.Documents.Project $"{DocsAppConsts.Latest}", DocsAppConsts.Latest, true); - + if(string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase)) { Version = RemoveVersionPrefix(Project.LatestVersionBranchName); @@ -387,16 +388,16 @@ namespace Volo.Docs.Pages.Documents.Project Value = CreateVersionLink(LatestVersionInfo, v.Version, DocumentName), Selected = v.IsSelected }).ToList(); - + IsLatestVersion = Version == LatestVersionInfo.Version; - + return true; } private VersionInfoViewModel GetLatestVersionInfo(List versions) { - if (Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") - && (GithubVersionProviderSource)(long)Project.ExtraProperties["GithubVersionProviderSource"] == GithubVersionProviderSource.Branches) + if (Project.HasProperty("GithubVersionProviderSource") + && Project.GetProperty("GithubVersionProviderSource") == GithubVersionProviderSource.Branches) { var LatestVersionBranchNameWithoutPrefix = RemoveVersionPrefix(Project.LatestVersionBranchName); @@ -418,12 +419,12 @@ namespace Volo.Docs.Pages.Documents.Project private string RemoveVersionPrefix(string version) { - if (!Project.ExtraProperties.ContainsKey("VersionBranchPrefix")) + if (!Project.HasProperty("VersionBranchPrefix")) { return version; } - var prefix = Project.ExtraProperties["VersionBranchPrefix"]?.ToString(); + var prefix = Project.GetProperty("VersionBranchPrefix"); if (string.IsNullOrWhiteSpace(version) || string.IsNullOrWhiteSpace(prefix) || !version.StartsWith(prefix) || version.Length <= prefix.Length) { @@ -435,8 +436,8 @@ namespace Volo.Docs.Pages.Documents.Project private void SetLatestVersionBranchName(List versions) { - if (!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") - || (GithubVersionProviderSource)(long)Project.ExtraProperties["GithubVersionProviderSource"] == GithubVersionProviderSource.Releases) + if (!Project.HasProperty("GithubVersionProviderSource") + || Project.GetProperty("GithubVersionProviderSource") == GithubVersionProviderSource.Releases) { versions.First(v => !SemanticVersionHelper.IsPreRelease(v.Version)).Version = Project.LatestVersionBranchName; } @@ -467,7 +468,7 @@ namespace Volo.Docs.Pages.Documents.Project { version = DocsAppConsts.Latest; } - + return DocsLinkGenerator.GenerateLink(ProjectName, LanguageCode, version, documentName); } @@ -536,7 +537,7 @@ namespace Volo.Docs.Pages.Documents.Project SetUserPreferences(); var partialTemplates = await GetDocumentPartialTemplatesAsync(); - + DocumentNavigationsDto = await _documentSectionRenderer.GetDocumentNavigationsAsync(Document.Content); Document.Content = await _documentSectionRenderer.RenderAsync(Document.Content, UserPreferences, partialTemplates); @@ -819,4 +820,4 @@ namespace Volo.Docs.Pages.Documents.Project return description.Truncate(MaxDescriptionMetaTagLength); } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs index 943c7cd28c..7be35394ae 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Pagination; +using Volo.Abp.Data; using Volo.Docs.Documents; using Volo.Docs.GitHub.Documents.Version; using Volo.Docs.HtmlConverting; @@ -26,9 +27,9 @@ namespace Volo.Docs.Pages.Documents [BindProperty(SupportsGet = true)] public string LanguageCode { get; set; } [BindProperty(SupportsGet = true)] public string KeyWord { get; set; } - + [BindProperty(SupportsGet = true)] public int CurrentPage { get; set; } = 1; - + public PagerModel PagerModel { get; set; } public ProjectDto Project { get; set; } @@ -73,8 +74,8 @@ namespace Volo.Docs.Pages.Documents if (versions.Any() && string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase)) { - if ((!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") || - (GithubVersionProviderSource) (long) Project.ExtraProperties["GithubVersionProviderSource"] ==GithubVersionProviderSource.Releases) && + if ((!Project.HasProperty("GithubVersionProviderSource") || + Project.GetProperty("GithubVersionProviderSource") ==GithubVersionProviderSource.Releases) && !string.IsNullOrEmpty(Project.LatestVersionBranchName)) { Version = Project.LatestVersionBranchName; @@ -94,9 +95,9 @@ namespace Volo.Docs.Pages.Documents MaxResultCount = 10, SkipCount = (CurrentPage - 1) * 10 }); - + SearchOutputs = pagedSearchOutputs.Items.ToList(); - + PagerModel = new PagerModel(pagedSearchOutputs.TotalCount, 10, CurrentPage, 10, Url.Page("Search", new { ProjectName, @@ -120,7 +121,7 @@ namespace Volo.Docs.Pages.Documents return Page(); } - + private async Task SetProjectAsync() { if (!_uiOptions.SingleProjectMode.Enable) @@ -128,14 +129,14 @@ namespace Volo.Docs.Pages.Documents Project = await _projectAppService.GetAsync(ProjectName); return; } - + var singleProjectName = ProjectName ?? _uiOptions.SingleProjectMode.ProjectName; if (!singleProjectName.IsNullOrWhiteSpace()) { Project = await _projectAppService.GetAsync(singleProjectName); return; } - + var listResult = await _projectAppService.GetListAsync(); if (listResult.Items.Count == 1) { From af856f9d383245a69904abea414a31791d5f6400 Mon Sep 17 00:00:00 2001 From: ahmetfarukulu Date: Thu, 1 Aug 2024 14:35:26 +0300 Subject: [PATCH 2/3] CLI documentation 'check-extensions' section added --- docs/en/cli/index.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/en/cli/index.md b/docs/en/cli/index.md index 8549e9d05f..26acb087d1 100644 --- a/docs/en/cli/index.md +++ b/docs/en/cli/index.md @@ -23,6 +23,7 @@ dotnet tool update -g Volo.Abp.Studio.Cli While each command may have a set of options, there are some global options that can be used with any command; * `--skip-cli-version-check`: Skips to check the latest version of the ABP CLI. If you don't specify, it will check the latest version and shows a warning message if there is a newer version of the ABP CLI. +- `--skip-extension-version-check` or `-sevc`: Skips to check the latest version of the ABP CLI extensions. If you don't specify, it will check the latest version and download the latest version if there is a newer version of the ABP CLI extensions. * `--old`: ABP CLI has two variations: `Volo.Abp.Studio.Cli` and `Volo.Abp.Cli`. New features/templates are added to the `Volo.Abp.Studio.Cli`. But if you want to use the old version, you can use this option **at the end of your commands**. For example, `abp new Acme.BookStore --old`. ## Commands @@ -64,6 +65,7 @@ Here, is the list of all available commands before explaining their details: * **`bundle`**: Generates script and style references for ABP Blazor and MAUI Blazor project. * **`install-libs`**: Install NPM Packages for MVC / Razor Pages and Blazor Server UI types. * **`clear-download-cache`**: Clears the templates download cache. +* **`check-extensions`**: Checks the latest version of the ABP CLI extensions. ### help @@ -919,6 +921,16 @@ abp install-libs [options] * ```--working-directory``` or ```-wd```: Specifies the working directory. This option is useful when executing directory doesn't contain a project file. +### check-extensions + +This command checks the installed ABP CLI extensions and updates them if necessary. + +Usage: + +````bash +abp check-extensions +```` + ## See Also * [Examples for the new command](./new-command-samples.md) From 738f5e2afc12f66f1b6c566b345517e64220d7e4 Mon Sep 17 00:00:00 2001 From: ahmetfarukulu Date: Thu, 1 Aug 2024 15:45:15 +0300 Subject: [PATCH 3/3] Additional global options added --- docs/en/cli/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/en/cli/index.md b/docs/en/cli/index.md index 26acb087d1..7b4dbd9502 100644 --- a/docs/en/cli/index.md +++ b/docs/en/cli/index.md @@ -22,9 +22,10 @@ dotnet tool update -g Volo.Abp.Studio.Cli While each command may have a set of options, there are some global options that can be used with any command; -* `--skip-cli-version-check`: Skips to check the latest version of the ABP CLI. If you don't specify, it will check the latest version and shows a warning message if there is a newer version of the ABP CLI. +* `--skip-cli-version-check` or `-scvc`: Skips to check the latest version of the ABP CLI. If you don't specify, it will check the latest version and shows a warning message if there is a newer version of the ABP CLI. - `--skip-extension-version-check` or `-sevc`: Skips to check the latest version of the ABP CLI extensions. If you don't specify, it will check the latest version and download the latest version if there is a newer version of the ABP CLI extensions. * `--old`: ABP CLI has two variations: `Volo.Abp.Studio.Cli` and `Volo.Abp.Cli`. New features/templates are added to the `Volo.Abp.Studio.Cli`. But if you want to use the old version, you can use this option **at the end of your commands**. For example, `abp new Acme.BookStore --old`. +* `--help` or `-h`: Shows help for the specified command. ## Commands