From 0399861ee720a5c3856a4945c82ca08c95f4c676 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Thu, 28 Sep 2023 12:25:37 -0500 Subject: [PATCH] add guid try parse --- .../Repository/MongoRepository.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs index 364cf6e3..5ea7e8e0 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs @@ -189,7 +189,7 @@ public class MongoRepository : IBotSharpRepository { Id = string.IsNullOrEmpty(x.Id) ? Guid.NewGuid() : new Guid(x.Id), AgentId = Guid.Parse(x.AgentId), - UserId = Guid.Parse(x.UserId), + UserId = !string.IsNullOrEmpty(x.UserId) && Guid.TryParse(x.UserId, out var _) ? Guid.Parse(x.UserId) : Guid.Empty, Title = x.Title, States = x.States?.ToKeyValueList() ?? new List(), CreatedTime = x.CreatedTime, @@ -293,7 +293,7 @@ public class MongoRepository : IBotSharpRepository { Id = string.IsNullOrEmpty(x.Id) ? Guid.NewGuid() : new Guid(x.Id), AgentId = Guid.Parse(x.AgentId), - UserId = Guid.Parse(x.UserId), + UserId = !string.IsNullOrEmpty(x.UserId) && Guid.TryParse(x.UserId, out var _) ? Guid.Parse(x.UserId) : Guid.Empty, CreatedTime = x.CreatedTime, UpdatedTime = x.UpdatedTime }).ToList(); @@ -550,7 +550,7 @@ public class MongoRepository : IBotSharpRepository { Id = !string.IsNullOrEmpty(conversation.Id) ? Guid.Parse(conversation.Id) : Guid.NewGuid(), AgentId = Guid.Parse(conversation.AgentId), - UserId = !string.IsNullOrEmpty(conversation.UserId) ? Guid.Parse(conversation.UserId) : Guid.Empty, + UserId = !string.IsNullOrEmpty(conversation.UserId) && Guid.TryParse(conversation.UserId, out var _) ? Guid.Parse(conversation.UserId) : Guid.Empty, Title = conversation.Title, States = conversation.States?.ToKeyValueList() ?? new List(), CreatedTime = DateTime.UtcNow, @@ -652,7 +652,7 @@ public class MongoRepository : IBotSharpRepository public List GetConversations(string userId) { var records = new List(); - if (string.IsNullOrEmpty(userId)) return records; + if (string.IsNullOrEmpty(userId) || Guid.TryParse(userId, out var _)) return records; var filterByUserId = Builders.Filter.Eq(x => x.UserId, Guid.Parse(userId)); var conversations = _dc.Conversations.Find(filterByUserId).ToList();