From 2da0738339ff0ccb45616545865bc52373654c7c Mon Sep 17 00:00:00 2001 From: Argo-Cloud <argo@163.com> Date: Wed, 18 Nov 2020 14:50:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20DataAccess=20=E6=B6=88=E7=81=AD?= =?UTF-8?q?=E8=AD=A6=E5=91=8A=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/admin/Bootstrap.DataAccess/App.cs | 4 ++-- src/admin/Bootstrap.DataAccess/AutoDB.cs | 2 +- .../Bootstrap.DataAccess.csproj | 2 +- src/admin/Bootstrap.DataAccess/DbManager.cs | 2 +- src/admin/Bootstrap.DataAccess/Group.cs | 12 +++++----- .../Helper/LoginHelper.cs | 2 +- .../Helper/OAuthHelper.cs | 2 +- .../Helper/QueryAppOption.cs | 12 +++++----- .../Helper/TraceHelper.cs | 2 +- src/admin/Bootstrap.DataAccess/Menu.cs | 8 +++---- src/admin/Bootstrap.DataAccess/Role.cs | 16 ++++++------- src/admin/Bootstrap.DataAccess/User.cs | 24 +++++++++---------- 12 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/admin/Bootstrap.DataAccess/App.cs b/src/admin/Bootstrap.DataAccess/App.cs index 5f547608..cae79d56 100644 --- a/src/admin/Bootstrap.DataAccess/App.cs +++ b/src/admin/Bootstrap.DataAccess/App.cs @@ -74,10 +74,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } diff --git a/src/admin/Bootstrap.DataAccess/AutoDB.cs b/src/admin/Bootstrap.DataAccess/AutoDB.cs index 50de4654..91d99c35 100644 --- a/src/admin/Bootstrap.DataAccess/AutoDB.cs +++ b/src/admin/Bootstrap.DataAccess/AutoDB.cs @@ -78,7 +78,7 @@ namespace Bootstrap.DataAccess { var psi = new ProcessStartInfo("powershell", $"{file} \"{folder}\""); var p = Process.Start(psi); - p.WaitForExit(); + p!.WaitForExit(); } } } diff --git a/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 8fcba11a..de913bee 100644 --- a/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -15,7 +15,7 @@ <PackageReference Include="Longbow.GitHubAuth" Version="5.0.0" /> <PackageReference Include="Longbow.OAuth" Version="5.0.0" /> <PackageReference Include="Longbow.PetaPoco" Version="5.0.0" /> - <PackageReference Include="Longbow.Security.Cryptography" Version="1.3.1" /> + <PackageReference Include="Longbow.Security.Cryptography" Version="5.0.0" /> <PackageReference Include="Longbow.Tasks" Version="5.0.0" /> <PackageReference Include="Longbow.TencentAuth" Version="5.0.0" /> <PackageReference Include="Longbow.Web" Version="5.0.0" /> diff --git a/src/admin/Bootstrap.DataAccess/DbManager.cs b/src/admin/Bootstrap.DataAccess/DbManager.cs index 7669acb7..c1c2c08e 100644 --- a/src/admin/Bootstrap.DataAccess/DbManager.cs +++ b/src/admin/Bootstrap.DataAccess/DbManager.cs @@ -30,7 +30,7 @@ namespace Bootstrap.DataAccess db.OnCommandExecuted(async provider => { var context = provider.GetRequiredService<IHttpContextAccessor>(); - var userName = context.HttpContext?.User.Identity.Name; + var userName = context.HttpContext?.User.Identity?.Name; var log = new DBLog() { LogTime = DateTime.Now, diff --git a/src/admin/Bootstrap.DataAccess/Group.cs b/src/admin/Bootstrap.DataAccess/Group.cs index 72badbd0..2ffbb58e 100644 --- a/src/admin/Bootstrap.DataAccess/Group.cs +++ b/src/admin/Bootstrap.DataAccess/Group.cs @@ -52,10 +52,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception e) + catch (Exception) { db.AbortTransaction(); - throw e; + throw; } return ret; } @@ -113,10 +113,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } @@ -140,10 +140,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } diff --git a/src/admin/Bootstrap.DataAccess/Helper/LoginHelper.cs b/src/admin/Bootstrap.DataAccess/Helper/LoginHelper.cs index 256408e1..2d6303c6 100644 --- a/src/admin/Bootstrap.DataAccess/Helper/LoginHelper.cs +++ b/src/admin/Bootstrap.DataAccess/Helper/LoginHelper.cs @@ -24,7 +24,7 @@ namespace Bootstrap.DataAccess public static bool Log(this HttpContext context, string userName, bool auth) { var ipLocator = context.RequestServices.GetRequiredService<IIPLocatorProvider>(); - var ip = context.Connection.RemoteIpAddress.ToIPv4String(); + var ip = context.Connection.RemoteIpAddress?.ToIPv4String() ?? ""; var userAgent = context.Request.Headers["User-Agent"]; var agent = new UserAgent(userAgent); diff --git a/src/admin/Bootstrap.DataAccess/Helper/OAuthHelper.cs b/src/admin/Bootstrap.DataAccess/Helper/OAuthHelper.cs index f769c879..8b47912e 100644 --- a/src/admin/Bootstrap.DataAccess/Helper/OAuthHelper.cs +++ b/src/admin/Bootstrap.DataAccess/Helper/OAuthHelper.cs @@ -33,7 +33,7 @@ namespace Bootstrap.DataAccess var webhookUrls = config.GetSection<TOptions>().GetValue("StarredUrl", "").SpanSplit(";", StringSplitOptions.RemoveEmptyEntries); foreach (var webhookUrl in webhookUrls) { - var webhookParameters = new Dictionary<string, string>() + var webhookParameters = new Dictionary<string, string?>() { { "access_token", context.AccessToken } }; diff --git a/src/admin/Bootstrap.DataAccess/Helper/QueryAppOption.cs b/src/admin/Bootstrap.DataAccess/Helper/QueryAppOption.cs index 7ff14e5e..c5655896 100644 --- a/src/admin/Bootstrap.DataAccess/Helper/QueryAppOption.cs +++ b/src/admin/Bootstrap.DataAccess/Helper/QueryAppOption.cs @@ -66,12 +66,12 @@ namespace Bootstrap.DataAccess { var ret = new QueryAppOption() { AppCode = key }; var dicts = DictHelper.RetrieveDicts(); - ret.AppName = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == key).Name ?? ""; - ret.AppUrl = dicts.FirstOrDefault(d => d.Category == "应用首页" && d.Name == key).Code ?? ""; - ret.AppTitle = dicts.FirstOrDefault(d => d.Category == ret.AppName && d.Name == "网站标题").Code ?? ""; - ret.AppFooter = dicts.FirstOrDefault(d => d.Category == ret.AppName && d.Name == "网站页脚").Code ?? ""; - ret.AppFavicon = dicts.FirstOrDefault(d => d.Category == ret.AppName && d.Name == "网站图标").Code ?? ""; - ret.AppIcon = dicts.FirstOrDefault(d => d.Category == ret.AppName && d.Name == "favicon").Code ?? ""; + ret.AppName = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == key)?.Name ?? ""; + ret.AppUrl = dicts.FirstOrDefault(d => d.Category == "应用首页" && d.Name == key)?.Code ?? ""; + ret.AppTitle = dicts.FirstOrDefault(d => d.Category == ret.AppName && d.Name == "网站标题")?.Code ?? ""; + ret.AppFooter = dicts.FirstOrDefault(d => d.Category == ret.AppName && d.Name == "网站页脚")?.Code ?? ""; + ret.AppFavicon = dicts.FirstOrDefault(d => d.Category == ret.AppName && d.Name == "网站图标")?.Code ?? ""; + ret.AppIcon = dicts.FirstOrDefault(d => d.Category == ret.AppName && d.Name == "favicon")?.Code ?? ""; return ret; } } diff --git a/src/admin/Bootstrap.DataAccess/Helper/TraceHelper.cs b/src/admin/Bootstrap.DataAccess/Helper/TraceHelper.cs index 1bf9bdbe..63dbd33b 100644 --- a/src/admin/Bootstrap.DataAccess/Helper/TraceHelper.cs +++ b/src/admin/Bootstrap.DataAccess/Helper/TraceHelper.cs @@ -20,7 +20,7 @@ namespace Bootstrap.DataAccess /// <param name="v"></param> public static void Save(HttpContext context, OnlineUser v) { - if (context.User.Identity.IsAuthenticated) + if (context.User.Identity!.IsAuthenticated) { var user = UserHelper.RetrieveUserByUserName(context.User.Identity.Name); diff --git a/src/admin/Bootstrap.DataAccess/Menu.cs b/src/admin/Bootstrap.DataAccess/Menu.cs index 82e4a754..eb6565d1 100644 --- a/src/admin/Bootstrap.DataAccess/Menu.cs +++ b/src/admin/Bootstrap.DataAccess/Menu.cs @@ -30,10 +30,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } @@ -87,10 +87,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } diff --git a/src/admin/Bootstrap.DataAccess/Role.cs b/src/admin/Bootstrap.DataAccess/Role.cs index e73c1ab4..e27b53f0 100644 --- a/src/admin/Bootstrap.DataAccess/Role.cs +++ b/src/admin/Bootstrap.DataAccess/Role.cs @@ -65,10 +65,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } @@ -103,10 +103,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } @@ -170,10 +170,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } @@ -207,10 +207,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } diff --git a/src/admin/Bootstrap.DataAccess/User.cs b/src/admin/Bootstrap.DataAccess/User.cs index 79d97941..28ac3440 100644 --- a/src/admin/Bootstrap.DataAccess/User.cs +++ b/src/admin/Bootstrap.DataAccess/User.cs @@ -172,10 +172,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } @@ -203,10 +203,10 @@ namespace Bootstrap.DataAccess if (ret) db.Execute("delete from ResetUsers where UserName = @0", userName); db.CompleteTransaction(); } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } @@ -242,10 +242,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } @@ -297,10 +297,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } @@ -335,10 +335,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; } @@ -373,10 +373,10 @@ namespace Bootstrap.DataAccess db.CompleteTransaction(); ret = true; } - catch (Exception ex) + catch (Exception) { db.AbortTransaction(); - throw ex; + throw; } return ret; }