From f3812084984b77ff5c99672158913f3c59eea234 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Sun, 3 Sep 2023 17:58:07 -0500 Subject: [PATCH] use list extension --- .../BotSharp.Abstraction/Utilities/ListExtenstion.cs | 2 +- .../BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs | 2 +- .../BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs | 4 ++-- src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs | 2 +- src/Infrastructure/BotSharp.Core/Routing/Router.cs | 2 +- .../BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Utilities/ListExtenstion.cs b/src/Infrastructure/BotSharp.Abstraction/Utilities/ListExtenstion.cs index df68be64..7dcc566a 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Utilities/ListExtenstion.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Utilities/ListExtenstion.cs @@ -2,7 +2,7 @@ namespace BotSharp.Abstraction.Utilities; public static class ListExtenstion { - public static bool IsEmpty(this IEnumerable strList) + public static bool IsEmpty(this IEnumerable strList) { return strList == null || !strList.Any(); } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index 9243d28a..89a915f5 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -30,7 +30,7 @@ public partial class AgentService hook.OnInstructionLoaded(agent.Instruction, templateDict); } - if (agent.Functions != null && agent.Functions.Any()) + if (!agent.Functions.IsEmpty()) { var functions = agent.Functions; hook.OnFunctionsLoaded(ref functions); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index a14620f1..7c4a3183 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -27,10 +27,10 @@ public partial class AgentService if (!string.IsNullOrEmpty(agent.Instruction)) record.Instruction = agent.Instruction; - if (agent.Functions != null && agent.Functions.Any()) + if (!agent.Functions.IsEmpty()) record.Functions = agent.Functions; - if (agent.Responses != null && agent.Responses.Any()) + if (!agent.Responses.IsEmpty()) record.Responses = agent.Responses; db.UpdateAgent(record); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs index e85d932f..82a9162d 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs @@ -311,7 +311,7 @@ public class FileRepository : IBotSharpRepository File.WriteAllText(instructionFile, agent.Instruction); } - if (agent.Functions != null || agent.Functions.Any()) + if (!agent.Functions.IsEmpty()) { var functionFile = Path.Combine(dir, "functions.json"); var functions = new List(); diff --git a/src/Infrastructure/BotSharp.Core/Routing/Router.cs b/src/Infrastructure/BotSharp.Core/Routing/Router.cs index 296a3b02..8f1b5de4 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Router.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Router.cs @@ -36,7 +36,7 @@ public class Router : IAgentRouting var records = db.RoutingItem.Select(x => x.ToRoutingItem()).ToArray(); var profiles = db.RoutingProfile.ToList(); - if (profiles != null && profiles.Any()) + if (!profiles.IsEmpty()) { var state = _services.GetRequiredService(); var name = state.GetState("channel"); diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs index 3df3fc6a..6f3912a5 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs @@ -43,10 +43,10 @@ public class AgentUpdateModel if (Samples != null) agent.Samples = Samples; - if (Functions != null && Functions.Any()) + if (!Functions.IsEmpty()) agent.Functions = Functions; - if (Responses != null && Responses.Any()) + if (!Responses.IsEmpty()) agent.Responses = Responses; return agent;