temp save

This commit is contained in:
Jicheng Lu 2023-09-19 11:38:31 -05:00
parent 4a219798d9
commit 16b6683c01
3 changed files with 60 additions and 3 deletions

View file

@ -4,6 +4,7 @@ using FunctionDef = BotSharp.Abstraction.Functions.Models.FunctionDef;
using BotSharp.Abstraction.Users.Models;
using BotSharp.Abstraction.Agents.Models;
using MongoDB.Driver;
using BotSharp.Abstraction.Routing.Models;
namespace BotSharp.Core.Repository;
@ -240,6 +241,18 @@ public class FileRepository : IBotSharpRepository
case AgentField.IsPublic:
UpdateAgentIsPublic(agent.Id, agent.IsPublic);
break;
case AgentField.Disabled:
UpdateAgentDisabled(agent.Id, agent.Disabled);
break;
case AgentField.AllowRouting:
UpdateAgentAllowRouting(agent.Id, agent.AllowRouting);
break;
case AgentField.Profiles:
UpdateAgentProfiles(agent.Id, agent.Profiles);
break;
case AgentField.RoutingRules:
UpdateAgentRoutingRules(agent.Id, agent.RoutingRules);
break;
case AgentField.Instruction:
UpdateAgentInstruction(agent.Id, agent.Instruction);
break;
@ -298,6 +311,50 @@ public class FileRepository : IBotSharpRepository
File.WriteAllText(agentFile, json);
}
private void UpdateAgentDisabled(string agentId, bool disabled)
{
var (agent, agentFile) = GetAgentFromFile(agentId);
if (agent == null) return;
agent.Disabled = disabled;
agent.UpdatedDateTime = DateTime.UtcNow;
var json = JsonSerializer.Serialize(agent, _options);
File.WriteAllText(agentFile, json);
}
private void UpdateAgentAllowRouting(string agentId, bool allowRouting)
{
var (agent, agentFile) = GetAgentFromFile(agentId);
if (agent == null) return;
agent.AllowRouting = allowRouting;
agent.UpdatedDateTime = DateTime.UtcNow;
var json = JsonSerializer.Serialize(agent, _options);
File.WriteAllText(agentFile, json);
}
private void UpdateAgentProfiles(string agentId, List<string> profiles)
{
var (agent, agentFile) = GetAgentFromFile(agentId);
if (agent == null) return;
agent.Profiles = profiles;
agent.UpdatedDateTime = DateTime.UtcNow;
var json = JsonSerializer.Serialize(agent, _options);
File.WriteAllText(agentFile, json);
}
private void UpdateAgentRoutingRules(string agentId, List<RoutingRule> rules)
{
var (agent, agentFile) = GetAgentFromFile(agentId);
if (agent == null) return;
agent.RoutingRules = rules;
agent.UpdatedDateTime = DateTime.UtcNow;
var json = JsonSerializer.Serialize(agent, _options);
File.WriteAllText(agentFile, json);
}
private void UpdateAgentInstruction(string agentId, string instruction)
{
if (string.IsNullOrEmpty(instruction)) return;

View file

@ -15,7 +15,7 @@ public class AgentCollection : MongoBase
public bool AllowRouting { get; set; }
public bool Disabled { get; set; }
public List<string> Profiles { get; set; }
public List<RoutintRuleElement> RoutingRules { get; set; }
public List<RoutingRuleElement> RoutingRules { get; set; }
public DateTime CreatedTime { get; set; }
public DateTime UpdatedTime { get; set; }

View file

@ -218,8 +218,8 @@ public class MongoRepository : IBotSharpRepository
Disabled = x.Disabled,
Profiles = x.Profiles,
RoutingRules = x.RoutingRules?
.Select(r => RoutingRuleElement.ToMongoElement(r))?
.ToList() ?? new List<RoutingRuleElement>(),
.Select(r => RoutingRuleElement.ToMongoElement(r))?
.ToList() ?? new List<RoutingRuleElement>(),
CreatedTime = x.CreatedDateTime,
UpdatedTime = x.UpdatedDateTime
}).ToList();