Merge pull request #276 from iceljc/features/add-agent-inherit-id
add inherit agent id in mongo
This commit is contained in:
commit
cf780ebd21
|
|
@ -8,6 +8,7 @@ public enum AgentField
|
|||
IsPublic,
|
||||
Disabled,
|
||||
Type,
|
||||
InheritAgentId,
|
||||
Profiles,
|
||||
RoutingRule,
|
||||
Instruction,
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ namespace BotSharp.Core.Repository
|
|||
case AgentField.Type:
|
||||
UpdateAgentType(agent.Id, agent.Type);
|
||||
break;
|
||||
case AgentField.InheritAgentId:
|
||||
UpdateAgentInheritAgentId(agent.Id, agent.InheritAgentId);
|
||||
break;
|
||||
case AgentField.Profiles:
|
||||
UpdateAgentProfiles(agent.Id, agent.Profiles);
|
||||
break;
|
||||
|
|
@ -123,6 +126,17 @@ namespace BotSharp.Core.Repository
|
|||
File.WriteAllText(agentFile, json);
|
||||
}
|
||||
|
||||
private void UpdateAgentInheritAgentId(string agentId, string? inheritAgentId)
|
||||
{
|
||||
var (agent, agentFile) = GetAgentFromFile(agentId);
|
||||
if (agent == null) return;
|
||||
|
||||
agent.InheritAgentId = inheritAgentId;
|
||||
agent.UpdatedDateTime = DateTime.UtcNow;
|
||||
var json = JsonSerializer.Serialize(agent, _options);
|
||||
File.WriteAllText(agentFile, json);
|
||||
}
|
||||
|
||||
private void UpdateAgentProfiles(string agentId, List<string> profiles)
|
||||
{
|
||||
if (profiles.IsNullOrEmpty()) return;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ public class AgentDocument : MongoBase
|
|||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string? InheritAgentId { get; set; }
|
||||
public string? IconUrl { get; set; }
|
||||
public string Instruction { get; set; }
|
||||
public List<AgentTemplateMongoElement> Templates { get; set; }
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ public partial class MongoRepository
|
|||
case AgentField.Type:
|
||||
UpdateAgentType(agent.Id, agent.Type);
|
||||
break;
|
||||
case AgentField.InheritAgentId:
|
||||
UpdateAgentInheritAgentId(agent.Id, agent.InheritAgentId);
|
||||
break;
|
||||
case AgentField.Profiles:
|
||||
UpdateAgentProfiles(agent.Id, agent.Profiles);
|
||||
break;
|
||||
|
|
@ -119,6 +122,16 @@ public partial class MongoRepository
|
|||
_dc.Agents.UpdateOne(filter, update);
|
||||
}
|
||||
|
||||
private void UpdateAgentInheritAgentId(string agentId, string? inheritAgentId)
|
||||
{
|
||||
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
|
||||
var update = Builders<AgentDocument>.Update
|
||||
.Set(x => x.InheritAgentId, inheritAgentId)
|
||||
.Set(x => x.UpdatedTime, DateTime.UtcNow);
|
||||
|
||||
_dc.Agents.UpdateOne(filter, update);
|
||||
}
|
||||
|
||||
private void UpdateAgentProfiles(string agentId, List<string> profiles)
|
||||
{
|
||||
if (profiles.IsNullOrEmpty()) return;
|
||||
|
|
@ -268,6 +281,7 @@ public partial class MongoRepository
|
|||
IsPublic = agent.IsPublic,
|
||||
Disabled = agent.Disabled,
|
||||
Type = agent.Type,
|
||||
InheritAgentId = agent.InheritAgentId,
|
||||
Profiles = agent.Profiles,
|
||||
RoutingRules = !agent.RoutingRules.IsNullOrEmpty() ? agent.RoutingRules
|
||||
.Select(r => RoutingRuleMongoElement.ToDomainElement(agent.Id, agent.Name, r))
|
||||
|
|
@ -329,6 +343,7 @@ public partial class MongoRepository
|
|||
IsPublic = x.IsPublic,
|
||||
Disabled = x.Disabled,
|
||||
Type = x.Type,
|
||||
InheritAgentId = x.InheritAgentId,
|
||||
Profiles = x.Profiles,
|
||||
RoutingRules = !x.RoutingRules.IsNullOrEmpty() ? x.RoutingRules
|
||||
.Select(r => RoutingRuleMongoElement.ToDomainElement(x.Id, x.Name, r))
|
||||
|
|
@ -393,6 +408,7 @@ public partial class MongoRepository
|
|||
Samples = x.Samples ?? new List<string>(),
|
||||
IsPublic = x.IsPublic,
|
||||
Type = x.Type,
|
||||
InheritAgentId = x.InheritAgentId,
|
||||
Disabled = x.Disabled,
|
||||
Profiles = x.Profiles,
|
||||
RoutingRules = x.RoutingRules?
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ public partial class MongoRepository
|
|||
Samples = x.Samples ?? new List<string>(),
|
||||
IsPublic = x.IsPublic,
|
||||
Type = x.Type,
|
||||
InheritAgentId = x.InheritAgentId,
|
||||
Disabled = x.Disabled,
|
||||
Profiles = x.Profiles,
|
||||
RoutingRules = x.RoutingRules?
|
||||
|
|
@ -78,6 +79,7 @@ public partial class MongoRepository
|
|||
.Set(x => x.Samples, agent.Samples)
|
||||
.Set(x => x.IsPublic, agent.IsPublic)
|
||||
.Set(x => x.Type, agent.Type)
|
||||
.Set(x => x.InheritAgentId, agent.InheritAgentId)
|
||||
.Set(x => x.Disabled, agent.Disabled)
|
||||
.Set(x => x.Profiles, agent.Profiles)
|
||||
.Set(x => x.RoutingRules, agent.RoutingRules)
|
||||
|
|
|
|||
Loading…
Reference in a new issue