Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #33

Merged
merged 15 commits into from
Jun 2, 2024
40 changes: 20 additions & 20 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<EnablePackageVersionOverride>true</EnablePackageVersionOverride>
<EuoniaPackageVersion>8.1.24</EuoniaPackageVersion>
<EuoniaPackageVersion>8.1.25</EuoniaPackageVersion>
<FluentBlazorPackageVersion>4.7.2</FluentBlazorPackageVersion>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -31,18 +31,18 @@
<PackageVersion Include="Euonia.Validation" Version="$(EuoniaPackageVersion)" />
<PackageVersion Include="Euonia.Repository.EfCore" Version="$(EuoniaPackageVersion)" />
<PackageVersion Include="Google.Api.CommonProtos" Version="2.15.0" />
<PackageVersion Include="Google.Protobuf" Version="3.26.1" />
<PackageVersion Include="Grpc.Net.Client" Version="2.62.0" />
<PackageVersion Include="Grpc.Tools" Version="2.63.0" />
<PackageVersion Include="Google.Protobuf" Version="3.27.0" />
<PackageVersion Include="Grpc.Net.Client" Version="2.63.0" />
<PackageVersion Include="Grpc.Tools" Version="2.64.0" />
<PackageVersion Include="IdentityModel" Version="7.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.6" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.FeatureManagement.AspNetCore" Version="3.2.0" />
<PackageVersion Include="Microsoft.FeatureManagement.AspNetCore" Version="3.3.1" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components" Version="$(FluentBlazorPackageVersion)" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="$(FluentBlazorPackageVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
Expand All @@ -51,16 +51,16 @@
<PackageVersion Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageVersion Include="Refit.Newtonsoft.Json" Version="7.0.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.7.33" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.6" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageVersion Include="MongoDB.EntityFrameworkCore" Version="8.0.0" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageVersion Include="MongoDB.EntityFrameworkCore" Version="8.0.1" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="ConfigureAwait.Fody" Version="3.3.2">
Expand Down Expand Up @@ -102,9 +102,9 @@
<!-- Tests -->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="xunit" Version="2.7.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="xunit" Version="2.8.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
Expand Down
18 changes: 5 additions & 13 deletions Documents/SCRIPTS_PGSQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
);

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions Source/Starfish.Client/StarfishConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion Source/Starfish.Common/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@

internal static class EnumExtensions
{
/// <summary>
/// 获取枚举字段描述
/// </summary>
/// <param name="enum"></param>
/// <param name="resourceManager"></param>
/// <param name="resourceCulture"></param>
/// <returns></returns>
/// <exception cref="NullReferenceException"></exception>
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<DescriptionAttribute>();
var key = attribute?.Description ?? @enum.ToString();
var value = resourceManager.GetString(key, resourceCulture);
Expand Down
34 changes: 33 additions & 1 deletion Source/Starfish.Common/GzipHelper.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
using System.IO.Compression;

// ReSharper disable MemberCanBePrivate.Global

namespace Nerosoft.Starfish.Common;

public static class GzipHelper
{
/// <summary>
/// 使用Gzip压缩字符串并转换为Base64字符串
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static string CompressToBase64(string source)
{
var buffer = Compress(source);

return Convert.ToBase64String(buffer);
}

/// <summary>
/// 使用Gzip压缩字符串
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static byte[] Compress(string source)
{
var data = Encoding.UTF8.GetBytes(source);
Expand All @@ -26,17 +39,36 @@ public static byte[] Compress(string source)
return buffer;
}

/// <summary>
/// 解压Base64字符串
/// </summary>
/// <param name="base64Data"></param>
/// <returns></returns>
/// <remarks>
/// 此操作将Base64字符串解码为字节数组,然后解压缩
/// </remarks>
public static string DecompressFromBase64(string base64Data)
{
var data = Convert.FromBase64String(base64Data);
return Decompress(data);
}

/// <summary>
/// 解压Gzip压缩的字节数组
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string Decompress(byte[] data)
{
return Decompress(data, data.Length);
}

/// <summary>
/// 解压Gzip压缩的字节数组
/// </summary>
/// <param name="data"></param>
/// <param name="count"></param>
/// <returns></returns>
public static string Decompress(byte[] data, int count)
{
var stream = new MemoryStream(data, 0, count);
Expand All @@ -61,4 +93,4 @@ public static string Decompress(byte[] data, int count)
destStream.Close();
return Encoding.UTF8.GetString(buffer);
}
}
}
7 changes: 2 additions & 5 deletions Source/Starfish.Common/ObservableRangeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ public void AddRange(IEnumerable<T> collection, NotifyCollectionChangedAction no
return;
}

var changedItems = collection is List<T>
? (List<T>)collection
: new List<T>(collection);
var changedItems = collection as List<T> ?? [..collection];

RaiseChangeNotificationEvents(
action: NotifyCollectionChangedAction.Add,
RaiseChangeNotificationEvents(action: NotifyCollectionChangedAction.Add,
changedItems: changedItems,
startingIndex: startIndex);
}
Expand Down
9 changes: 5 additions & 4 deletions Source/Starfish.Common/UuidGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class OperateLogCreateCommand : Command
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
public string Content { get; set; }

/// <summary>
/// 用户名
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
16 changes: 13 additions & 3 deletions Source/Starfish.Service/Application/Mappings/LogsMappingProfile.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutoMapper;
using Nerosoft.Starfish.Domain;
using Nerosoft.Starfish.Transit;
using Newtonsoft.Json;

namespace Nerosoft.Starfish.Application;

Expand All @@ -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<object[]>(source.Content);

return string.Format(value, args);
}
catch
{
return value;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Nerosoft.Euonia.Bus;
using Nerosoft.Starfish.Domain;

namespace Nerosoft.Starfish.Application;

Expand All @@ -23,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);
Expand All @@ -43,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
Expand Down
Loading
Loading