/// <summary> /// 登录 /// </summary> /// <param name="request">请求</param> public async Task <SignInWithTokenResult> SignInAsync(AdminLoginRequest request) { var user = await GetUserAsync(request.UserName); if (user == null) { return new SignInWithTokenResult { Message = "用户名不存在", State = SignInState.Failed } } ; await AddClaimsToUserAsync(user, ApplicationCode.Admin); var result = await SignInManager.SignInAsync(user, request.Password); user.AddLoginLog(Web.IP, Web.Browser); await MessageEventBus.PublishAsync(new UserLoginMessageEvent(new UserLoginMessage { UserId = user.Id, Name = user.Nickname, Ip = Web.IP, UserAgent = Web.Browser }, false)); await UnitOfWork.CommitAsync(); return(await GetLoginResultAsync(user, result, ApplicationCode.Admin)); }
/// <summary> /// 获取登录结果 /// </summary> /// <param name="user">用户</param> /// <param name="signInResult">登录结果</param> /// <param name="applicationCode">应用程序编码</param> private async Task <SignInWithTokenResult> GetLoginResultAsync(User user, SignInResult signInResult, string applicationCode) { if (signInResult.State == SignInState.Failed) { return new SignInWithTokenResult { UserId = signInResult.UserId, State = signInResult.State, Message = signInResult.Message } } ; await MessageEventBus.PublishAsync(new UserLoginMessageEvent(new UserLoginMessage { UserId = user.Id, Name = user.Nickname, Ip = Web.IP, UserAgent = Web.Browser })); var result = await TokenBuilder.CreateAsync(user.GetClaims().ToDictionary(x => x.Type, x => x.Value)); return(new SignInWithTokenResult { UserId = signInResult.UserId, State = signInResult.State, Message = signInResult.Message, Token = result }); }
public async Task <IActionResult> TestMessageAsync([FromBody] TestMessage request) { await MessageEventBus.PublishAsync(new TestMessageEvent1(request)); await UnitOfWork.CommitAsync(); return(Success()); }
//[AntiDuplicateRequest] public async Task <IActionResult> TestMessageAsync([FromBody] TestMessage request) { Log.Info("测试日志消息Begin"); await MessageEventBus.PublishAsync(new TestMessageEvent1(request, request.Send)); if (request.NeedCommit) { await UnitOfWork.CommitAsync(); } Log.Info("测试日志消息End"); return(Success()); }
static async Task CommonPublish() { var eventBus = new MessageEventBus(); var tokenSource = new CancellationTokenSource(); var i = 0; while (!tokenSource.IsCancellationRequested) { await eventBus.PublishAsync("test", new { Time = DateTime.Now, Index = i }, ""); i++; } }
public async Task <IActionResult> TestMessageAsync([FromBody] TestMessage request) { Logger.LogInformation($"测试Logger消息{nameof(ILogger<TestController>)} - 0: {request.Id}"); OtherLog .Message($"测试Logger消息{nameof(ILog<TestController>)} - 0: {request.Id}") .LogInformation(); Log.Info("测试日志消息Begin"); await MessageEventBus.PublishAsync(new TestMessageEvent1(request, request.Send)); if (request.NeedCommit) { await UnitOfWork.CommitAsync(); } Log.Info("测试日志消息End"); return(Success()); }
public async Task TestMessage1Async(TestMessage message, [FromCap] CapHeader header) { if (message.ThrowException) { throw new NotImplementedException("主动触发,暂未生效"); } Log.Info($"测试一波CAP消息 - 0: {message.Id}"); Logger.LogDebug($"测试一波CAP消息 - 1: {message.Id}"); var log = Bing.Logs.Log.GetLog(nameof(TestMessageEventHandler)); log.Debug($"测试一波CAP消息 - 1 - 1: {message.Id}"); Debug.WriteLine(message.Id); await MessageEventBus.PublishAsync(new TestMessageEvent2(message, message.Send)); if (message.NeedCommit) { await UnitOfWork.CommitAsync(); } }
/// <summary> /// 创建角色 /// </summary> /// <param name="request">创建请求参数</param> public async Task <Guid> CreateAsync(CreateRoleRequest request) { var role = ToEntity(request); role.Type = "Role"; await RoleManager.CreateAsync(role); await MessageEventBus.PublishAsync(new CreateRoleMessageEvent( new CreateRoleMessage() { Code = $"event:{role.Code}", Name = $"event:{role.Name}", Type = $"event:{role.Type}" })); await UnitOfWork.CommitAsync(); return(role.Id); }
/// <summary> /// 创建角色 /// </summary> /// <param name="request">创建请求参数</param> public async Task <Guid> CreateAsync(CreateRoleRequest request) { var role = ToEntity(request); role.Type = "Role"; await RoleManager.CreateAsync(role); await MessageEventBus.PublishAsync(new CreateRoleMessageEvent( new CreateRoleMessage() { Code = $"event:{role.Code}", Name = $"event:{role.Name}", Type = $"event:{role.Type}" })); await SqlExecutor.ExecuteSqlAsync("insert into Systems.Test(Id, Name) Values(@Id, @Name)", new { Id = Guid.NewGuid(), Name = "隔壁老王" }); await UnitOfWork.CommitAsync(); return(role.Id); }