diff --git a/IRaCIS.Core.API/_ServiceExtensions/Serilog/SerilogSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/Serilog/SerilogSetup.cs index f0740dbbf..a27de1505 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/Serilog/SerilogSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/Serilog/SerilogSetup.cs @@ -21,7 +21,7 @@ namespace IRaCIS.Core.API .MinimumLevel.Override("Hangfire", LogEventLevel.Warning) .MinimumLevel.Override("System.Net.Http.HttpClient.HttpReports", LogEventLevel.Warning) .Enrich.WithClientIp() - .Enrich.WithClientAgent() + .Enrich.FromLogContext() //控制台 方便调试 问题 我们显示记录日志 时 获取上下文的ip 和用户名 用户类型 diff --git a/IRaCIS.Core.API/_ServiceExtensions/Swagger/JsonPatchDocumentFilter.cs b/IRaCIS.Core.API/_ServiceExtensions/Swagger/JsonPatchDocumentFilter.cs deleted file mode 100644 index 9f3562072..000000000 --- a/IRaCIS.Core.API/_ServiceExtensions/Swagger/JsonPatchDocumentFilter.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Microsoft.OpenApi.Models; -using Swashbuckle.AspNetCore.SwaggerGen; -using System.Collections.Generic; -using System.Linq; - -namespace IRaCIS.Core.API -{ - public class JsonPatchDocumentFilter : IDocumentFilter - { - public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) - { - var schemas = swaggerDoc.Components.Schemas.ToList(); - foreach (var item in schemas) - { - if (item.Key.StartsWith("Operation") || item.Key.StartsWith("JsonPatchDocument")) - swaggerDoc.Components.Schemas.Remove(item.Key); - } - - swaggerDoc.Components.Schemas.Add("Operation", new OpenApiSchema - { - Type = "object", - Properties = new Dictionary - { - { "op", new OpenApiSchema { Type = "string" } }, - {"value", new OpenApiSchema{ Type = "object", Nullable = true } }, - { "path", new OpenApiSchema { Type = "string" } } - } - }); - - swaggerDoc.Components.Schemas.Add("JsonPatchDocument", new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "Operation" } - }, - Description = "Array of operations to perform" - }); - - foreach (var path in swaggerDoc.Paths.SelectMany(p => p.Value.Operations) - .Where(p => p.Key == Microsoft.OpenApi.Models.OperationType.Patch)) - { - foreach (var item in path.Value.RequestBody.Content.Where(c => c.Key != "application/json-patch+json")) - path.Value.RequestBody.Content.Remove(item.Key); - - var response = path.Value.RequestBody.Content.SingleOrDefault(c => c.Key == "application/json-patch+json"); - - response.Value.Schema = new OpenApiSchema - { - Reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "JsonPatchDocument" } - }; - } - } - } -} diff --git a/IRaCIS.Core.API/_ServiceExtensions/Swagger/SwaggerSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/Swagger/SwaggerSetup.cs index 44bbb60f4..a5c53cd7f 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/Swagger/SwaggerSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/Swagger/SwaggerSetup.cs @@ -62,7 +62,6 @@ namespace IRaCIS.Core.API // 在header中添加token,传递到后台 options.OperationFilter(); - options.DocumentFilter(); // 添加登录按钮 options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme() diff --git a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs index cc5bf300d..f41b6d3bc 100644 --- a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs +++ b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs @@ -259,7 +259,7 @@ namespace IRaCIS.Application.Services public async Task>> GetBasicDataSelect(string[] searchArray) { - var searchList = await _dicRepository.Where(t => searchArray.Contains(t.Parent.Code) && t.ParentId != null && t.IsEnable).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); + var searchList = await _dicRepository.Where(t => searchArray.Contains(t.Parent.Code) && t.ParentId != null && t.IsEnable).ProjectTo(_mapper.ConfigurationProvider,new { isEn_Us = _userInfo.IsEn_Us}).ToListAsync(); return searchList.GroupBy(t => t.ParentCode).ToDictionary(g => g.Key, g => g.OrderBy(t => t.ShowOrder).ToList()); diff --git a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs index bff993ccd..cf8a3a95c 100644 --- a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs @@ -51,7 +51,7 @@ namespace IRaCIS.Core.Application.Service CreateMap() .ForMember(o => o.ParentChildCodeEnum, t => t.MapFrom(u => u.Parent.ChildCodeEnum)) - .ForMember(o => o.Value, t => t.MapFrom(u => u.MappedValue)) + .ForMember(o => o.Value, t => t.MapFrom(u => isEn_Us? u.Value : u.ValueCN )) .ForMember(o => o.ParentCode, t => t.MapFrom(u => u.Parent.Code)); CreateMap() diff --git a/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs b/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs index 4d3003ad9..21480bae3 100644 --- a/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/SystemDocumentService.cs @@ -170,7 +170,7 @@ namespace IRaCIS.Core.Application.Services SignViewMinimumMinutes = sysDoc.SignViewMinimumMinutes, Name = sysDoc.Name, Path = sysDoc.Path, - FileType = sysDoc.FileType.MappedValue, + FileType = _userInfo.IsEn_Us? sysDoc.FileType.Value: sysDoc.FileType.ValueCN, UpdateTime = sysDoc.UpdateTime, FullFilePath = sysDoc.Path , diff --git a/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs b/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs index d8818be71..eb34d3eb7 100644 --- a/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs @@ -60,7 +60,7 @@ namespace IRaCIS.Core.Application.Services var trialDocumentQueryable = _trialDocumentRepository.AsQueryable(true).Where(t => t.TrialId == queryTrialDocument.TrialId) .WhereIf(!string.IsNullOrEmpty(queryTrialDocument.Name), t => t.Name.Contains(queryTrialDocument.Name)) .WhereIf(queryTrialDocument.FileTypeId != null, t => t.FileTypeId == queryTrialDocument.FileTypeId) - .ProjectTo(_mapper.ConfigurationProvider, new { token = _userInfo.UserToken }); + .ProjectTo(_mapper.ConfigurationProvider, new { token = _userInfo.UserToken, isEn_Us=_userInfo.IsEn_Us }); return await trialDocumentQueryable.ToPagedListAsync(queryTrialDocument.PageIndex, queryTrialDocument.PageSize, queryTrialDocument.SortField, queryTrialDocument.Asc); } @@ -187,7 +187,7 @@ namespace IRaCIS.Core.Application.Services Name = needConfirmedUserType.SystemDocument.Name, Path = needConfirmedUserType.SystemDocument.Path, FileTypeId = needConfirmedUserType.SystemDocument.FileTypeId, - FileType = needConfirmedUserType.SystemDocument.FileType.MappedValue, + FileType = _userInfo.IsEn_Us? needConfirmedUserType.SystemDocument.FileType.Value: needConfirmedUserType.SystemDocument.FileType.ValueCN, UpdateTime = needConfirmedUserType.SystemDocument.UpdateTime, FullFilePath = needConfirmedUserType.SystemDocument.Path , @@ -219,7 +219,7 @@ namespace IRaCIS.Core.Application.Services Name = trialDoc.Name, Path = trialDoc.Path, FileTypeId = trialDoc.FileTypeId, - FileType = trialDoc.FileType.MappedValue, + FileType = _userInfo.IsEn_Us ? trialDoc.FileType.Value: trialDoc.FileType.ValueCN, UpdateTime = trialDoc.UpdateTime, SignViewMinimumMinutes = trialDoc.SignViewMinimumMinutes, @@ -333,7 +333,7 @@ namespace IRaCIS.Core.Application.Services Name = trialDocumentNeedConfirmedUserType.TrialDocument.Name, Path = trialDocumentNeedConfirmedUserType.TrialDocument.Path, FileTypeId = trialDocumentNeedConfirmedUserType.TrialDocument.FileTypeId, - FileType = trialDocumentNeedConfirmedUserType.TrialDocument.FileType.MappedValue, + FileType = _userInfo.IsEn_Us ? trialDocumentNeedConfirmedUserType.TrialDocument.FileType.Value : trialDocumentNeedConfirmedUserType.TrialDocument.FileType.ValueCN, UpdateTime = trialDocumentNeedConfirmedUserType.TrialDocument.UpdateTime, @@ -367,7 +367,7 @@ namespace IRaCIS.Core.Application.Services SignViewMinimumMinutes = needConfirmEdUserType.SystemDocument.SignViewMinimumMinutes, Name = needConfirmEdUserType.SystemDocument.Name, Path = needConfirmEdUserType.SystemDocument.Path, - FileType = needConfirmEdUserType.SystemDocument.FileType.MappedValue, + FileType = _userInfo.IsEn_Us ? needConfirmEdUserType.SystemDocument.FileType.Value : needConfirmEdUserType.SystemDocument.FileType.ValueCN, FileTypeId = needConfirmEdUserType.SystemDocument.FileTypeId, UpdateTime = needConfirmEdUserType.SystemDocument.UpdateTime, diff --git a/IRaCIS.Core.Application/Service/Document/_MapConfig.cs b/IRaCIS.Core.Application/Service/Document/_MapConfig.cs index 3cec4fc79..1116a7bf1 100644 --- a/IRaCIS.Core.Application/Service/Document/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Document/_MapConfig.cs @@ -14,12 +14,13 @@ namespace IRaCIS.Core.Application.Service var userId = Guid.Empty; var token = string.Empty; + var isEn_Us = false; CreateMap() .ForMember(d => d.FileType, u => u.MapFrom(s => s.FileType.Value)) .ForMember(d => d.FullFilePath, u => u.MapFrom(s => s.Path)); CreateMap() - .ForMember(d => d.FileType, u => u.MapFrom(s => s.FileType.MappedValue)) + .ForMember(d => d.FileType, u => u.MapFrom(s => isEn_Us ? s.FileType.Value : s.FileType.ValueCN )) .ForMember(d => d.IsSomeUserSigned, u => u.MapFrom(s => s.TrialDocConfirmedUserList.Any(t=>t.ConfirmTime!=null))) .ForMember(d => d.FullFilePath, u => u.MapFrom(s => s.Path )); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs index 76f6cdacc..69f46a855 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs @@ -92,7 +92,7 @@ namespace IRaCIS.Application.Services .WhereIf(multiCriteriaSelectCount > 0, t => t.TrialDicList.Count(t => t.KeyName == StaticData.Criterion) == multiCriteriaSelectCount) .WhereIf(multiReviewTypeSelectCount > 0, t => t.TrialDicList.Count(t => t.KeyName == StaticData.ReviewType) == multiReviewTypeSelectCount) .WhereIf(_userInfo.UserTypeEnumInt != (int)UserTypeEnum.SuperAdmin, t => t.TrialUserList.Any(t => t.UserId == _userInfo.Id && t.IsDeleted == false) && t.IsDeleted == false) - .ProjectTo(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id }); + .ProjectTo(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id , isEn_Us= _userInfo.IsEn_Us }); return await query.ToPagedListAsync(searchParam.PageIndex, searchParam.PageSize, string.IsNullOrWhiteSpace(searchParam.SortField) ? "CreateTime" : searchParam.SortField, searchParam.Asc); @@ -118,7 +118,7 @@ namespace IRaCIS.Application.Services [HttpGet("{projectId:guid}")] public async Task GetTrialInfoAndLockState(Guid projectId) { - return (await _trialRepository.Where(o => o.Id == projectId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); + return (await _trialRepository.Where(o => o.Id == projectId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider, new {isEn_Us = _userInfo.IsEn_Us }).FirstOrDefaultAsync()).IfNullThrowException(); } @@ -609,7 +609,7 @@ namespace IRaCIS.Application.Services .WhereIf(param.Status == 8, t => t.EnrollList.Any(u => u.EnrollStatus == EnrollStatus.InviteIntoGroup)) .WhereIf(param.Status == 10, t => t.EnrollList.Any(u => u.EnrollStatus == EnrollStatus.DoctorReading)) .WhereIf(param.Status == 14, t => t.EnrollList.Any(u => u.EnrollStatus == EnrollStatus.Finished)) - .ProjectTo(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id }); + .ProjectTo(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id, isEn_Us = _userInfo.IsEn_Us }); return await query.ToPagedListAsync(param.PageIndex, param.PageSize, string.IsNullOrWhiteSpace(param.SortField) ? "CreateTime" : param.SortField, param.Asc); @@ -644,7 +644,7 @@ namespace IRaCIS.Application.Services .WhereIf(!string.IsNullOrEmpty(searchModel.Code), o => o.TrialCode.Contains(searchModel.Code)) .WhereIf(!string.IsNullOrWhiteSpace(searchModel.Indication), o => o.Indication.Contains(searchModel.Indication)) .WhereIf(_userInfo.UserTypeEnumInt != (int)UserTypeEnum.SuperAdmin, t => t.TrialUserList.Any(t => t.UserId == _userInfo.Id)) - .ProjectTo(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id }); + .ProjectTo(_mapper.ConfigurationProvider, new { userTypeEnumInt = _userInfo.UserTypeEnumInt, userId = _userInfo.Id ,isEn_Us = _userInfo.IsEn_Us }); return await query.ToPagedListAsync(searchModel.PageIndex, searchModel.PageSize, string.IsNullOrWhiteSpace(searchModel.SortField) ? "CreateTime" : searchModel.SortField, searchModel.Asc); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs index f5861e37e..200b6f4c3 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs @@ -65,16 +65,17 @@ namespace IRaCIS.Core.Application.Service var userId = Guid.Empty; var userTypeEnumInt = 0; + var isEn_Us = false; CreateMap() .ForMember(x=>x.CriterionList,y=>y.MapFrom(z=>z.ReadingQuestionCriterionTrialList.Where(n=>n.IsConfirm).Select(m=>m.CriterionName))) .ForMember(d => d.DictionaryList, u => u.MapFrom(s => s.TrialDicList.Select(t => t.Dictionary).OrderBy(t => t.ShowOrder))) //.ForMember(d => d.Code, u => u.MapFrom(s => s.TrialCode)) .ForMember(d => d.Sponsor, u => u.MapFrom(s => s.Sponsor.SponsorName)) - .ForMember(d => d.Phase, u => u.MapFrom(s => s.Phase.MappedValue)) + .ForMember(d => d.Phase, u => u.MapFrom(s => isEn_Us? s.Phase.Value: s.Phase.ValueCN)) //.ForMember(d => d.DeclarationType, u => u.MapFrom(s => s.DeclarationType.MappedValue)) - .ForMember(d => d.IndicationType, u => u.MapFrom(s => s.IndicationType.MappedValue)) + .ForMember(d => d.IndicationType, u => u.MapFrom(s => isEn_Us ? s.IndicationType.Value:s.IndicationType.ValueCN)) .ForMember(d => d.CRO, u => u.MapFrom(s => s.CRO.CROName)) - .ForMember(d => d.ReviewMode, u => u.MapFrom(s => s.ReviewMode.MappedValue)) + .ForMember(d => d.ReviewMode, u => u.MapFrom(s => isEn_Us ? s.ReviewMode.Value:s.ReviewMode.ValueCN)) //.ForMember(d => d.ReviewType, u => u.MapFrom(s => s.ReviewType.Value)) .ForMember(d => d.IsLocked, u => u.MapFrom(s => s.WorkloadList.Any(u => u.DataFrom == (int)WorkLoadFromStatus.FinalConfirm))) //.ForMember(d => d.SiteCount, u => u.MapFrom(s => userTypeEnumInt == (int)UserTypeEnum.ClinicalResearchCoordinator ? s.TrialSiteUserList.Count(k => k.UserId == userId) : s.TrialSiteList.Count())) @@ -111,7 +112,6 @@ namespace IRaCIS.Core.Application.Service .ForMember(d => d.HospitalName, u => u.MapFrom(s => s.Hospital.HospitalName)); //trial site 选择列表 subjectVisit pannel 模式添加的时候 - var isEn_Us = false; CreateMap() .ForMember(d => d.IsSelect, u => u.MapFrom(s => s.TrialSiteList.Any(k => k.TrialId == trialId))) diff --git a/IRaCIS.Core.Domain/Common/Dictionary.cs b/IRaCIS.Core.Domain/Common/Dictionary.cs index 6b518574a..f178c6154 100644 --- a/IRaCIS.Core.Domain/Common/Dictionary.cs +++ b/IRaCIS.Core.Domain/Common/Dictionary.cs @@ -59,9 +59,6 @@ namespace IRaCIS.Core.Domain.Models public List ChildList { get; set; } = new List(); - [NotMapped] - public string MappedValue { get; set; } - [Projectable] public string TranslateValue( string value, string valueCN,bool isCN) => isCN?valueCN:value; diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index b98df40d8..068df0e6d 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -123,14 +123,14 @@ namespace IRaCIS.Core.Infra.EFCore modelBuilder.Entity().HasMany(t => t.ChildList).WithOne(t => t.Parent); modelBuilder.Entity().HasMany(t => t.EarlierSubjectUserList).WithOne(t => t.OrignalSubjectUser); - if (_userInfo.IsEn_Us) - { - modelBuilder.Entity().Property(t => t.MappedValue).HasColumnName(nameof(Domain.Models.Dictionary.Value)); - } - else - { - modelBuilder.Entity().Property(t => t.MappedValue).HasColumnName(nameof(Domain.Models.Dictionary.ValueCN)); - } + //if (_userInfo.IsEn_Us) + //{ + // modelBuilder.Entity().Property(t => t.MappedValue).HasColumnName(nameof(Domain.Models.Dictionary.Value)); + //} + //else + //{ + // modelBuilder.Entity().Property(t => t.MappedValue).HasColumnName(nameof(Domain.Models.Dictionary.ValueCN)); + //} //遍历实体模型手动配置 diff --git a/IRaCIS.Core.Infrastructure/Extention/RequestExtension.cs b/IRaCIS.Core.Infrastructure/Extention/RequestExtension.cs deleted file mode 100644 index 1aecdeb67..000000000 --- a/IRaCIS.Core.Infrastructure/Extention/RequestExtension.cs +++ /dev/null @@ -1,158 +0,0 @@ -using Microsoft.AspNetCore.Http; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace IRaCIS.Core.Infrastructure.Extention -{ - public static class HttpContextExtension - { - - public static T GetService(this HttpContext context) where T : class - { - return context.RequestServices.GetService(typeof(T)) as T; - } - - - public static string GetUserIp(this HttpContext context) - { - string realIP = null; - string forwarded = null; - string remoteIpAddress = context.Connection.RemoteIpAddress.ToString(); - if (context.Request.Headers.ContainsKey("X-Real-IP")) - { - realIP = context.Request.Headers["X-Real-IP"].ToString(); - if (realIP != remoteIpAddress) - { - remoteIpAddress = realIP; - } - } - if (context.Request.Headers.ContainsKey("X-Forwarded-For")) - { - forwarded = context.Request.Headers["X-Forwarded-For"].ToString(); - if (forwarded != remoteIpAddress) - { - remoteIpAddress = forwarded; - } - } - return remoteIpAddress; - } - - - - /// - /// 获取Request值 - /// - /// - /// - /// - public static string Request(this HttpContext context, string parameter) - { - try - { - if (context == null) - return null; - if (context.Request.Method == "POST") - return context.Request.Form[parameter].ToString(); - else - return context.Request.Query[parameter].ToString(); - } - catch (System.Exception ex) - { - Console.Write(ex.Message + ex.InnerException); - return context.RequestString(parameter); - } - } - - public static T Request(this HttpContext context, string parameter) where T : class - { - return context.RequestString(parameter)?.DeserializeObject(); - } - public static string RequestString(this HttpContext context, string parameter) - { - string requestParam = context.GetRequestParameters(); - if (string.IsNullOrEmpty(requestParam)) return null; - Dictionary keyValues = requestParam.DeserializeObject>(); - if (keyValues == null || keyValues.Count == 0) return null; - if (keyValues.TryGetValue(parameter, out object value)) - { - if (value == null) return null; - if (value.GetType() == typeof(string)) - { - return value?.ToString(); - } - return value.Serialize(); - } - return null; - } - /// - /// 是否为ajax请求 - /// - /// - /// - public static bool IsAjaxRequest(this HttpContext context) - { - return context.Request("X-Requested-With") == "XMLHttpRequest" - || (context.Request.Headers != null - && context.Request.Headers["X-Requested-With"] == "XMLHttpRequest"); - } - - public static UserAgent GetAgentType(this HttpContext context) - { - string agent = context.Request.Headers["User-Agent"].ToString().ToLower(); - - if (agent.Contains("ios") || agent.Contains("ipod") || agent.Contains("ipad")) - { - return UserAgent.IOS; - } - if (agent.Contains("windows")) - { - return UserAgent.Windows; - } - return UserAgent.Android; - - } - - /// - /// 获取请求的参数 - /// net core 2.0已增加回读方法 context.Request.EnableRewind(); - /// - /// - /// - /// - - public static string GetRequestParameters(this HttpContext context) - { - if (context.Request.Body == null || !context.Request.Body.CanRead || !context.Request.Body.CanSeek) - return null; - if (context.Request.Body.Length == 0) - return null; - if (context.Request.Body.Position > 0) - context.Request.Body.Position = 0; - - string prarameters = null; - var bodyStream = context.Request.Body; - - using (var buffer = new MemoryStream()) - { - bodyStream.CopyToAsync(buffer); - buffer.Position = 0L; - bodyStream.Position = 0L; - using (var reader = new StreamReader(buffer, Encoding.UTF8)) - { - buffer.Seek(0, SeekOrigin.Begin); - prarameters = reader.ReadToEnd(); - } - } - return prarameters; - } - } - public enum UserAgent - { - IOS = 0, - Android = 1, - Windows = 2, - Linux - } -} diff --git a/IRaCIS.Core.Infrastructure/Helper/IPHelper.cs b/IRaCIS.Core.Infrastructure/Helper/IPHelper.cs deleted file mode 100644 index c8827eab0..000000000 --- a/IRaCIS.Core.Infrastructure/Helper/IPHelper.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; -using System.Text.RegularExpressions; -using Microsoft.AspNetCore.Http; - -namespace IRaCIS.Core.Infrastructure -{ - public class IPHelper - { - /// - /// 是否为ip - /// - /// - /// - public static bool IsIP(string ip) - { - return Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$"); - } - - public static string GetIP(HttpRequest request) - { - if (request == null) - { - return ""; - } - - string ip = request.Headers["X-Real-IP"].FirstOrDefault(); - if (string.IsNullOrEmpty(ip)) - { - ip = request.Headers["X-Forwarded-For"].FirstOrDefault(); - } - if (string.IsNullOrEmpty(ip)) - { - ip = request.HttpContext?.Connection?.RemoteIpAddress?.ToString(); - } - if (string.IsNullOrEmpty(ip) || !IsIP(ip)) - { - ip = "127.0.0.1"; - } - - return ip; - } - } -} \ No newline at end of file diff --git a/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj b/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj index 152693792..9976f5251 100644 --- a/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj +++ b/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj @@ -9,13 +9,12 @@ - - - - - - - + + + + + +