From 576397a0425d0ee72af50a788ef1c18b58943edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= Date: Fri, 6 Jan 2023 10:15:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=AF=E7=A9=BA=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/RABC/FileController.cs | 2 +- .../Controllers/RABC/UserController.cs | 6 ++--- .../Abstract/ICurrentUser.cs | 4 ++-- .../Attribute/AppServiceAttribute.cs | 2 +- .../Exceptions/BusinessException.cs | 8 +++---- .../Exceptions/IHasErrorDetails.cs | 2 +- .../Exceptions/UserFriendlyException.cs | 4 ++-- .../Helper/AssemblyHelper.cs | 2 +- .../Helper/DistinctHelper.cs | 8 ++++--- .../Yi.Framework.Common/Helper/HttpHelper.cs | 2 +- .../Yi.Framework.Common/Helper/IpHelper.cs | 5 ++++ .../Yi.Framework.Common/Helper/JsonHelper.cs | 4 ++-- .../Yi.Framework.Common/Helper/MD5Hepler.cs | 2 +- .../Yi.Framework.Common/Helper/MimeHelper.cs | 6 ++--- .../Yi.Framework.Common/Helper/RSAHelper.cs | 12 +++++----- .../Helper/SerializeHelper.cs | 2 +- .../Helper/StringHelper.cs | 4 ++-- .../Yi.Framework.Common/Helper/TreeHelper.cs | 24 +++++++++---------- .../Yi.Framework.Common/Helper/XmlHelper.cs | 4 ++-- .../Yi.Framework.Common/Models/Result.cs | 17 +++++++------ .../Yi.Framework.Common.csproj | 1 + .../RABC/Entitys/MenuEntity.cs | 10 ++++---- .../RABC/Entitys/UserEntity.cs | 4 ++++ .../Yi.Framework.Template/TemplateFactory.cs | 3 +-- .../AspNetCoreExtensions/LocalizerExtend.cs | 2 +- .../DbExtend/DbFiterExtend.cs | 2 +- .../CustomExceptionFilterAttribute.cs | 2 +- .../FilterExtend/LogActionFilterAttribute.cs | 4 ++-- .../MiddlewareExtend/CurrentUserExrension.cs | 2 +- 29 files changed, 82 insertions(+), 68 deletions(-) diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RABC/FileController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RABC/FileController.cs index 5da73d6a..44cd33a4 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RABC/FileController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RABC/FileController.cs @@ -69,7 +69,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers //路径为: 文件路径/文件id+文件扩展名 var path = Path.Combine($"{PathConst.wwwroot}/{file.FilePath}", file.Id.ToString() + Path.GetExtension(file.FileName)); var stream = System.IO.File.OpenRead(path); - var MimeType = Common.Helper.MimeHelper.GetMimeMapping(file.FileName); + var MimeType = Common.Helper.MimeHelper.GetMimeMapping(file.FileName!); return File(stream, MimeType, file.FileName); } catch diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RABC/UserController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RABC/UserController.cs index 86aa97fb..0d01cd52 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RABC/UserController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RABC/UserController.cs @@ -102,7 +102,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers [Log("用户模块", OperEnum.Update)] public async Task Update(UserInfoDto userDto) { - if (await _repository.IsAnyAsync(u => userDto.User.UserName!.Equals(u.UserName) && !userDto.User.Id.Equals(u.Id))) + if (await _repository.IsAnyAsync(u => userDto.User!.UserName!.Equals(u.UserName) && !userDto.User.Id.Equals(u.Id))) { return Result.Error("用户名已存在,修改失败!"); } @@ -121,7 +121,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers public async Task UpdateProfile(UserInfoDto userDto) { //修改需要赋值上主键哦 - userDto.User.Id = HttpContext.GetUserIdInfo(); + userDto.User!.Id = HttpContext.GetUserIdInfo(); return Result.Success().SetStatus(await _iUserService.UpdateProfile(userDto)); } @@ -135,7 +135,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers [Log("用户模块", OperEnum.Insert)] public async Task Add(UserInfoDto userDto) { - if (string.IsNullOrEmpty(userDto.User.Password)) + if (string.IsNullOrEmpty(userDto?.User?.Password)) { return Result.Error("密码为空,添加失败!"); } diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Abstract/ICurrentUser.cs b/Yi.Framework.Net6/Yi.Framework.Common/Abstract/ICurrentUser.cs index 582a97a1..0c3b6870 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Abstract/ICurrentUser.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Abstract/ICurrentUser.cs @@ -23,9 +23,9 @@ namespace Yi.Framework.Common.Abstract public bool PhoneNumberVerified { get; set; } - public string[] Roles { get; set; } + public string[]? Roles { get; set; } - public string[] Permission { get; set; } + public string[]? Permission { get; set; } } } diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Attribute/AppServiceAttribute.cs b/Yi.Framework.Net6/Yi.Framework.Common/Attribute/AppServiceAttribute.cs index 5b833933..949ef20e 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Attribute/AppServiceAttribute.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Attribute/AppServiceAttribute.cs @@ -19,7 +19,7 @@ namespace Yi.Framework.Common.Attribute /// /// 指定服务类型 /// - public Type ServiceType { get; set; } + public Type? ServiceType { get; set; } } diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/BusinessException.cs b/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/BusinessException.cs index b4116638..3d0d77ae 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/BusinessException.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/BusinessException.cs @@ -13,15 +13,15 @@ public class BusinessException : Exception, { public ResultCodeEnum Code { get; set; } - public string Details { get; set; } + public string? Details { get; set; } public LogLevel LogLevel { get; set; } public BusinessException( ResultCodeEnum code = ResultCodeEnum.NotSuccess, - string message = null, - string details = null, - Exception innerException = null, + string? message = null, + string? details = null, + Exception? innerException = null, LogLevel logLevel = LogLevel.Warning) : base(message, innerException) { diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/IHasErrorDetails.cs b/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/IHasErrorDetails.cs index ed892d21..77a5a37c 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/IHasErrorDetails.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/IHasErrorDetails.cs @@ -2,5 +2,5 @@ namespace Yi.Framework.Common.Exceptions; public interface IHasErrorDetails { - string Details { get; } + string? Details { get; } } diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/UserFriendlyException.cs b/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/UserFriendlyException.cs index b47ab9be..258f8f74 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/UserFriendlyException.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Exceptions/UserFriendlyException.cs @@ -14,8 +14,8 @@ public class UserFriendlyException : BusinessException public UserFriendlyException( string message, ResultCodeEnum code = ResultCodeEnum.NotSuccess, - string details = null, - Exception innerException = null, + string? details = null, + Exception? innerException = null, LogLevel logLevel = LogLevel.Warning) : base( code, diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/AssemblyHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/AssemblyHelper.cs index c74ef1ff..003928c7 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/AssemblyHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/AssemblyHelper.cs @@ -11,7 +11,7 @@ namespace Yi.Framework.Common.Helper { public class AssemblyHelper { - public static List GetClass(string assemblyFile, string className = null, string spaceName = null) + public static List GetClass(string assemblyFile, string? className = null, string? spaceName = null) { Assembly assembly = Assembly.Load(assemblyFile); return assembly.GetTypes().Where(m => m.IsClass diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/DistinctHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/DistinctHelper.cs index 1e245aaf..0d531e99 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/DistinctHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/DistinctHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -13,13 +14,14 @@ namespace Yi.Framework.Common.Helper { this._getField = getfield; } - public bool Equals(T x, T y) + public bool Equals(T? x, T? y) { - return EqualityComparer.Default.Equals(_getField(x), _getField(y)); + return EqualityComparer.Default.Equals(_getField(x!), _getField(y!)); } + public int GetHashCode(T obj) { - return EqualityComparer.Default.GetHashCode(this._getField(obj)); + return EqualityComparer.Default.GetHashCode(this._getField(obj)!); } } public static class DistinctHelper diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/HttpHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/HttpHelper.cs index 7e639c88..94e244ca 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/HttpHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/HttpHelper.cs @@ -28,7 +28,7 @@ namespace Yi.Framework.Common.Helper } - public static async Task Post(string url, object item = null, Dictionary head = null) + public static async Task Post(string url, object? item = null, Dictionary? head = null) { using StringContent json = new(JsonSerializer.Serialize(item), Encoding.UTF8, MediaTypeNames.Application.Json); diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/IpHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/IpHelper.cs index b39d112a..700be7b5 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/IpHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/IpHelper.cs @@ -24,6 +24,11 @@ namespace Yi.Framework.Common.Helper // 获取所有可用网卡IP信息 var ipCollection = nics?.Select(x => x.GetIPProperties())?.SelectMany(x => x.UnicastAddresses); + if (ipCollection is null) + { + return instanceIp; + } + foreach (var ipadd in ipCollection) { if (!IPAddress.IsLoopback(ipadd.Address) && ipadd.Address.AddressFamily == AddressFamily.InterNetwork) diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/JsonHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/JsonHelper.cs index 9b983cbe..6ceefa24 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/JsonHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/JsonHelper.cs @@ -15,7 +15,7 @@ namespace Yi.Framework.Common.Helper public static T StrToObj(string str) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(str); + return Newtonsoft.Json.JsonConvert.DeserializeObject(str)!; } /// /// 转换对象为JSON格式数据 @@ -85,7 +85,7 @@ namespace Yi.Framework.Common.Helper { System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(T)); - return (T)serializer.ReadObject(ms); + return (T)serializer.ReadObject(ms)!; } } diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/MD5Hepler.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/MD5Hepler.cs index 9cd1def1..e050c8b8 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/MD5Hepler.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/MD5Hepler.cs @@ -35,7 +35,7 @@ namespace Yi.Framework.Common.Helper byte[] bIn = Encoding.Unicode.GetBytes(pass); byte[] bSalt = Convert.FromBase64String(salt); byte[] bAll = new byte[bSalt.Length + bIn.Length]; - byte[] bRet = null; + byte[]? bRet = null; Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length); Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length); diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/MimeHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/MimeHelper.cs index bd783d48..3c72676e 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/MimeHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/MimeHelper.cs @@ -22,15 +22,15 @@ namespace Yi.Framework.Common.Helper public static string GetMimeMapping(string FileName) { - string text = null; + string text = null!; int num = FileName.LastIndexOf('.'); if (0 < num && num > FileName.LastIndexOf('\\')) { - text = (string)MimeHelper._mimeMappingTable[FileName.Substring(num)]; + text = (string)MimeHelper._mimeMappingTable[FileName.Substring(num)]!; } if (text == null) { - text = (string)MimeHelper._mimeMappingTable[".*"]; + text = (string)MimeHelper._mimeMappingTable[".*"]!; } return text; } diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/RSAHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/RSAHelper.cs index f439b544..0501f3dd 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/RSAHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/RSAHelper.cs @@ -11,8 +11,8 @@ namespace Yi.Framework.Common.Helper /// public class RSAHelper { - public readonly RSA _privateKeyRsaProvider; - public readonly RSA _publicKeyRsaProvider; + public readonly RSA? _privateKeyRsaProvider; + public readonly RSA? _publicKeyRsaProvider; private readonly HashAlgorithmName _hashAlgorithmName; private readonly Encoding _encoding; @@ -23,7 +23,7 @@ namespace Yi.Framework.Common.Helper /// 编码类型 /// 私钥 /// 公钥 - public RSAHelper(RSAType rsaType, Encoding encoding, string privateKey, string publicKey = null) + public RSAHelper(RSAType rsaType, Encoding encoding, string privateKey, string? publicKey = null) { _encoding = encoding; if (!string.IsNullOrEmpty(privateKey)) @@ -50,7 +50,7 @@ namespace Yi.Framework.Common.Helper { byte[] dataBytes = _encoding.GetBytes(data); - var signatureBytes = _privateKeyRsaProvider.SignData(dataBytes, _hashAlgorithmName, RSASignaturePadding.Pkcs1); + var signatureBytes = _privateKeyRsaProvider!.SignData(dataBytes, _hashAlgorithmName, RSASignaturePadding.Pkcs1); return Convert.ToBase64String(signatureBytes); } @@ -70,7 +70,7 @@ namespace Yi.Framework.Common.Helper byte[] dataBytes = _encoding.GetBytes(data); byte[] signBytes = Convert.FromBase64String(sign); - var verify = _publicKeyRsaProvider.VerifyData(dataBytes, signBytes, _hashAlgorithmName, RSASignaturePadding.Pkcs1); + var verify = _publicKeyRsaProvider!.VerifyData(dataBytes, signBytes, _hashAlgorithmName, RSASignaturePadding.Pkcs1); return verify; } @@ -225,7 +225,7 @@ namespace Yi.Framework.Common.Helper /// /// /// - public RSA CreateRsaProviderFromPublicKey(string publicKeyString) + public RSA? CreateRsaProviderFromPublicKey(string publicKeyString) { // encoded OID sequence for PKCS #1 rsaEncryption szOID_RSA_RSA = "1.2.840.113549.1.1.1" byte[] seqOid = { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00 }; diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/SerializeHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/SerializeHelper.cs index 9a5aee9b..4370de2c 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/SerializeHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/SerializeHelper.cs @@ -22,7 +22,7 @@ namespace Yi.Framework.Common.Helper /// /// /// - public static TEntity Deserialize(byte[] value) + public static TEntity? Deserialize(byte[] value) { if (value == null) { diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/StringHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/StringHelper.cs index b4287ed5..e44951d9 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/StringHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/StringHelper.cs @@ -50,7 +50,7 @@ namespace Yi.Framework.Common.Helper { StringBuilder sb = new StringBuilder(); - string urlPars = null; + string? urlPars = null; bool isEnter = false; foreach (var item in dic) { @@ -69,7 +69,7 @@ namespace Yi.Framework.Common.Helper { StringBuilder sb = new StringBuilder(); - string urlPars = null; + string? urlPars = null; bool isEnter = false; foreach (var item in dic) { diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/TreeHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/TreeHelper.cs index b1252d6b..fc7cf398 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/TreeHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/TreeHelper.cs @@ -9,13 +9,13 @@ namespace Yi.Framework.Common.Helper { public static class TreeHelper { - public static List SetTree(List list, Action action = null) + public static List SetTree(List list, Action action = null!) { if (list is not null && list.Count > 0) { IList result = new List(); - long pid = list.Min(m => (m as ITreeModel).ParentId); - IList t = list.Where(m => (m as ITreeModel).ParentId == pid).ToList(); + long pid = list.Min(m => (m as ITreeModel)!.ParentId); + IList t = list.Where(m => (m as ITreeModel)!.ParentId == pid).ToList(); foreach (T model in t) { if (action is not null) @@ -24,20 +24,20 @@ namespace Yi.Framework.Common.Helper } result.Add(model); var item = (model as ITreeModel); - IList children = list.Where(m => (m as ITreeModel).ParentId == item.Id).ToList(); + IList children = list.Where(m => (m as ITreeModel)!.ParentId == item!.Id).ToList(); if (children.Count > 0) { - SetTreeChildren(list, children, model, action); + SetTreeChildren(list, children, model, action!); } } - return result.OrderByDescending(m => (m as ITreeModel).OrderNum).ToList(); + return result.OrderByDescending(m => (m as ITreeModel)!.OrderNum).ToList(); } - return null; + return null!; } - private static void SetTreeChildren(IList list, IList children, T model, Action action = null) + private static void SetTreeChildren(IList list, IList children, T model, Action action = null!) { var mm = (model as ITreeModel); - mm.Children = new List(); + mm!.Children = new List(); foreach (T item in children) { if (action is not null) @@ -46,13 +46,13 @@ namespace Yi.Framework.Common.Helper } mm.Children.Add(item); var _item = (item as ITreeModel); - IList _children = list.Where(m => (m as ITreeModel).ParentId == _item.Id).ToList(); + IList _children = list.Where(m => (m as ITreeModel)!.ParentId == _item!.Id).ToList(); if (_children.Count > 0) { - SetTreeChildren(list, _children, item, action); + SetTreeChildren(list, _children, item, action!); } } - mm.Children = mm.Children.OrderByDescending(m => (m as ITreeModel).OrderNum).ToList(); + mm.Children = mm.Children.OrderByDescending(m => (m as ITreeModel)!.OrderNum).ToList(); } } } diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Helper/XmlHelper.cs b/Yi.Framework.Net6/Yi.Framework.Common/Helper/XmlHelper.cs index 44133350..538c774a 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Helper/XmlHelper.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Helper/XmlHelper.cs @@ -13,7 +13,7 @@ namespace Yi.Framework.Common.Helper /// /// 对象 /// 字符格式的JSON数据 - public static string GetXML(object obj) + public static string? GetXML(object obj) { try { @@ -42,7 +42,7 @@ namespace Yi.Framework.Common.Helper XmlSerializer serializer = new XmlSerializer(typeof(T), new XmlRootAttribute(rootName)); StringReader reader = new StringReader(xml); - T res = (T)serializer.Deserialize(reader); + T res = (T)serializer.Deserialize(reader)!; reader.Close(); reader.Dispose(); return res; diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Models/Result.cs b/Yi.Framework.Net6/Yi.Framework.Common/Models/Result.cs index f0f75e4b..5ddd8ff7 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Models/Result.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Models/Result.cs @@ -6,12 +6,12 @@ namespace Yi.Framework.Common.Models { public class Result { - public static IStringLocalizer _local; + public static IStringLocalizer? _local; public ResultCodeEnum Code { get; set; } public bool Status { get; set; } - public string Message { get; set; } - public object Data { get; set; } + public string? Message { get; set; } + public object? Data { get; set; } public static Result Expire(ResultCodeEnum Code, string msg="") { return new Result() { Code = Code, Status=false, Message = Get(msg, "token_expiration") }; @@ -49,7 +49,7 @@ namespace Yi.Framework.Common.Models this.Status = _Status; return this; } - public Result SetData(object obj) + public Result SetData(object? obj) { this.Data = obj; return this; @@ -74,7 +74,10 @@ namespace Yi.Framework.Common.Models { if (msg=="") { - msg = _local[msg2]; + if (_local is not null) + { + msg = _local[msg2]; + } } return msg; } @@ -82,8 +85,8 @@ namespace Yi.Framework.Common.Models public class Result { public ResultCodeEnum Code { get; set; } - public string Message { get; set; } - public T Data { get; set; } + public string? Message { get; set; } + public T? Data { get; set; } public static Result Error(string msg = "fail") { return new Result() { Code = ResultCodeEnum.NotSuccess, Message = msg }; diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Yi.Framework.Common.csproj b/Yi.Framework.Net6/Yi.Framework.Common/Yi.Framework.Common.csproj index 5b591087..784b6b95 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Yi.Framework.Common.csproj +++ b/Yi.Framework.Net6/Yi.Framework.Common/Yi.Framework.Common.csproj @@ -2,6 +2,7 @@ net6.0 + enable diff --git a/Yi.Framework.Net6/Yi.Framework.Model/RABC/Entitys/MenuEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/RABC/Entitys/MenuEntity.cs index f0ee48e7..86bd8a30 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/RABC/Entitys/MenuEntity.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/RABC/Entitys/MenuEntity.cs @@ -138,7 +138,7 @@ namespace Yi.Framework.Model.RABC.Entitys //开头大写 r.Name = routerName?.First().ToString().ToUpper() + routerName?.Substring(1); - r.Path = m.Router; + r.Path = m.Router!; r.Hidden = !m.IsShow ?? false; @@ -162,18 +162,18 @@ namespace Yi.Framework.Model.RABC.Entitys r.Redirect = "noRedirect"; r.AlwaysShow = true; - r.Component = m.Component; + r.Component = m.Component!; r.AlwaysShow = false; } r.Meta = new Meta { - Title = m.MenuName, - Icon = m.MenuIcon, + Title = m.MenuName!, + Icon = m.MenuIcon!, NoCache = !m.IsCache ?? true }; if (m.IsLink ?? false) { - r.Meta.link = m.Router; + r.Meta.link = m.Router!; r.AlwaysShow = false; } diff --git a/Yi.Framework.Net6/Yi.Framework.Model/RABC/Entitys/UserEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/RABC/Entitys/UserEntity.cs index cb7e35f1..89fc1d19 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/RABC/Entitys/UserEntity.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/RABC/Entitys/UserEntity.cs @@ -169,6 +169,10 @@ namespace Yi.Framework.Model.RABC.Entitys /// public bool JudgePassword(string password) { + if (this.Salt is null) + { + throw new ArgumentNullException(this.Salt); + } var p = MD5Helper.SHA2Encode(password, Salt); if (Password == MD5Helper.SHA2Encode(password, Salt)) { diff --git a/Yi.Framework.Net6/Yi.Framework.Template/TemplateFactory.cs b/Yi.Framework.Net6/Yi.Framework.Template/TemplateFactory.cs index 76c879fc..2196a913 100644 --- a/Yi.Framework.Net6/Yi.Framework.Template/TemplateFactory.cs +++ b/Yi.Framework.Net6/Yi.Framework.Template/TemplateFactory.cs @@ -10,11 +10,10 @@ namespace Yi.Framework.Template { public class TemplateFactory { - private List _templateProviders; + private List _templateProviders=new List(); public void CreateTemplateProviders(Action> action) { - _templateProviders=new List(); action(_templateProviders); } diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/AspNetCoreExtensions/LocalizerExtend.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/AspNetCoreExtensions/LocalizerExtend.cs index 6a4c94b5..f1f837f7 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/AspNetCoreExtensions/LocalizerExtend.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/AspNetCoreExtensions/LocalizerExtend.cs @@ -22,7 +22,7 @@ namespace Yi.Framework.WebCore.AspNetCoreExtensions public static void UseLocalizerService(this IApplicationBuilder app) { - Result._local = app.ApplicationServices.GetService>(); + Result._local = app.ApplicationServices.GetRequiredService>(); var support = new[] { "zh", "en" }; var local = new RequestLocalizationOptions().SetDefaultCulture(support[0]) diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/DbExtend/DbFiterExtend.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/DbExtend/DbFiterExtend.cs index 5d22d284..9fa35866 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/DbExtend/DbFiterExtend.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/DbExtend/DbFiterExtend.cs @@ -42,7 +42,7 @@ namespace Yi.Framework.WebCore.DbExtend var roles = userRoleMenu?.Roles; - if (roles.IsNull()) + if (roles!.IsNull()) { roles = new(); } diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/FilterExtend/CustomExceptionFilterAttribute.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/FilterExtend/CustomExceptionFilterAttribute.cs index 7e6754b6..10f787c7 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/FilterExtend/CustomExceptionFilterAttribute.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/FilterExtend/CustomExceptionFilterAttribute.cs @@ -33,7 +33,7 @@ namespace Yi.Framework.WebCore.FilterExtend var logModel = new LogModel() { OriginalClassName = "", - OriginalMethodName = actionName, + OriginalMethodName = actionName??"", Remark = $"来源于{nameof(CustomExceptionFilterAttribute)}.{nameof(OnException)}" }; this._logger.LogError(context.Exception, $"{url}----->actionName={actionName} Message={context.Exception.Message}", JsonConvert.SerializeObject(logModel)); diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/FilterExtend/LogActionFilterAttribute.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/FilterExtend/LogActionFilterAttribute.cs index 0e91e039..dc84f153 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/FilterExtend/LogActionFilterAttribute.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/FilterExtend/LogActionFilterAttribute.cs @@ -30,8 +30,8 @@ namespace Yi.Framework.WebCore.FilterExtend LogModel logModel = new LogModel() { - OriginalClassName = controllerName, - OriginalMethodName = actionName, + OriginalClassName = controllerName??"", + OriginalMethodName = actionName ?? "", Remark = $"来源于{nameof(LogActionFilterAttribute)}.{nameof(OnActionExecuting)}" }; diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/CurrentUserExrension.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/CurrentUserExrension.cs index 09f8e8fe..b0b1bd30 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/CurrentUserExrension.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/CurrentUserExrension.cs @@ -53,7 +53,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend //通过鉴权之后,开始赋值 _currentUser.IsAuthenticated = true; _currentUser.Id = claims.GetClaim(JwtRegisteredClaimNames.Sid) is null ? 0 : Convert.ToInt64(claims.GetClaim(JwtRegisteredClaimNames.Sid)); - _currentUser.UserName = claims.GetClaim(SystemConst.UserName); + _currentUser.UserName = claims.GetClaim(SystemConst.UserName)??""; _currentUser.Permission = claims.GetClaims(SystemConst.PermissionClaim); _currentUser.TenantId = claims.GetClaim(SystemConst.TenantId) is null ? null : Guid.Parse(claims.GetClaim(SystemConst.TenantId)!); await _next(context);