From 7c7a71e8779c6393e981c0b0654cb2b951817022 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Mon, 4 Mar 2024 20:24:07 -0600 Subject: [PATCH] allow empty list update --- .../FileRepository/FileRepository.Agent.cs | 18 +++++++++--------- .../Repository/MongoRepository.Agent.cs | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs index 5ce7d7d8..1fbca99c 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs @@ -69,7 +69,7 @@ namespace BotSharp.Core.Repository #region Update Agent Fields private void UpdateAgentName(string agentId, string name) { - if (string.IsNullOrEmpty(name)) return; + if (string.IsNullOrWhiteSpace(name)) return; var (agent, agentFile) = GetAgentFromFile(agentId); if (agent == null) return; @@ -82,7 +82,7 @@ namespace BotSharp.Core.Repository private void UpdateAgentDescription(string agentId, string description) { - if (string.IsNullOrEmpty(description)) return; + if (string.IsNullOrWhiteSpace(description)) return; var (agent, agentFile) = GetAgentFromFile(agentId); if (agent == null) return; @@ -139,7 +139,7 @@ namespace BotSharp.Core.Repository private void UpdateAgentProfiles(string agentId, List profiles) { - if (profiles.IsNullOrEmpty()) return; + if (profiles == null) return; var (agent, agentFile) = GetAgentFromFile(agentId); if (agent == null) return; @@ -152,7 +152,7 @@ namespace BotSharp.Core.Repository private void UpdateAgentRoutingRules(string agentId, List rules) { - if (rules.IsNullOrEmpty()) return; + if (rules == null) return; var (agent, agentFile) = GetAgentFromFile(agentId); if (agent == null) return; @@ -165,7 +165,7 @@ namespace BotSharp.Core.Repository private void UpdateAgentInstruction(string agentId, string instruction) { - if (string.IsNullOrEmpty(instruction)) return; + if (string.IsNullOrWhiteSpace(instruction)) return; var (agent, agentFile) = GetAgentFromFile(agentId); if (agent == null) return; @@ -178,7 +178,7 @@ namespace BotSharp.Core.Repository private void UpdateAgentFunctions(string agentId, List inputFunctions) { - if (inputFunctions.IsNullOrEmpty()) return; + if (inputFunctions == null) return; var (agent, agentFile) = GetAgentFromFile(agentId); if (agent == null) return; @@ -192,7 +192,7 @@ namespace BotSharp.Core.Repository private void UpdateAgentTemplates(string agentId, List templates) { - if (templates.IsNullOrEmpty()) return; + if (templates == null) return; var (agent, agentFile) = GetAgentFromFile(agentId); if (agent == null) return; @@ -218,7 +218,7 @@ namespace BotSharp.Core.Repository private void UpdateAgentResponses(string agentId, List responses) { - if (responses.IsNullOrEmpty()) return; + if (responses == null) return; var (agent, agentFile) = GetAgentFromFile(agentId); if (agent == null) return; @@ -245,7 +245,7 @@ namespace BotSharp.Core.Repository private void UpdateAgentSamples(string agentId, List samples) { - if (samples.IsNullOrEmpty()) return; + if (samples == null) return; var (agent, agentFile) = GetAgentFromFile(agentId); if (agent == null) return; diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index ba31f6ae..75d496f8 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -72,7 +72,7 @@ public partial class MongoRepository #region Update Agent Fields private void UpdateAgentName(string agentId, string name) { - if (string.IsNullOrEmpty(name)) return; + if (string.IsNullOrWhiteSpace(name)) return; var filter = Builders.Filter.Eq(x => x.Id, agentId); var update = Builders.Update @@ -84,7 +84,7 @@ public partial class MongoRepository private void UpdateAgentDescription(string agentId, string description) { - if (string.IsNullOrEmpty(description)) return; + if (string.IsNullOrWhiteSpace(description)) return; var filter = Builders.Filter.Eq(x => x.Id, agentId); var update = Builders.Update @@ -136,7 +136,7 @@ public partial class MongoRepository private void UpdateAgentProfiles(string agentId, List profiles) { - if (profiles.IsNullOrEmpty()) return; + if (profiles == null) return; var filter = Builders.Filter.Eq(x => x.Id, agentId); var update = Builders.Update @@ -148,7 +148,7 @@ public partial class MongoRepository private void UpdateAgentRoutingRules(string agentId, List rules) { - if (rules.IsNullOrEmpty()) return; + if (rules == null) return; var ruleElements = rules.Select(x => RoutingRuleMongoElement.ToMongoElement(x)).ToList(); var filter = Builders.Filter.Eq(x => x.Id, agentId); @@ -161,7 +161,7 @@ public partial class MongoRepository private void UpdateAgentInstruction(string agentId, string instruction) { - if (string.IsNullOrEmpty(instruction)) return; + if (string.IsNullOrWhiteSpace(instruction)) return; var filter = Builders.Filter.Eq(x => x.Id, agentId); var update = Builders.Update @@ -173,7 +173,7 @@ public partial class MongoRepository private void UpdateAgentFunctions(string agentId, List functions) { - if (functions.IsNullOrEmpty()) return; + if (functions == null) return; var functionsToUpdate = functions.Select(f => FunctionDefMongoElement.ToMongoElement(f)).ToList(); var filter = Builders.Filter.Eq(x => x.Id, agentId); @@ -186,7 +186,7 @@ public partial class MongoRepository private void UpdateAgentTemplates(string agentId, List templates) { - if (templates.IsNullOrEmpty()) return; + if (templates == null) return; var templatesToUpdate = templates.Select(t => AgentTemplateMongoElement.ToMongoElement(t)).ToList(); var filter = Builders.Filter.Eq(x => x.Id, agentId); @@ -199,7 +199,7 @@ public partial class MongoRepository private void UpdateAgentResponses(string agentId, List responses) { - if (responses.IsNullOrEmpty()) return; + if (responses == null) return; var responsesToUpdate = responses.Select(r => AgentResponseMongoElement.ToMongoElement(r)).ToList(); var filter = Builders.Filter.Eq(x => x.Id, agentId); @@ -212,7 +212,7 @@ public partial class MongoRepository private void UpdateAgentSamples(string agentId, List samples) { - if (samples.IsNullOrEmpty()) return; + if (samples == null) return; var filter = Builders.Filter.Eq(x => x.Id, agentId); var update = Builders.Update