public Task ExecuteAsync(CaberRequestContext context) { context.WriteResponseMessage(statusCode, new object()); return(Task.CompletedTask); }
public Task ExecuteAsync(CaberRequestContext context) { var action = context.Services.GetService <RegisterAction>(); var requestDto = new RequestDto(); try { context.ReadRequestMessage(requestDto); ValidateRequest(requestDto, context.GetPeerPrincipal()); } catch (Exception ex) { context.Logger.BadRequest(ex, typeof(RegisterRoute)); context.BadRequest(); return(Task.CompletedTask); } var request = new RegisterAction.Request { ClientIdentity = new CaberIdentity { Uuid = requestDto.clientIdentity.uuid }, ServerIdentity = new CaberIdentity { Uuid = requestDto.serverIdentity.uuid }, Environment = new CaberSharedEnvironment { HashAlgorithm = requestDto.environment.hashAlgorithm }, Roots = requestDto.roots.Select(r => r.name).ToArray() }; var response = action.Execute(request, context.GetPeerPrincipal()); switch (response.Type) { case RegisterAction.ResponseType.Accepted: context.WriteResponseMessage(StatusCodes.Status200OK, new SucceededResponseDto { serverIdentity = new CaberIdentityDto { uuid = response.ServerIdentity.Uuid }, acceptedRoots = response.AcceptedRoots.Select(r => new RootDto { name = r }).ToArray() }); break; case RegisterAction.ResponseType.EnvironmentNotSupported: context.WriteResponseMessage(StatusCodes.Status501NotImplemented, new NotImplementedResponseDto { serverIdentity = new CaberIdentityDto { uuid = response.ServerIdentity.Uuid }, environment = new EnvironmentDto { hashAlgorithm = response.Environment.HashAlgorithm }, }); break; default: context.BugCheck(); break; } return(Task.CompletedTask); }