Skip to content

Commit

Permalink
Merge pull request #15 from NerosoftDev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Codespilot authored Jan 20, 2024
2 parents 01730cb + a3072eb commit 838180c
Show file tree
Hide file tree
Showing 49 changed files with 660 additions and 314 deletions.
20 changes: 15 additions & 5 deletions Source/Starfish.Client/Clients/HttpConfigurationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ internal class HttpConfigurationClient : IConfigurationClient
{
private readonly HttpClient _httpClient = new();

private readonly string _team;
private readonly string _app;
private readonly string _secret;
private readonly string _env;

public HttpConfigurationClient(Uri host, string team, string app, string secret, string env)
{
_httpClient.BaseAddress = host;
_httpClient.DefaultRequestHeaders.Add(Constants.RequestHeaders.Team, team);
_httpClient.DefaultRequestHeaders.Add(Constants.RequestHeaders.App, app);
_httpClient.DefaultRequestHeaders.Add(Constants.RequestHeaders.Secret, secret);
_httpClient.DefaultRequestHeaders.Add(Constants.RequestHeaders.Env, env);
_team = team;
_app = app;
_secret = secret;
_env = env;

// _httpClient.DefaultRequestHeaders.Add(Constants.RequestHeaders.Team, team);
// _httpClient.DefaultRequestHeaders.Add(Constants.RequestHeaders.App, app);
// _httpClient.DefaultRequestHeaders.Add(Constants.RequestHeaders.Secret, secret);
// _httpClient.DefaultRequestHeaders.Add(Constants.RequestHeaders.Env, env);
}

public async Task GetConfigurationAsync(Action<byte[], int> dataAction, CancellationToken cancellationToken = default)
Expand All @@ -20,7 +30,7 @@ public async Task GetConfigurationAsync(Action<byte[], int> dataAction, Cancella
try
{
attempts++;
using var request = new HttpRequestMessage(HttpMethod.Get, "es");
using var request = new HttpRequestMessage(HttpMethod.Get, $"es?team={_team}&app={_app}&secret={_secret}&env={_env}");

var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);

Expand Down
14 changes: 7 additions & 7 deletions Source/Starfish.Client/Clients/SocketConfigurationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ internal class SocketConfigurationClient : IConfigurationClient
private readonly ClientWebSocket _client = new();
private readonly Uri _uri;

public SocketConfigurationClient(Uri host,string team, string app, string secret, string env)
public SocketConfigurationClient(Uri host, string team, string app, string secret, string env)
{
_uri = new Uri($"{host.AbsoluteUri}ws");
_client.Options.SetRequestHeader(Constants.RequestHeaders.Team, team);
_client.Options.SetRequestHeader(Constants.RequestHeaders.App, app);
_client.Options.SetRequestHeader(Constants.RequestHeaders.Secret, secret);
_client.Options.SetRequestHeader(Constants.RequestHeaders.Env, env);
_uri = new Uri($"{host.AbsoluteUri}ws?team={team}&app={app}&secret={secret}&env={env}");
// _client.Options.SetRequestHeader(Constants.RequestHeaders.Team, team);
// _client.Options.SetRequestHeader(Constants.RequestHeaders.App, app);
// _client.Options.SetRequestHeader(Constants.RequestHeaders.Secret, secret);
// _client.Options.SetRequestHeader(Constants.RequestHeaders.Env, env);
}

public async Task GetConfigurationAsync(Action<byte[], int> dataAction, CancellationToken cancellationToken = default)
{
var attempts = 0;

RUN:
RUN:
try
{
attempts++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public interface IAppsApplicationService : IApplicationService
/// 获取符合条件的应用列表
/// </summary>
/// <param name="criteria">查询条件</param>
/// <param name="page">页码</param>
/// <param name="size">数量</param>
/// <param name="skip">页码</param>
/// <param name="count">数量</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<List<AppInfoItemDto>> SearchAsync(AppInfoCriteria criteria, int page, int size, CancellationToken cancellationToken = default);
Task<List<AppInfoItemDto>> QueryAsync(AppInfoCriteria criteria, int skip, int count, CancellationToken cancellationToken = default);

/// <summary>
/// 获取符合条件的应用数量
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,4 @@ public interface IDictionaryApplicationService : IApplicationService
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<List<DictionaryItemDto>> GetDatabaseTypeItemsAsync(CancellationToken cancellationToken = default);

/// <summary>
/// 获取可用的配置节点类型列表
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<List<DictionaryItemDto>> GetSettingItemTypeItemsAsync(CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public interface ILogsApplicationService : IApplicationService
/// 搜索日志
/// </summary>
/// <param name="criteria"></param>
/// <param name="page"></param>
/// <param name="size"></param>
/// <param name="skip"></param>
/// <param name="count"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<List<OperateLogDto>> QueryAsync(OperateLogCriteria criteria, int page, int size, CancellationToken cancellationToken = default);
Task<List<OperateLogDto>> QueryAsync(OperateLogCriteria criteria, int skip, int count, CancellationToken cancellationToken = default);

/// <summary>
/// 查询日志数量
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public interface ISettingApplicationService : IApplicationService
/// </summary>
/// <param name="appId"></param>
/// <param name="environment"></param>
/// <param name="page"></param>
/// <param name="size"></param>
/// <param name="skip"></param>
/// <param name="count"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<List<SettingItemDto>> GetItemListAsync(long appId, string environment, int page, int size, CancellationToken cancellationToken = default);
Task<List<SettingItemDto>> GetItemListAsync(long appId, string environment, int skip, int count, CancellationToken cancellationToken = default);

/// <summary>
/// 获取配置项数量
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Nerosoft.Starfish.Application;

public interface ITeamApplicationService : IApplicationService
{
Task<List<TeamItemDto>> QueryAsync(TeamCriteria criteria, int page, int size, CancellationToken cancellationToken = default);
Task<List<TeamItemDto>> QueryAsync(TeamCriteria criteria, int skip, int count, CancellationToken cancellationToken = default);

Task<int> CountAsync(TeamCriteria criteria, CancellationToken cancellationToken = default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public interface IUserApplicationService : IApplicationService
/// 查询符合条件的用户列表
/// </summary>
/// <param name="criteria"></param>
/// <param name="size"></param>
/// <param name="count"></param>
/// <param name="cancellationToken"></param>
/// <param name="page"></param>
/// <param name="skip"></param>
/// <returns></returns>
Task<List<UserItemDto>> SearchAsync(UserCriteria criteria, int page, int size, CancellationToken cancellationToken = default);
Task<List<UserItemDto>> QueryAsync(UserCriteria criteria, int skip, int count, CancellationToken cancellationToken = default);

/// <summary>
/// 查询符合条件的用户数量
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace Nerosoft.Starfish.Application;
public class AppsApplicationService : BaseApplicationService, IAppsApplicationService
{
/// <inheritdoc />
public Task<List<AppInfoItemDto>> SearchAsync(AppInfoCriteria criteria, int page, int size, CancellationToken cancellationToken = default)
public Task<List<AppInfoItemDto>> QueryAsync(AppInfoCriteria criteria, int skip, int count, CancellationToken cancellationToken = default)
{
var input = new AppInfoSearchInput(criteria, page, size);
var useCase = LazyServiceProvider.GetRequiredService<IAppInfoSearchUseCase>();
var input = new AppInfoQueryInput(criteria, skip, count);
var useCase = LazyServiceProvider.GetRequiredService<IAppInfoQueryUseCase>();
return useCase.ExecuteAsync(input, cancellationToken)
.ContinueWith(task => task.Result.Result, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,43 +105,4 @@ public Task<List<DictionaryItemDto>> GetDatabaseTypeItemsAsync(CancellationToken
};
return Task.FromResult(items);
}

/// <inheritdoc />
public Task<List<DictionaryItemDto>> GetSettingItemTypeItemsAsync(CancellationToken cancellationToken = default)
{
var items = new List<DictionaryItemDto>
{
new()
{
Name = nameof(SettingItemType.Root),
Description = Resources.IDS_ENUM_SETTING_ITEM_TYPE_ROOT
},
new()
{
Name = nameof(SettingItemType.Array),
Description = Resources.IDS_ENUM_SETTING_ITEM_TYPE_ARRAY
},
new()
{
Name = nameof(SettingItemType.Object),
Description = Resources.IDS_ENUM_SETTING_ITEM_TYPE_OBJECT
},
new()
{
Name = nameof(SettingItemType.String),
Description = Resources.IDS_ENUM_SETTING_ITEM_TYPE_STRING
},
new()
{
Name = nameof(SettingItemType.Number),
Description = Resources.IDS_ENUM_SETTING_ITEM_TYPE_NUMBER
},
new()
{
Name = nameof(SettingItemType.Boolean),
Description = Resources.IDS_ENUM_SETTING_ITEM_TYPE_BOOLEAN
}
};
return Task.FromResult(items);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Nerosoft.Starfish.Application;
public class LogsApplicationService : BaseApplicationService, ILogsApplicationService
{
/// <inheritdoc />
public Task<List<OperateLogDto>> QueryAsync(OperateLogCriteria criteria, int page, int size, CancellationToken cancellationToken = default)
public Task<List<OperateLogDto>> QueryAsync(OperateLogCriteria criteria, int skip, int count, CancellationToken cancellationToken = default)
{
var useCase = LazyServiceProvider.GetService<ILogsQueryUseCase>();
return useCase.ExecuteAsync(new LogsQueryUseCaseInput(criteria, page, size), cancellationToken)
return useCase.ExecuteAsync(new LogsQueryUseCaseInput(criteria, skip, count), cancellationToken)
.ContinueWith(task => task.Result.Logs, cancellationToken);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace Nerosoft.Starfish.Application;
public class SettingApplicationService : BaseApplicationService, ISettingApplicationService
{
/// <inheritdoc />
public Task<List<SettingItemDto>> GetItemListAsync(long appId, string environment, int page, int size, CancellationToken cancellationToken = default)
public Task<List<SettingItemDto>> GetItemListAsync(long appId, string environment, int skip, int count, CancellationToken cancellationToken = default)
{
var useCase = LazyServiceProvider.GetRequiredService<IGetSettingItemListUseCase>();
var input = new GetSettingItemListInput(appId, environment, page, size);
var input = new GetSettingItemListInput(appId, environment, skip, count);
return useCase.ExecuteAsync(input, cancellationToken)
.ContinueWith(t => t.Result.Result, cancellationToken);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public Task<string> GetSettingRawAsync(long appId, string environment, Cancellat
public Task<string> GetItemsInTextAsync(long appId, string environment, string type, CancellationToken cancellationToken = default)
{
var parser = LazyServiceProvider.GetRequiredService<IServiceProvider>().GetNamedService<IConfigurationParser>(type.ToLower(CultureInfo.CurrentCulture));
return GetItemListAsync(appId, environment, 1, int.MaxValue, cancellationToken)
return GetItemListAsync(appId, environment, 0, int.MaxValue, cancellationToken)
.ContinueWith(task =>
{
task.WaitAndUnwrapException(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace Nerosoft.Starfish.Application;

public class TeamApplicationService : BaseApplicationService, ITeamApplicationService
{
public Task<List<TeamItemDto>> QueryAsync(TeamCriteria criteria, int page, int size, CancellationToken cancellationToken = default)
public Task<List<TeamItemDto>> QueryAsync(TeamCriteria criteria, int skip, int count, CancellationToken cancellationToken = default)
{
var userCase = LazyServiceProvider.GetService<ITeamQueryUseCase>();
var input = new TeamQueryInput(criteria, page, size);
var input = new TeamQueryInput(criteria, skip, count);
return userCase.ExecuteAsync(input, cancellationToken)
.ContinueWith(task => task.Result.Result, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public Task UpdateAsync(int id, UserUpdateDto data, CancellationToken cancellati
}

/// <inheritdoc />
public Task<List<UserItemDto>> SearchAsync(UserCriteria criteria, int page, int size, CancellationToken cancellationToken = default)
public Task<List<UserItemDto>> QueryAsync(UserCriteria criteria, int skip, int count, CancellationToken cancellationToken = default)
{
var useCase = LazyServiceProvider.GetService<IUserQueryUseCase>();
var input = new UserSearchInput(criteria, page, size);
var input = new UserSearchInput(criteria, skip, count);
return useCase.ExecuteAsync(input, cancellationToken)
.ContinueWith(task => task.Result.Result, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,40 @@ public Task HandleAsync(AppInfoDisableEvent @event, MessageContext context, Canc
return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken);
}

[Subscribe]
public Task HandleAsync(AppInfoSecretChangedEvent @event, MessageContext context, CancellationToken cancellationToken = default)
{
var aggregate = @event.GetAggregate<AppInfo>();
var command = new OperateLogCreateCommand
{
Module = "apps",
Type = "secret",
Description = string.Format(Resources.IDS_MESSAGE_LOGS_APPS_RESET_SECRET, aggregate.Code, aggregate.Name),
OperateTime = DateTime.Now,
RequestTraceId = context.RequestTraceId,
UserName = context.User?.Identity?.Name
};

return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken);
}

[Subscribe]
public Task HandleAsync(AppInfoUpdatedEvent @event, MessageContext context, CancellationToken cancellationToken = default)
{
var aggregate = @event.GetAggregate<AppInfo>();
var command = new OperateLogCreateCommand
{
Module = "apps",
Type = "update",
Description = string.Format(Resources.IDS_MESSAGE_LOGS_APPS_UPDATE, aggregate.Code, aggregate.Name),
OperateTime = DateTime.Now,
RequestTraceId = context.RequestTraceId,
UserName = context.User?.Identity?.Name
};

return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken);
}

/// <summary>
/// 处理配置节点创建事件
/// </summary>
Expand Down Expand Up @@ -196,4 +230,6 @@ public Task HandleAsync(SettingPublishedEvent @event, MessageContext context, Ca
};
return _bus.SendAsync(command, new SendOptions { RequestTraceId = context.RequestTraceId }, null, cancellationToken);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface ISettingRepository : IBaseRepository<DataContext, Setting, long

Task<Setting> GetAsync(long appId, string environment, bool tracking, string[] properties, CancellationToken cancellationToken = default);

Task<List<SettingItem>> GetItemListAsync(long id, string environment, int page, int size, CancellationToken cancellationToken = default);
Task<List<SettingItem>> GetItemListAsync(long id, string environment, int skip, int count, CancellationToken cancellationToken = default);

Task<int> GetItemCountAsync(long id, string environment, CancellationToken cancellationToken = default);
}
34 changes: 8 additions & 26 deletions Source/Starfish.Service/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -136,35 +136,14 @@
<value>User Acceptance Testing</value>
</data>
<data name="IDS_DICTIONARY_NAME_SA" xml:space="preserve">
<value>Super administrator</value>
<value>System administrator</value>
</data>
<data name="IDS_ENUM_APPINFO_STATUS_DISABLED" xml:space="preserve">
<value>Disabled</value>
</data>
<data name="IDS_ENUM_APPINFO_STATUS_ENABLED" xml:space="preserve">
<value>Enabled</value>
</data>
<data name="IDS_ENUM_SETTING_ITEM_TYPE_ARRAY" xml:space="preserve">
<value>Array</value>
</data>
<data name="IDS_ENUM_SETTING_ITEM_TYPE_BOOLEAN" xml:space="preserve">
<value>Boolean</value>
</data>
<data name="IDS_ENUM_SETTING_ITEM_TYPE_NUMBER" xml:space="preserve">
<value>Number</value>
</data>
<data name="IDS_ENUM_SETTING_ITEM_TYPE_OBJECT" xml:space="preserve">
<value>Object</value>
</data>
<data name="IDS_ENUM_SETTING_ITEM_TYPE_REFERER" xml:space="preserve">
<value>Referer</value>
</data>
<data name="IDS_ENUM_SETTING_ITEM_TYPE_ROOT" xml:space="preserve">
<value>Root</value>
</data>
<data name="IDS_ENUM_SETTING_ITEM_TYPE_STRING" xml:space="preserve">
<value>String</value>
</data>
<data name="IDS_ENUM_SETTING_STATUS_DISABLED" xml:space="preserve">
<value>Disabled</value>
</data>
Expand Down Expand Up @@ -192,11 +171,11 @@
<data name="IDS_ERROR_APPINFO_STATUS_INVALID" xml:space="preserve">
<value>Invalid app status.</value>
</data>
<data name="IDS_ERROR_PAGE_NUMBER_MUST_GREATER_THAN_0" xml:space="preserve">
<value>Page must be greater than 0.</value>
<data name="IDS_ERROR_PARAM_COUNT_MUST_GREATER_THAN_0" xml:space="preserve">
<value>The query parameter 'count' must be greater than 0.</value>
</data>
<data name="IDS_ERROR_PAGE_SIZE_MUST_GREATER_THAN_0" xml:space="preserve">
<value>Page size must be greater than 0.</value>
<data name="IDS_ERROR_PARAM_SKIP_CANNOT_BE_NEGATIVE" xml:space="preserve">
<value>The query parameter 'skip' can not be a negative number.</value>
</data>
<data name="IDS_ERROR_PASSWORD_INCORRECT" xml:space="preserve">
<value>The password is not correct.</value>
Expand Down Expand Up @@ -300,6 +279,9 @@
<data name="IDS_MESSAGE_LOGS_APPS_ENABLE" xml:space="preserve">
<value>Enable app {0}({1}).</value>
</data>
<data name="IDS_MESSAGE_LOGS_APPS_RESET_SECRET" xml:space="preserve">
<value>Reset app secret {0}({1}).</value>
</data>
<data name="IDS_MESSAGE_LOGS_APPS_UPDATE" xml:space="preserve">
<value>Update app {0}({1}).</value>
</data>
Expand Down
Loading

0 comments on commit 838180c

Please sign in to comment.