| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | |
| | | /// </summary> |
| | | public class ResendResourceCommandHandler( |
| | | IRepository<ResourceLog, LogDbContextLocator> repResourceLog, |
| | | IRepository<Resource> repResource, |
| | | ResourceHttpUtils resourceHttpUtils |
| | | IRepository<Resource> repResource |
| | | ) : |
| | | IRequestHandler<ResendResourceCommand, string> |
| | | { |
| | | private readonly IRepository<ResourceLog, LogDbContextLocator> repResourceLog = repResourceLog; |
| | | private readonly IRepository<Resource> repResource = repResource; |
| | | private readonly ResourceHttpUtils resourceHttpUtils = resourceHttpUtils; |
| | | |
| | | /// <summary> |
| | | /// 重新发送资源 |
| | |
| | | { |
| | | it.Method, |
| | | it.Path, |
| | | it.RequestHeaders, |
| | | it.Request, |
| | | it.CreatedUserId |
| | | }) |
| | |
| | | if (log == null) throw Oops.Oh(EnumErrorCodeType.s404, "日志"); |
| | | var resource = await repResource.AsQueryable().AsNoTracking() |
| | | .Where(it => it.Method == log.Method && it.Route == log.Path) |
| | | .Select(it => new |
| | | { |
| | | it.ServiceName, |
| | | it.Route, |
| | | it.Method |
| | | }) |
| | | .FirstOrDefaultAsync(); |
| | | if (resource == null) throw Oops.Oh(EnumErrorCodeType.s404, "资源"); |
| | | var paramters = log.Request |
| | | .JsonTo(new |
| | | { |
| | |
| | | }) |
| | | .request |
| | | .ToJson(); |
| | | var result = await resourceHttpUtils.SendHttpAsync(resource, paramters); |
| | | string? accessToken = null, refreshToken = null; |
| | | if (log.RequestHeaders.IsNotNull()) |
| | | { |
| | | var headers = log.RequestHeaders.JsonTo<Dictionary<string, List<string>>>(); |
| | | if (headers.ContainsKey("Authorization")) |
| | | { |
| | | accessToken = headers["Authorization"].FirstOrDefault(); |
| | | } |
| | | if (headers.ContainsKey("X-Authorization")) |
| | | { |
| | | refreshToken = headers["X-Authorization"].FirstOrDefault(); |
| | | } |
| | | } |
| | | var result = await paramters.SendHttpAsync(resource.ServiceName, resource.Route, resource.Method, accessToken: accessToken, refreshToken: refreshToken); |
| | | return result; |
| | | } |
| | | } |