Skip to content

Commit

Permalink
Refactoring the TinyEventBus
Browse files Browse the repository at this point in the history
  • Loading branch information
agile.zhou committed May 5, 2024
1 parent 84386e1 commit b68f9f0
Show file tree
Hide file tree
Showing 42 changed files with 1,784 additions and 1,193 deletions.
14 changes: 14 additions & 0 deletions AgileConfig.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AgileConfig.Server.Data.Abs
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AgileConfig.Server.Data.FreesqlTests", "test\AgileConfig.Server.Data.FreesqlTests\AgileConfig.Server.Data.FreesqlTests.csproj", "{AC7E4D24-D5E8-4E30-BFB0-5DDC581CB0C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileConfig.Server.Event", "src\AgileConfig.Server.Event\AgileConfig.Server.Event.csproj", "{C1138EE0-0C28-4BDE-82CD-CCE621C21BD0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileConfig.Server.EventHandler", "src\AgileConfig.Server.EventHandler\AgileConfig.Server.EventHandler.csproj", "{899F5AAE-2C6F-4F0A-9358-6F5C7D0412DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -130,6 +134,14 @@ Global
{AC7E4D24-D5E8-4E30-BFB0-5DDC581CB0C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC7E4D24-D5E8-4E30-BFB0-5DDC581CB0C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC7E4D24-D5E8-4E30-BFB0-5DDC581CB0C2}.Release|Any CPU.Build.0 = Release|Any CPU
{C1138EE0-0C28-4BDE-82CD-CCE621C21BD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1138EE0-0C28-4BDE-82CD-CCE621C21BD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1138EE0-0C28-4BDE-82CD-CCE621C21BD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1138EE0-0C28-4BDE-82CD-CCE621C21BD0}.Release|Any CPU.Build.0 = Release|Any CPU
{899F5AAE-2C6F-4F0A-9358-6F5C7D0412DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{899F5AAE-2C6F-4F0A-9358-6F5C7D0412DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{899F5AAE-2C6F-4F0A-9358-6F5C7D0412DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{899F5AAE-2C6F-4F0A-9358-6F5C7D0412DC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -153,6 +165,8 @@ Global
{15089E5A-12E4-4953-BA35-0CBB2B1189C0} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
{964F5F7A-3BBD-47B3-8C28-EC16B1038A5A} = {F277EC27-8C0E-4490-9645-F5F3244F9246}
{AC7E4D24-D5E8-4E30-BFB0-5DDC581CB0C2} = {F277EC27-8C0E-4490-9645-F5F3244F9246}
{C1138EE0-0C28-4BDE-82CD-CCE621C21BD0} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
{899F5AAE-2C6F-4F0A-9358-6F5C7D0412DC} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7F10DB58-5B6F-4EAC-994F-14E8046B306F}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<AssemblyVersion>1.9.2</AssemblyVersion>
<Version>1.9.2</Version>
<AssemblyVersion>1.9.3</AssemblyVersion>
<Version>1.9.3</Version>
<PackageVersion>1.9.2</PackageVersion>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<FileVersion>1.9.2</FileVersion>
<FileVersion>1.9.3</FileVersion>
<Authors>kklldog</Authors>
<Company>kklldog</Company>
</PropertyGroup>
Expand Down Expand Up @@ -38,13 +38,15 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AgileConfig.Server.Common\AgileConfig.Server.Common.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Abstraction\AgileConfig.Server.Data.Abstraction.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Repository.Freesql\AgileConfig.Server.Data.Repository.Freesql.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Repository.Mongodb\AgileConfig.Server.Data.Repository.Mongodb.csproj" />
<ProjectReference Include="..\Agile.Config.Protocol\Agile.Config.Protocol.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Entity\AgileConfig.Server.Data.Entity.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Freesql\AgileConfig.Server.Data.Freesql.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Repository.Selector\AgileConfig.Server.Data.Repository.Selector.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Event\AgileConfig.Server.Event.csproj" />
<ProjectReference Include="..\AgileConfig.Server.OIDC\AgileConfig.Server.OIDC.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Service\AgileConfig.Server.Service.csproj" />
</ItemGroup>
Expand Down
18 changes: 10 additions & 8 deletions src/AgileConfig.Server.Apisite/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using AgileConfig.Server.Apisite.Utilites;
using AgileConfig.Server.OIDC;
using System.Collections.Generic;
using AgileConfig.Server.Event;
using AgileConfig.Server.Common.EventBus;

namespace AgileConfig.Server.Apisite.Controllers
{
Expand All @@ -22,18 +24,22 @@ public class AdminController : Controller
private readonly IPremissionService _permissionService;
private readonly IJwtService _jwtService;
private readonly IOidcClient _oidcClient;
private readonly ITinyEventBus _tinyEventBus;

public AdminController(
ISettingService settingService,
IUserService userService,
IPremissionService permissionService,
IJwtService jwtService,
IOidcClient oidcClient)
IOidcClient oidcClient,
ITinyEventBus tinyEventBus)
{
_settingService = settingService;
_userService = userService;
_permissionService = permissionService;
_jwtService = jwtService;
_oidcClient = oidcClient;
_tinyEventBus = tinyEventBus;
}


Expand Down Expand Up @@ -72,9 +78,7 @@ private async Task<object> LoginSuccessful(string userName)
var jwt = _jwtService.GetToken(user.Id, user.UserName, userRoles.Any(r => r == Role.Admin || r == Role.SuperAdmin));
var userFunctions = await _permissionService.GetUserPermission(user.Id);

dynamic param = new ExpandoObject();
param.userName = user.UserName;
TinyEventBus.Instance.Fire(EventKeys.USER_LOGIN_SUCCESS, param);
_tinyEventBus.Fire(new LoginEvent(user.UserName));

return new
{
Expand Down Expand Up @@ -212,7 +216,7 @@ public async Task<IActionResult> InitPassword([FromBody] InitPasswordVM model)

if (result)
{
TinyEventBus.Instance.Fire(EventKeys.INIT_SUPERADMIN_PASSWORD_SUCCESS);
_tinyEventBus.Fire(new InitSaPasswordSuccessful());

return Json(new
{
Expand Down Expand Up @@ -317,9 +321,7 @@ public async Task<IActionResult> ChangePassword([FromBody] ChangePasswordVM mode

if (result)
{
dynamic param = new ExpandoObject();
param.userName = user.UserName;
TinyEventBus.Instance.Fire(EventKeys.CHANGE_USER_PASSWORD_SUCCESS, param);
_tinyEventBus.Fire(new ChangeUserPasswordSuccessful(user.UserName));

return Json(new
{
Expand Down
29 changes: 12 additions & 17 deletions src/AgileConfig.Server.Apisite/Controllers/AppController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using AgileConfig.Server.Common;
using System.Dynamic;
using AgileConfig.Server.Apisite.Utilites;
using AgileConfig.Server.Common.EventBus;
using AgileConfig.Server.Event;

namespace AgileConfig.Server.Apisite.Controllers
{
Expand All @@ -21,10 +23,15 @@ public class AppController : Controller
private readonly IAppService _appService;
private readonly IPremissionService _premissionService;
private readonly IUserService _userService;
private readonly ITinyEventBus _tinyEventBus;

public AppController(IAppService appService, IPremissionService premissionService, IUserService userService)
public AppController(IAppService appService,
IPremissionService premissionService,
IUserService userService,
ITinyEventBus tinyEventBus)
{
_userService = userService;
_tinyEventBus = tinyEventBus;
_appService = appService;
_premissionService = premissionService;
}
Expand Down Expand Up @@ -260,10 +267,7 @@ public async Task<IActionResult> Add([FromBody] AppVM model)
var result = await _appService.AddAsync(app, inheritanceApps);
if (result)
{
dynamic param = new ExpandoObject();
param.app = app;
param.userName = this.GetCurrentUserName();
TinyEventBus.Instance.Fire(EventKeys.ADD_APP_SUCCESS, param);
_tinyEventBus.Fire(new AddAppSuccessful(app, this.GetCurrentUserName()));
}

return Json(new
Expand Down Expand Up @@ -329,10 +333,7 @@ public async Task<IActionResult> Edit([FromBody] AppVM model)
var result = await _appService.UpdateAsync(app, inheritanceApps);
if (result)
{
dynamic param = new ExpandoObject();
param.app = app;
param.userName = this.GetCurrentUserName();
TinyEventBus.Instance.Fire(EventKeys.EDIT_APP_SUCCESS, param);
_tinyEventBus.Fire(new EditAppSuccessful(app, this.GetCurrentUserName()));
}
return Json(new
{
Expand Down Expand Up @@ -431,10 +432,7 @@ public async Task<IActionResult> DisableOrEanble(string id)

if (result)
{
dynamic param = new ExpandoObject();
param.app = app;
param.userName = this.GetCurrentUserName();
TinyEventBus.Instance.Fire(EventKeys.DISABLE_OR_ENABLE_APP_SUCCESS, param);
_tinyEventBus.Fire(new DisableOrEnableAppSuccessful(app, this.GetCurrentUserName()));
}

return Json(new
Expand Down Expand Up @@ -467,10 +465,7 @@ public async Task<IActionResult> Delete(string id)

if (result)
{
dynamic param = new ExpandoObject();
param.app = app;
param.userName = this.GetCurrentUserName();
TinyEventBus.Instance.Fire(EventKeys.DELETE_APP_SUCCESS, param);
_tinyEventBus.Fire(new DeleteAppSuccessful(app, this.GetCurrentUserName()));
}

return Json(new
Expand Down
61 changes: 18 additions & 43 deletions src/AgileConfig.Server.Apisite/Controllers/ConfigController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using System.Dynamic;
using System.IO;
using AgileConfig.Server.Apisite.Utilites;
using AgileConfig.Server.Common.EventBus;
using AgileConfig.Server.Event;

namespace AgileConfig.Server.Apisite.Controllers
{
Expand All @@ -24,15 +26,19 @@ public class ConfigController : Controller
private readonly IConfigService _configService;
private readonly IAppService _appService;
private readonly IUserService _userService;
private readonly ITinyEventBus _tinyEventBus;

public ConfigController(
IConfigService configService,
IAppService appService,
IUserService userService)
IUserService userService,
ITinyEventBus tinyEventBus
)
{
_configService = configService;
_appService = appService;
_userService = userService;
_tinyEventBus = tinyEventBus;
}

[TypeFilter(typeof(PremissionCheckAttribute), Arguments = new object[] { "Config.Add", Functions.Config_Add })]
Expand Down Expand Up @@ -84,10 +90,7 @@ public async Task<IActionResult> Add([FromBody] ConfigVM model, [FromQuery] stri

if (result)
{
dynamic param = new ExpandoObject();
param.config = config;
param.userName = this.GetCurrentUserName();
TinyEventBus.Instance.Fire(EventKeys.ADD_CONFIG_SUCCESS, param);
_tinyEventBus.Fire(new AddConfigSuccessful(config, this.GetCurrentUserName()));
}

return Json(new
Expand Down Expand Up @@ -158,10 +161,7 @@ public async Task<IActionResult> AddRange([FromBody] List<ConfigVM> model, [From
var userName = this.GetCurrentUserName();
addConfigs.ForEach(c =>
{
dynamic param = new ExpandoObject();
param.config = c;
param.userName = userName;
TinyEventBus.Instance.Fire(EventKeys.ADD_CONFIG_SUCCESS, param);
_tinyEventBus.Fire(new AddConfigSuccessful(c, this.GetCurrentUserName()));
});
}

Expand Down Expand Up @@ -252,11 +252,7 @@ public async Task<IActionResult> Edit([FromBody] ConfigVM model, [FromQuery] str

if (result)
{
dynamic param = new ExpandoObject();
param.config = config;
param.userName = this.GetCurrentUserName();
param.oldConfig = config;
TinyEventBus.Instance.Fire(EventKeys.EDIT_CONFIG_SUCCESS, param);
_tinyEventBus.Fire(new EditConfigSuccessful(config, this.GetCurrentUserName()));
}

return Json(new
Expand Down Expand Up @@ -417,10 +413,7 @@ public async Task<IActionResult> Delete(string id, string env)
var result = await _configService.UpdateAsync(config, env);
if (result)
{
dynamic param = new ExpandoObject();
param.config = config;
param.userName = this.GetCurrentUserName();
TinyEventBus.Instance.Fire(EventKeys.DELETE_CONFIG_SUCCESS, param);
_tinyEventBus.Fire(new DeleteConfigSuccessful(config, this.GetCurrentUserName()));
}

return Json(new
Expand Down Expand Up @@ -472,11 +465,7 @@ public async Task<IActionResult> DeleteSome([FromBody] List<string> ids, string
var result = await _configService.UpdateAsync(deleteConfigs, env);
if (result)
{
dynamic param = new ExpandoObject();
param.userName = this.GetCurrentUserName();
param.appId = deleteConfigs.First().AppId;
param.env = env;
TinyEventBus.Instance.Fire(EventKeys.DELETE_CONFIG_SOME_SUCCESS, param);
_tinyEventBus.Fire(new DeleteSomeConfigSuccessful(deleteConfigs.First(), this.GetCurrentUserName()));
}

return Json(new
Expand All @@ -503,11 +492,8 @@ public async Task<IActionResult> Rollback(string publishTimelineId, string env)

if (result)
{
dynamic param = new ExpandoObject();
param.userName = this.GetCurrentUserName();
param.timelineNode = await _configService.GetPublishTimeLineNodeAsync(publishTimelineId, env);
param.env = env;
TinyEventBus.Instance.Fire(EventKeys.ROLLBACK_CONFIG_SUCCESS, param);
var node = await _configService.GetPublishTimeLineNodeAsync(publishTimelineId, env);
_tinyEventBus.Fire(new RollbackConfigSuccessful(node, this.GetCurrentUserName()));
}

return Json(new
Expand Down Expand Up @@ -577,11 +563,7 @@ public async Task<IActionResult> Publish([FromBody] PublishLogVM model, string e
if (ret.result)
{
var timelineNode = await _configService.GetPublishTimeLineNodeAsync(ret.publishTimelineId, env);
dynamic param = new ExpandoObject();
param.publishTimelineNode = timelineNode;
param.userName = this.GetCurrentUserName();
param.env = env;
TinyEventBus.Instance.Fire(EventKeys.PUBLISH_CONFIG_SUCCESS, param);
_tinyEventBus.Fire(new PublishConfigSuccessful(timelineNode, this.GetCurrentUserName()));
}

return Json(new
Expand Down Expand Up @@ -753,11 +735,8 @@ public async Task<IActionResult> CancelEdit(string configId, string env)

if (result)
{
dynamic param = new ExpandoObject();
param.config = await _configService.GetAsync(configId, env);
param.userName = this.GetCurrentUserName();
param.env = env;
TinyEventBus.Instance.Fire(EventKeys.CANCEL_EDIT_CONFIG_SUCCESS, param);
var config = await _configService.GetAsync(configId, env);
_tinyEventBus.Fire(new CancelEditConfigSuccessful(config, this.GetCurrentUserName()));
}

return Json(new
Expand All @@ -780,11 +759,7 @@ public async Task<IActionResult> CancelSomeEdit([FromBody] List<string> ids, str
if (result)
{
var config = await _configService.GetAsync(ids.First(), env);
dynamic param = new ExpandoObject();
param.userName = this.GetCurrentUserName();
param.appId = config.AppId;
param.env = env;
TinyEventBus.Instance.Fire(EventKeys.CANCEL_EDIT_CONFIG_SOME_SUCCESS, param);
_tinyEventBus.Fire(new CancelEditConfigSomeSuccessful(config, this.GetCurrentUserName()));
}

return Json(new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Agile.Config.Protocol;
using AgileConfig.Server.Apisite.Utilites;
using AgileConfig.Server.Common;
using AgileConfig.Server.Common.EventBus;
using AgileConfig.Server.Event;
using AgileConfig.Server.IService;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -17,14 +19,17 @@ namespace AgileConfig.Server.Apisite.Controllers
public class RemoteServerProxyController : Controller
{
private readonly IRemoteServerNodeProxy _remoteServerNodeProxy;
private readonly ITinyEventBus _tinyEventBus;
private readonly ILogger _logger;

public RemoteServerProxyController(
IRemoteServerNodeProxy remoteServerNodeProxy,
ILoggerFactory loggerFactory
ILoggerFactory loggerFactory,
ITinyEventBus tinyEventBus
)
{
_remoteServerNodeProxy = remoteServerNodeProxy;
_tinyEventBus = tinyEventBus;
_logger = loggerFactory.CreateLogger<RemoteServerProxyController>();
}

Expand All @@ -50,10 +55,7 @@ public async Task<IActionResult> Client_Offline(string address, string clientId)
var result = await _remoteServerNodeProxy.OneClientDoActionAsync(address, clientId, action);
if (result)
{
dynamic param = new ExpandoObject();
param.clientId = clientId;
param.userName = this.GetCurrentUserName();
TinyEventBus.Instance.Fire(EventKeys.DISCONNECT_CLIENT_SUCCESS, param);
_tinyEventBus.Fire(new DiscoinnectSuccessful(clientId, this.GetCurrentUserName()));
}

_logger.LogInformation("Request remote node {0} 's action OneClientDoAction {1} .", address,
Expand Down
Loading

0 comments on commit b68f9f0

Please sign in to comment.