From 1ed91f7dfd957a809cd21f02c49db1b773e5672d Mon Sep 17 00:00:00 2001 From: damon Date: Fri, 31 May 2024 22:56:15 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Packages.props | 38 +++++++++---------- .../Identity/GrantWithPasswordUseCase.cs | 2 +- global.props | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 0bf3d86..7d221f7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -31,18 +31,18 @@ - - - + + + - - - - + + + + - + - + @@ -51,16 +51,16 @@ - - + + - - - + + + - - + + @@ -102,9 +102,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Source/Starfish.Service/UseCases/Identity/GrantWithPasswordUseCase.cs b/Source/Starfish.Service/UseCases/Identity/GrantWithPasswordUseCase.cs index ae383bb..74b4022 100644 --- a/Source/Starfish.Service/UseCases/Identity/GrantWithPasswordUseCase.cs +++ b/Source/Starfish.Service/UseCases/Identity/GrantWithPasswordUseCase.cs @@ -66,7 +66,7 @@ public async Task ExecuteAsync(GrantWithPassword var passwordHash = Cryptography.DES.Encrypt(input.Password, Encoding.UTF8.GetBytes(user.PasswordSalt)); - if (string.Equals(user.PasswordHash, passwordHash)) + if (!string.Equals(user.PasswordHash, passwordHash)) { throw new AuthenticationException(Resources.IDS_ERROR_USER_USERNAME_OR_PASSWORD_IS_INVALID); } diff --git a/global.props b/global.props index ad45b6d..f598b3e 100644 --- a/global.props +++ b/global.props @@ -1,6 +1,6 @@ - 1.0.5 + 1.0.6 damon Nerosoft Ltd. Starfish From ab7d4bcd7687475424674ff4067e758e2a8b87f9 Mon Sep 17 00:00:00 2001 From: damon Date: Fri, 31 May 2024 22:57:11 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8DPGSQL=E9=9D=9EUCT?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=97=A0=E6=B3=95=E4=BF=9D=E5=AD=98=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/Contexts/DataContext.cs | 9 ++++++ .../Repository/DateTimeStorageConverter.cs | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Source/Starfish.Service/Repository/DateTimeStorageConverter.cs diff --git a/Source/Starfish.Service/Repository/Contexts/DataContext.cs b/Source/Starfish.Service/Repository/Contexts/DataContext.cs index dd44186..ef2bd15 100644 --- a/Source/Starfish.Service/Repository/Contexts/DataContext.cs +++ b/Source/Starfish.Service/Repository/Contexts/DataContext.cs @@ -108,6 +108,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) base.OnModelCreating(modelBuilder); } + protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) + { + base.ConfigureConventions(configurationBuilder); + configurationBuilder.Properties() + .HaveConversion(); + configurationBuilder.Properties() + .HaveConversion(); + } + private List GetTrackedEvents() { var entries = ChangeTracker.Entries(); diff --git a/Source/Starfish.Service/Repository/DateTimeStorageConverter.cs b/Source/Starfish.Service/Repository/DateTimeStorageConverter.cs new file mode 100644 index 0000000..39d78dd --- /dev/null +++ b/Source/Starfish.Service/Repository/DateTimeStorageConverter.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Nerosoft.Starfish.Repository; + +public class DateTimeStorageConverter : ValueConverter +{ + public DateTimeStorageConverter() + : base(t => ConvertToUniversalTime(t), t => ConvertToLocalTime(t)) + { + } + + private static DateTime ConvertToUniversalTime(DateTime time) + { + return time.Kind switch + { + DateTimeKind.Unspecified => DateTime.SpecifyKind(time, DateTimeKind.Local).ToUniversalTime(), + DateTimeKind.Local => time.ToUniversalTime(), + _ => time + }; + } + + private static DateTime ConvertToLocalTime(DateTime time) + { + return time.Kind switch + { + DateTimeKind.Unspecified => DateTime.SpecifyKind(time, DateTimeKind.Utc).ToLocalTime(), + DateTimeKind.Utc => time.ToLocalTime(), + _ => time + }; + } +} \ No newline at end of file From d5e09abd14b125559f4dc691678410c7aeb59368 Mon Sep 17 00:00:00 2001 From: damon Date: Sat, 1 Jun 2024 09:23:10 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E4=BF=9D=E5=AD=98=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Starfish.Service/Domain/Aggregates/Configuration.cs | 8 +++++++- .../Domain/Business/ConfigurationPublishBusiness.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs index 7bfcb9a..50eac8c 100644 --- a/Source/Starfish.Service/Domain/Aggregates/Configuration.cs +++ b/Source/Starfish.Service/Domain/Aggregates/Configuration.cs @@ -137,10 +137,16 @@ internal void SetSecret(string secret) { throw new BadRequestException(Resources.IDS_ERROR_CONFIG_SECRET_NOT_MATCHES_RULE); } + + var secretHash = Cryptography.SHA.Encrypt(secret); if (!string.IsNullOrEmpty(Id)) { - RaiseEvent(new ConfigurationSecretChangedEvent(Cryptography.SHA.Encrypt(secret))); + RaiseEvent(new ConfigurationSecretChangedEvent(secretHash)); + } + else + { + Secret = secretHash; } } diff --git a/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs b/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs index 5ade11e..31bb84b 100644 --- a/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs +++ b/Source/Starfish.Service/Domain/Business/ConfigurationPublishBusiness.cs @@ -29,7 +29,7 @@ protected async Task ExecuteAsync(string id, string version, string comment, Can throw new ConfigurationNotFoundException(id); } - var permission = await TeamRepository.CheckPermissionAsync(id, Identity.UserId, cancellationToken); + var permission = await TeamRepository.CheckPermissionAsync(aggregate.TeamId, Identity.UserId, cancellationToken); switch (permission) { From 87c96332bab2ac75fcd6535784add6e61a0b0d66 Mon Sep 17 00:00:00 2001 From: damon Date: Sat, 1 Jun 2024 21:29:02 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E6=89=A9=E5=B1=95=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Starfish.Common/EnumExtensions.cs | 11 +++++- Source/Starfish.Common/GzipHelper.cs | 34 ++++++++++++++++++- .../ObservableRangeCollection.cs | 7 ++-- Source/Starfish.Common/UuidGenerator.cs | 9 ++--- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/Source/Starfish.Common/EnumExtensions.cs b/Source/Starfish.Common/EnumExtensions.cs index 6944f14..6c088a4 100644 --- a/Source/Starfish.Common/EnumExtensions.cs +++ b/Source/Starfish.Common/EnumExtensions.cs @@ -5,13 +5,22 @@ internal static class EnumExtensions { + /// + /// 获取枚举字段描述 + /// + /// + /// + /// + /// + /// public static string GetDescription(this Enum @enum, ResourceManager resourceManager, CultureInfo resourceCulture) { var field = @enum.GetType().GetField(@enum.ToString()); if (field == null) { - throw new NullReferenceException("field"); + throw new NullReferenceException($"Field ‘{@enum}’ not defined."); } + var attribute = field.GetCustomAttribute(); var key = attribute?.Description ?? @enum.ToString(); var value = resourceManager.GetString(key, resourceCulture); diff --git a/Source/Starfish.Common/GzipHelper.cs b/Source/Starfish.Common/GzipHelper.cs index c798f11..7c91f62 100644 --- a/Source/Starfish.Common/GzipHelper.cs +++ b/Source/Starfish.Common/GzipHelper.cs @@ -1,8 +1,16 @@ using System.IO.Compression; +// ReSharper disable MemberCanBePrivate.Global + namespace Nerosoft.Starfish.Common; + public static class GzipHelper { + /// + /// 使用Gzip压缩字符串并转换为Base64字符串 + /// + /// + /// public static string CompressToBase64(string source) { var buffer = Compress(source); @@ -10,6 +18,11 @@ public static string CompressToBase64(string source) return Convert.ToBase64String(buffer); } + /// + /// 使用Gzip压缩字符串 + /// + /// + /// public static byte[] Compress(string source) { var data = Encoding.UTF8.GetBytes(source); @@ -26,17 +39,36 @@ public static byte[] Compress(string source) return buffer; } + /// + /// 解压Base64字符串 + /// + /// + /// + /// + /// 此操作将Base64字符串解码为字节数组,然后解压缩 + /// public static string DecompressFromBase64(string base64Data) { var data = Convert.FromBase64String(base64Data); return Decompress(data); } + /// + /// 解压Gzip压缩的字节数组 + /// + /// + /// public static string Decompress(byte[] data) { return Decompress(data, data.Length); } + /// + /// 解压Gzip压缩的字节数组 + /// + /// + /// + /// public static string Decompress(byte[] data, int count) { var stream = new MemoryStream(data, 0, count); @@ -61,4 +93,4 @@ public static string Decompress(byte[] data, int count) destStream.Close(); return Encoding.UTF8.GetString(buffer); } -} +} \ No newline at end of file diff --git a/Source/Starfish.Common/ObservableRangeCollection.cs b/Source/Starfish.Common/ObservableRangeCollection.cs index fcba41a..1b92c00 100644 --- a/Source/Starfish.Common/ObservableRangeCollection.cs +++ b/Source/Starfish.Common/ObservableRangeCollection.cs @@ -51,12 +51,9 @@ public void AddRange(IEnumerable collection, NotifyCollectionChangedAction no return; } - var changedItems = collection is List - ? (List)collection - : new List(collection); + var changedItems = collection as List ?? [..collection]; - RaiseChangeNotificationEvents( - action: NotifyCollectionChangedAction.Add, + RaiseChangeNotificationEvents(action: NotifyCollectionChangedAction.Add, changedItems: changedItems, startingIndex: startIndex); } diff --git a/Source/Starfish.Common/UuidGenerator.cs b/Source/Starfish.Common/UuidGenerator.cs index 67e58db..3cca2a9 100644 --- a/Source/Starfish.Common/UuidGenerator.cs +++ b/Source/Starfish.Common/UuidGenerator.cs @@ -3,7 +3,7 @@ internal class UuidGenerator { public static string New() - { + { var bytes = Guid.NewGuid().ToByteArray(); var longValue = BitConverter.ToInt64(bytes, 0); var shortUuid = Base62Encode(longValue); @@ -13,14 +13,15 @@ public static string New() private static string Base62Encode(long value) { const string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - string result = ""; + var result = string.Empty; do { result = chars[(int)(value % 62)] + result; value /= 62; - } while (value > 0); + } + while (value > 0); return result; } -} +} \ No newline at end of file From d2f5644afbdd6e8bb9bc702c73039b4382f6afcd Mon Sep 17 00:00:00 2001 From: damon Date: Sat, 1 Jun 2024 21:38:06 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A2=E9=98=9F?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Starfish.Webapp/Pages/Configs/Edit.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Starfish.Webapp/Pages/Configs/Edit.razor b/Source/Starfish.Webapp/Pages/Configs/Edit.razor index 19a73b5..7631b48 100644 --- a/Source/Starfish.Webapp/Pages/Configs/Edit.razor +++ b/Source/Starfish.Webapp/Pages/Configs/Edit.razor @@ -138,7 +138,7 @@ private async Task LoadTeamsAsync() { - await TeamApi.QueryAsync(new TeamCriteria(), 1, 100) + await TeamApi.QueryAsync(new TeamCriteria(), 0, 100) .EnsureSuccess(result => { if (result == null) From 71bba831176228b973eff7dbf7eb036b65224d5b Mon Sep 17 00:00:00 2001 From: damon Date: Sun, 2 Jun 2024 00:36:31 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E8=AE=BF=E9=97=AEDbContext=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Subscribers/LoggingEventSubscriber.Auth.cs | 1 - .../Starfish.Service/Domain/Aggregates/TeamMember.cs | 11 ++++++++++- .../Contexts/RelationalDatabaseModelBuilder.cs | 2 +- .../Starfish.Service/Seedwork/CommandHandlerBase.cs | 8 ++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Auth.cs b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Auth.cs index b556022..2a442fc 100644 --- a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Auth.cs +++ b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Auth.cs @@ -1,5 +1,4 @@ using Nerosoft.Euonia.Bus; -using Nerosoft.Starfish.Domain; namespace Nerosoft.Starfish.Application; diff --git a/Source/Starfish.Service/Domain/Aggregates/TeamMember.cs b/Source/Starfish.Service/Domain/Aggregates/TeamMember.cs index 0fe0a00..4c0c3ae 100644 --- a/Source/Starfish.Service/Domain/Aggregates/TeamMember.cs +++ b/Source/Starfish.Service/Domain/Aggregates/TeamMember.cs @@ -5,7 +5,7 @@ namespace Nerosoft.Starfish.Domain; /// /// 团队成员实体 /// -public sealed class TeamMember : Entity, IHasCreateTime +public sealed class TeamMember : Entity, IHasCreateTime { private TeamMember() { @@ -17,10 +17,19 @@ private TeamMember(string userId) UserId = userId; } + /// + /// 用户Id + /// public string UserId { get; set; } + /// + /// 团队Id + /// public string TeamId { get; set; } + /// + /// 创建时间 + /// public DateTime CreateTime { get; set; } public User User { get; set; } diff --git a/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs b/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs index 3d0e0bb..6bd6686 100644 --- a/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs +++ b/Source/Starfish.Service/Repository/Contexts/RelationalDatabaseModelBuilder.cs @@ -31,7 +31,7 @@ protected override ModelBuilder ConfigureUser(ModelBuilder modelBuilder) .HasValueGenerator(); }); } - + protected override ModelBuilder ConfigureTeam(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => diff --git a/Source/Starfish.Service/Seedwork/CommandHandlerBase.cs b/Source/Starfish.Service/Seedwork/CommandHandlerBase.cs index 9ff2d90..2e0e1fd 100644 --- a/Source/Starfish.Service/Seedwork/CommandHandlerBase.cs +++ b/Source/Starfish.Service/Seedwork/CommandHandlerBase.cs @@ -50,7 +50,7 @@ protected virtual async Task ExecuteAsync(string messageId, [No var response = new CommandResponse(messageId); try { - using (var uow = UnitOfWork.Begin()) + using (var uow = UnitOfWork.Begin(true, true)) { await action(); await uow.CommitAsync(); @@ -79,7 +79,7 @@ protected virtual async Task> ExecuteAsync(str try { TResult result; - using (var uow = UnitOfWork.Begin()) + using (var uow = UnitOfWork.Begin(true, true)) { result = await action(); await uow.CommitAsync(); @@ -102,7 +102,7 @@ protected virtual async Task> ExecuteAsync(str /// protected virtual async Task ExecuteAsync([NotNull] Func action) { - using var uow = UnitOfWork.Begin(); + using var uow = UnitOfWork.Begin(true, true); await action(); await uow.CommitAsync(); } @@ -116,7 +116,7 @@ protected virtual async Task ExecuteAsync([NotNull] Func action) /// protected virtual async Task ExecuteAsync([NotNull] Func> action, Action next) { - using var uow = UnitOfWork.Begin(); + using var uow = UnitOfWork.Begin(true, true); var result = await action(); await uow.CommitAsync(); next(result); From 64b94c8825a081920a2679329a7fbcd08754708a Mon Sep 17 00:00:00 2001 From: damon Date: Sun, 2 Jun 2024 14:18:51 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E4=BF=AE=E6=AD=A3PGSQL=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documents/SCRIPTS_PGSQL.md | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Documents/SCRIPTS_PGSQL.md b/Documents/SCRIPTS_PGSQL.md index b0aa356..626f8a4 100644 --- a/Documents/SCRIPTS_PGSQL.md +++ b/Documents/SCRIPTS_PGSQL.md @@ -11,8 +11,7 @@ CREATE TABLE "public"."operate_log" ( "Error" varchar(2000) COLLATE "pg_catalog"."default", "RequestTraceId" varchar(40) COLLATE "pg_catalog"."default" NOT NULL, PRIMARY KEY ("Id") -) -; +); CREATE INDEX "IDX_OPERATE_LOG_MODULE" ON "public"."operate_log" USING btree ( "Module" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST @@ -40,7 +39,7 @@ CREATE TABLE "public"."configuration" ( "CreateTime" timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, "UpdateTime" timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, "CreatedBy" varchar(255) COLLATE "pg_catalog"."default" NOT NULL, - "UpdatedBy" date NOT NULL, + "UpdatedBy" varchar(255) COLLATE "pg_catalog"."default" NOT NULL, PRIMARY KEY ("Id") ); @@ -61,14 +60,11 @@ CREATE UNIQUE INDEX "IDX_CONFIG_UNIQUE" ON "public"."configuration" USING btree ```sql CREATE TABLE "public"."configuration_archive" ( "Id" varchar(32) COLLATE "pg_catalog"."default" NOT NULL, - "AppId" varchar(32) COLLATE "pg_catalog"."default" NOT NULL, - "Environment" varchar(50) COLLATE "pg_catalog"."default" NOT NULL, "Data" text COLLATE "pg_catalog"."default", "Operator" varchar(64) COLLATE "pg_catalog"."default" NOT NULL, "ArchiveTime" timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY ("Id") -) -; +); ``` # configuration_item @@ -79,11 +75,8 @@ CREATE TABLE "public"."configuration_item" ( "ConfigurationId" varchar(32) COLLATE "pg_catalog"."default" NOT NULL, "Key" varchar(255) COLLATE "pg_catalog"."default" NOT NULL, "Value" text COLLATE "pg_catalog"."default", - "UpdatedTime" timestamp(6) NOT NULL, - "UpdatedBy" varchar(64) COLLATE "pg_catalog"."default" NOT NULL, PRIMARY KEY ("Id") -) -; +); CREATE INDEX "IDX_CONFIG_ITEM_FK" ON "public"."configuration_item" USING btree ( "ConfigurationId" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST @@ -106,8 +99,7 @@ CREATE TABLE "public"."configuration_revision" ( "Operator" varchar(64) COLLATE "pg_catalog"."default" NOT NULL, "CreateTime" timestamp(6) NOT NULL, PRIMARY KEY ("Id") -) -; +); CREATE INDEX "IDS_CONFIG_REVISION_FK" ON "public"."configuration_revision" USING btree ( "ConfigurationId" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST From 92602328db6818b4ce01dbcaad93ecc5123a4110 Mon Sep 17 00:00:00 2001 From: damon Date: Sun, 2 Jun 2024 14:19:44 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/OperateLogCreateCommand.cs | 2 +- .../Handlers/OperateLogCommandHandler.cs | 2 +- .../Mappings/LogsMappingProfile.cs | 16 +++++++-- .../LoggingEventSubscriber.Auth.cs | 3 +- .../LoggingEventSubscriber.Config.cs | 33 ++++++++++++------- .../Properties/Resources.resx | 22 ++++++------- 6 files changed, 48 insertions(+), 30 deletions(-) diff --git a/Source/Starfish.Service/Application/Commands/OperateLogCreateCommand.cs b/Source/Starfish.Service/Application/Commands/OperateLogCreateCommand.cs index ce96fae..f760d81 100644 --- a/Source/Starfish.Service/Application/Commands/OperateLogCreateCommand.cs +++ b/Source/Starfish.Service/Application/Commands/OperateLogCreateCommand.cs @@ -20,7 +20,7 @@ public class OperateLogCreateCommand : Command /// /// 描述 /// - public string Description { get; set; } + public string Content { get; set; } /// /// 用户名 diff --git a/Source/Starfish.Service/Application/Handlers/OperateLogCommandHandler.cs b/Source/Starfish.Service/Application/Handlers/OperateLogCommandHandler.cs index 7f2a8ec..549f56c 100644 --- a/Source/Starfish.Service/Application/Handlers/OperateLogCommandHandler.cs +++ b/Source/Starfish.Service/Application/Handlers/OperateLogCommandHandler.cs @@ -31,7 +31,7 @@ public Task HandleAsync(OperateLogCreateCommand message, MessageContext context, { return ExecuteAsync(async () => { - var entity = OperateLog.Create(message.Module, message.Type, message.Description, message.UserName, message.OperateTime, message.Error, message.RequestTraceId); + var entity = OperateLog.Create(message.Module, message.Type, message.Content, message.UserName, message.OperateTime, message.Error, message.RequestTraceId); await _repository.InsertAsync(entity, true, cancellationToken); }); } diff --git a/Source/Starfish.Service/Application/Mappings/LogsMappingProfile.cs b/Source/Starfish.Service/Application/Mappings/LogsMappingProfile.cs index 167682c..af4915b 100644 --- a/Source/Starfish.Service/Application/Mappings/LogsMappingProfile.cs +++ b/Source/Starfish.Service/Application/Mappings/LogsMappingProfile.cs @@ -1,6 +1,7 @@ using AutoMapper; using Nerosoft.Starfish.Domain; using Nerosoft.Starfish.Transit; +using Newtonsoft.Json; namespace Nerosoft.Starfish.Application; @@ -20,15 +21,24 @@ public LogsMappingProfile() private static string GetDescription(OperateLog source, OperateLogDto destination, object obj, ResolutionContext context) { - var key = $"IDS_LOG_MESSAGE_{source.Module}_{source.Type}".Normalize(TextCaseType.Upper).Replace(".", "_"); + var key = $"IDS_MESSAGE_LOGS_{source.Module}_{source.Type}".Normalize(TextCaseType.Upper).Replace(".", "_"); var value = Resources.ResourceManager.GetString(key); - if (string.IsNullOrEmpty(value)) + if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(source.Content)) { return value; } - return string.Format(value, source.Content); + try + { + var args = JsonConvert.DeserializeObject(source.Content); + + return string.Format(value, args); + } + catch + { + return value; + } } } \ No newline at end of file diff --git a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Auth.cs b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Auth.cs index 2a442fc..17206ed 100644 --- a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Auth.cs +++ b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Auth.cs @@ -22,7 +22,6 @@ public Task HandleAsync(UserAuthSucceedEvent @event, MessageContext context, Can Type = @event.AuthType, UserName = @event.UserName, OperateTime = DateTime.Now, - Description = Resources.IDS_MESSAGE_LOGS_AUTH_SUCCEED, RequestTraceId = context.RequestTraceId }; return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); @@ -42,7 +41,7 @@ public Task HandleAsync(UserAuthFailedEvent @event, MessageContext context, Canc { Module = MODULE_AUTH, Type = @event.AuthType, - Description = Resources.IDS_MESSAGE_LOGS_AUTH_FAILED, + Content = Resources.IDS_MESSAGE_LOGS_AUTH_FAILED, OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, Error = @event.Error diff --git a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Config.cs b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Config.cs index d309122..794df55 100644 --- a/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Config.cs +++ b/Source/Starfish.Service/Application/Subscribers/LoggingEventSubscriber.Config.cs @@ -1,5 +1,6 @@ using Nerosoft.Euonia.Bus; using Nerosoft.Starfish.Domain; +using Newtonsoft.Json; namespace Nerosoft.Starfish.Application; @@ -22,7 +23,7 @@ public Task HandleAsync(ConfigurationEnabledEvent @event, MessageContext context { Module = MODULE_CONFIG, Type = "status.enable", - Description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_ENABLE, aggregate.Id, aggregate.Name), + Content = GenerateLogContent(aggregate.Id, aggregate.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name @@ -46,7 +47,7 @@ public Task HandleAsync(ConfigurationDisableEvent @event, MessageContext context { Module = MODULE_CONFIG, Type = "status.disable", - Description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_DISABLE, aggregate.Id, aggregate.Name), + Content = GenerateLogContent(aggregate.Id, aggregate.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name @@ -70,7 +71,7 @@ public Task HandleAsync(ConfigurationSecretChangedEvent @event, MessageContext c { Module = MODULE_CONFIG, Type = "secret", - Description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_RESET_SECRET, aggregate.Id, aggregate.Name), + Content = GenerateLogContent(aggregate.Id, aggregate.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name @@ -94,7 +95,7 @@ public Task HandleAsync(ConfigurationUpdatedEvent @event, MessageContext context { Module = MODULE_CONFIG, Type = "update", - Description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_UPDATE, aggregate.Id, aggregate.Name), + Content = GenerateLogContent(aggregate.Id, aggregate.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name @@ -113,13 +114,11 @@ public Task HandleAsync(ConfigurationUpdatedEvent @event, MessageContext context [Subscribe] public Task HandleAsync(ConfigurationCreatedEvent @event, MessageContext context, CancellationToken cancellationToken = default) { - var description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_CREATE, @event.Configuration.Id, @event.Configuration.Name); - var command = new OperateLogCreateCommand { Module = MODULE_CONFIG, Type = "create", - Description = description, + Content = GenerateLogContent(@event.Configuration.Id, @event.Configuration.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name @@ -138,13 +137,12 @@ public Task HandleAsync(ConfigurationCreatedEvent @event, MessageContext context public Task HandleAsync(ConfigurationDeletedEvent @event, MessageContext context, CancellationToken cancellationToken = default) { var aggregate = @event.GetAggregate(); - var description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_DELETE, aggregate.Id, aggregate.Name); var command = new OperateLogCreateCommand { Module = MODULE_CONFIG, Type = "delete", - Description = description, + Content = GenerateLogContent(aggregate.Id, aggregate.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name @@ -163,17 +161,28 @@ public Task HandleAsync(ConfigurationDeletedEvent @event, MessageContext context public Task HandleAsync(ConfigurationPublishedEvent @event, MessageContext context, CancellationToken cancellationToken = default) { var aggregate = @event.GetAggregate(); - var description = string.Format(Resources.IDS_MESSAGE_LOGS_CONFIG_PUBLISH, aggregate.Id, aggregate.Name); var command = new OperateLogCreateCommand { Module = MODULE_CONFIG, Type = "publish", - Description = description, + Content = GenerateLogContent(aggregate.Id, aggregate.Name), OperateTime = DateTime.Now, RequestTraceId = context.RequestTraceId, UserName = context.User?.Identity?.Name }; return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken); } -} + + private static string GenerateLogContent(params object[] args) + { + if (args == null || args.Length == 0) + { + return string.Empty; + } + + var items = args.Select(t => t.ToString()); + + return JsonConvert.SerializeObject(items); + } +} \ No newline at end of file diff --git a/Source/Starfish.Service/Properties/Resources.resx b/Source/Starfish.Service/Properties/Resources.resx index 45f5b53..f7d2326 100644 --- a/Source/Starfish.Service/Properties/Resources.resx +++ b/Source/Starfish.Service/Properties/Resources.resx @@ -258,37 +258,37 @@ UserName '{0}' not available. - + Login with one-time-password - + Login with password - + Refresh token - + Create team - + Add new member - + Remove member - + Update team - + Create user - + Change password - + Reset password - + Update user From 147dd5c182690fa0f03ded28aa017a1a4acb8760 Mon Sep 17 00:00:00 2001 From: damon Date: Sun, 2 Jun 2024 14:36:22 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E5=88=A0=E9=99=A4DataTimeStorageConverte?= =?UTF-8?q?r,=20=E4=BD=BF=E7=94=A8UniversalTimeConverter=E6=9B=BF=E4=BB=A3?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/Contexts/DataContext.cs | 4 +-- .../Repository/DateTimeStorageConverter.cs | 31 ------------------- 2 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 Source/Starfish.Service/Repository/DateTimeStorageConverter.cs diff --git a/Source/Starfish.Service/Repository/Contexts/DataContext.cs b/Source/Starfish.Service/Repository/Contexts/DataContext.cs index ef2bd15..afb916b 100644 --- a/Source/Starfish.Service/Repository/Contexts/DataContext.cs +++ b/Source/Starfish.Service/Repository/Contexts/DataContext.cs @@ -112,9 +112,9 @@ protected override void ConfigureConventions(ModelConfigurationBuilder configura { base.ConfigureConventions(configurationBuilder); configurationBuilder.Properties() - .HaveConversion(); + .HaveConversion(); configurationBuilder.Properties() - .HaveConversion(); + .HaveConversion(); } private List GetTrackedEvents() diff --git a/Source/Starfish.Service/Repository/DateTimeStorageConverter.cs b/Source/Starfish.Service/Repository/DateTimeStorageConverter.cs deleted file mode 100644 index 39d78dd..0000000 --- a/Source/Starfish.Service/Repository/DateTimeStorageConverter.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace Nerosoft.Starfish.Repository; - -public class DateTimeStorageConverter : ValueConverter -{ - public DateTimeStorageConverter() - : base(t => ConvertToUniversalTime(t), t => ConvertToLocalTime(t)) - { - } - - private static DateTime ConvertToUniversalTime(DateTime time) - { - return time.Kind switch - { - DateTimeKind.Unspecified => DateTime.SpecifyKind(time, DateTimeKind.Local).ToUniversalTime(), - DateTimeKind.Local => time.ToUniversalTime(), - _ => time - }; - } - - private static DateTime ConvertToLocalTime(DateTime time) - { - return time.Kind switch - { - DateTimeKind.Unspecified => DateTime.SpecifyKind(time, DateTimeKind.Utc).ToLocalTime(), - DateTimeKind.Utc => time.ToLocalTime(), - _ => time - }; - } -} \ No newline at end of file From 80363ff9d4525384a409cd6b7ce9432d3b98bf2e Mon Sep 17 00:00:00 2001 From: damon Date: Sun, 2 Jun 2024 14:36:35 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E5=8D=87=E7=BA=A7Euonia=E5=8C=85?= =?UTF-8?q?=E6=9C=AC=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 7d221f7..4aa0045 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,7 +2,7 @@ true true - 8.1.24 + 8.1.25 4.7.2 From ca6ca31fae730ba17629de697589651ebe25ca13 Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 3 Jun 2024 00:16:16 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Starfish.Webapp/Pages/Configs/Index.razor | 2 +- Source/Starfish.Webapp/Pages/Team/Index.razor | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/Starfish.Webapp/Pages/Configs/Index.razor b/Source/Starfish.Webapp/Pages/Configs/Index.razor index 15d4740..141dfd5 100644 --- a/Source/Starfish.Webapp/Pages/Configs/Index.razor +++ b/Source/Starfish.Webapp/Pages/Configs/Index.razor @@ -118,7 +118,7 @@ var title = string.IsNullOrEmpty(id) ? Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_ADD : Resources.IDS_CONFIG_EDIT_DIALOG_TITLE_EDIT; var dialog = await DialogService.ShowDialogAsync(id, new DialogParameters { Title = title, PreventDismissOnOverlayClick = true }); var result = await dialog.Result; - if (result.Cancelled) + if (!result.Cancelled) { await Pagination.SetCurrentPageIndexAsync(0); } diff --git a/Source/Starfish.Webapp/Pages/Team/Index.razor b/Source/Starfish.Webapp/Pages/Team/Index.razor index b3def26..07d7d1e 100644 --- a/Source/Starfish.Webapp/Pages/Team/Index.razor +++ b/Source/Starfish.Webapp/Pages/Team/Index.razor @@ -99,7 +99,12 @@ private async Task OnEditClicked(string id) { var title = string.IsNullOrEmpty(id) ? Resources.IDS_TEAM_EDIT_TITLE_ADD : Resources.IDS_TEAM_EDIT_TITLE_EDIT; - await DialogService.ShowDialogAsync(id ?? string.Empty, new DialogParameters { Title = title, PreventDismissOnOverlayClick = true }); + var dialog = await DialogService.ShowDialogAsync(id ?? string.Empty, new DialogParameters { Title = title, PreventDismissOnOverlayClick = true }); + var result = await dialog.Result; + if (!result.Cancelled) + { + await Pagination.SetCurrentPageIndexAsync(0); + } } private async Task OnSearchClicked() From 6e9a599b350ab9898ecc16101308cba891914152 Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 3 Jun 2024 00:18:18 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E4=B8=BA=E7=A9=BA=E6=97=B6=E4=B8=8D=E5=8F=91?= =?UTF-8?q?=E8=B5=B7=E8=AF=B7=E6=B1=82=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Starfish.Client/StarfishConfigurationProvider.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/Starfish.Client/StarfishConfigurationProvider.cs b/Source/Starfish.Client/StarfishConfigurationProvider.cs index 14dd668..b1716c3 100644 --- a/Source/Starfish.Client/StarfishConfigurationProvider.cs +++ b/Source/Starfish.Client/StarfishConfigurationProvider.cs @@ -55,11 +55,16 @@ public override void Load() private async void OnHostChanged(object sender, HostChangedEventArgs args) { + if (string.IsNullOrWhiteSpace(args.Host)) + { + return; + } + var uri = new Uri(args.Host); IConfigurationClient client = uri.Scheme switch { - "http" or "https" => new HttpConfigurationClient(uri, _options.Id, _options.Secret), - "ws" or "wss" => new SocketConfigurationClient(uri, _options.Id, _options.Secret), + "http" or "https" => new HttpConfigurationClient(uri, _options.Id, _options.Secret), + "ws" or "wss" => new SocketConfigurationClient(uri, _options.Id, _options.Secret), _ => throw new NotSupportedException(string.Format(Resources.IDS_ERROR_SCHEMA_NOT_SUPPORTED, uri.Scheme)), }; try From 732c15d8f405d8b7dd87b687ef532dfb7284222e Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 3 Jun 2024 00:34:15 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B5=84=E6=BA=90Key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Properties/Resources.resx | 54 +++++++++---------- .../Properties/Resources.zh-Hans.resx | 33 ++++++++++++ 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/Source/Starfish.Service/Properties/Resources.resx b/Source/Starfish.Service/Properties/Resources.resx index f7d2326..9708595 100644 --- a/Source/Starfish.Service/Properties/Resources.resx +++ b/Source/Starfish.Service/Properties/Resources.resx @@ -258,6 +258,9 @@ UserName '{0}' not available. + + User authenticate failed. + Login with one-time-password @@ -267,33 +270,6 @@ Refresh token - - Create team - - - Add new member - - - Remove member - - - Update team - - - Create user - - - Change password - - - Reset password - - - Update user - - - User authenticate failed. - User authenticate successfully. @@ -318,4 +294,28 @@ Update configuration, [Id]:{0}, [Name]:{1}. + + Create user + + + Create team + + + Add new member + + + Remove member + + + Update team + + + Change password + + + Reset password + + + Update user + \ No newline at end of file diff --git a/Source/Starfish.Service/Properties/Resources.zh-Hans.resx b/Source/Starfish.Service/Properties/Resources.zh-Hans.resx index 42dc9ad..9dd6519 100644 --- a/Source/Starfish.Service/Properties/Resources.zh-Hans.resx +++ b/Source/Starfish.Service/Properties/Resources.zh-Hans.resx @@ -307,6 +307,15 @@ 用户认证失败。 + + 验证码登录 + + + 账号密码登录 + + + 令牌登录 + 用户认证成功。 @@ -339,4 +348,28 @@ 更新配置,[Id]:{0},[名称]:{1}。 + + 新增用户 + + + 新增团队 + + + 添加团队成员 + + + 移除团队成员 + + + 编辑团队信息 + + + 修改登录密码 + + + 重置登录密码 + + + 编辑用户信息 + \ No newline at end of file From 93b9db48fdffe562dd271806bbcdd0feedcee18a Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 3 Jun 2024 00:41:46 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E7=BF=BB=E8=AF=91=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Properties/Resources.zh-Hant.resx | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Source/Starfish.Service/Properties/Resources.zh-Hant.resx b/Source/Starfish.Service/Properties/Resources.zh-Hant.resx index c810ce7..b1ff373 100644 --- a/Source/Starfish.Service/Properties/Resources.zh-Hant.resx +++ b/Source/Starfish.Service/Properties/Resources.zh-Hant.resx @@ -339,4 +339,37 @@ 更新配置,[Id]:{0},[名稱]:{1}。 + + 驗證碼登錄 + + + 帳號密碼登錄 + + + 令牌登錄 + + + 創建用戶 + + + 創建團隊 + + + 添加新成員 + + + 移除團隊成員 + + + 編輯團隊訊息 + + + 更改密碼 + + + 重設密碼 + + + 編輯用戶訊息 + \ No newline at end of file From 28f929acda886622d7f87d17ca141f7d1bcac261 Mon Sep 17 00:00:00 2001 From: damon Date: Mon, 3 Jun 2024 00:42:16 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Starfish.Webapp/Layout/MainLayout.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Starfish.Webapp/Layout/MainLayout.razor b/Source/Starfish.Webapp/Layout/MainLayout.razor index 857d1b0..546d3b4 100644 --- a/Source/Starfish.Webapp/Layout/MainLayout.razor +++ b/Source/Starfish.Webapp/Layout/MainLayout.razor @@ -73,7 +73,7 @@ - +
Nerosoft © @(DateTime.Today.Year). All rights reserved.