fetch routing items and profiles from file
This commit is contained in:
parent
4d25681491
commit
be3150a254
|
|
@ -62,13 +62,6 @@ public partial class AgentService
|
|||
return agentRecord;
|
||||
}
|
||||
|
||||
private JsonSerializerOptions _options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
private Agent FetchAgentInfoFromFile(string agentName, string filePath)
|
||||
{
|
||||
foreach (var dir in Directory.GetDirectories(filePath))
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ public partial class AgentService : IAgentService
|
|||
private readonly ILogger _logger;
|
||||
private readonly IUserIdentity _user;
|
||||
private readonly AgentSettings _settings;
|
||||
private readonly JsonSerializerOptions _options;
|
||||
|
||||
public AgentService(IServiceProvider services,
|
||||
ILogger<AgentService> logger,
|
||||
|
|
@ -20,6 +21,12 @@ public partial class AgentService : IAgentService
|
|||
_logger = logger;
|
||||
_user = user;
|
||||
_settings = settings;
|
||||
_options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
}
|
||||
|
||||
public string GetDataDir()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
using BotSharp.Abstraction.Repositories;
|
||||
using BotSharp.Abstraction.Routing.Models;
|
||||
using System.IO;
|
||||
|
||||
namespace BotSharp.Core.Routing.Services;
|
||||
|
||||
public partial class RoutingService
|
||||
{
|
||||
public async Task<List<RoutingItem>> CreateRoutingItems(List<RoutingItem> routingItems)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var items = FetchRoutingItemsFromFile();
|
||||
|
||||
if (items.IsNullOrEmpty())
|
||||
{
|
||||
items = routingItems?.ToList() ?? new List<RoutingItem>();
|
||||
}
|
||||
|
||||
var savedItems = db.CreateRoutingItems(items);
|
||||
return await Task.FromResult(savedItems.ToList());
|
||||
}
|
||||
|
||||
public async Task<List<RoutingProfile>> CreateRoutingProfiles(List<RoutingProfile> routingProfiles)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var profiles = FetchRoutingProfilesFromFile();
|
||||
|
||||
if (profiles.IsNullOrEmpty())
|
||||
{
|
||||
profiles = routingProfiles?.ToList() ?? new List<RoutingProfile>();
|
||||
}
|
||||
|
||||
var savedProfiles = db.CreateRoutingProfiles(profiles);
|
||||
return await Task.FromResult(savedProfiles.ToList());
|
||||
}
|
||||
|
||||
private List<RoutingItem> FetchRoutingItemsFromFile()
|
||||
{
|
||||
var routingItems = new List<RoutingItem>();
|
||||
var dbSettings = _services.GetRequiredService<BotSharpDatabaseSettings>();
|
||||
var agentSettings = _services.GetRequiredService<AgentSettings>();
|
||||
var filePath = Path.Combine(dbSettings.FileRepository, agentSettings.DataDir, "route.json");
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
routingItems = JsonSerializer.Deserialize<List<RoutingItem>>(File.ReadAllText(filePath), _options);
|
||||
}
|
||||
|
||||
return routingItems ?? new List<RoutingItem>();
|
||||
}
|
||||
|
||||
private List<RoutingProfile> FetchRoutingProfilesFromFile()
|
||||
{
|
||||
var routingProfiles = new List<RoutingProfile>();
|
||||
var dbSettings = _services.GetRequiredService<BotSharpDatabaseSettings>();
|
||||
var agentSettings = _services.GetRequiredService<AgentSettings>();
|
||||
var filePath = Path.Combine(dbSettings.FileRepository, agentSettings.DataDir, "routing-profile.json");
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
routingProfiles = JsonSerializer.Deserialize<List<RoutingProfile>>(File.ReadAllText(filePath), _options);
|
||||
}
|
||||
|
||||
return routingProfiles ?? new List<RoutingProfile>();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
using BotSharp.Abstraction.Repositories;
|
||||
|
||||
namespace BotSharp.Core.Routing.Services;
|
||||
|
||||
public partial class RoutingService
|
||||
{
|
||||
public async Task DeleteRoutingItems()
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
db.DeleteRoutingItems();
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task DeleteRoutingProfiles()
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
db.DeleteRoutingProfiles();
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +1,23 @@
|
|||
using BotSharp.Abstraction.Repositories;
|
||||
using BotSharp.Abstraction.Repositories.Records;
|
||||
using BotSharp.Abstraction.Routing;
|
||||
using BotSharp.Abstraction.Routing.Models;
|
||||
using System.IO;
|
||||
|
||||
namespace BotSharp.Core.Routing.Services;
|
||||
|
||||
public class RoutingService : IRoutingService
|
||||
public partial class RoutingService : IRoutingService
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly JsonSerializerOptions _options;
|
||||
|
||||
public RoutingService(IServiceProvider service)
|
||||
{
|
||||
_services = service;
|
||||
}
|
||||
public async Task<List<RoutingItem>> CreateRoutingItems(List<RoutingItem> routingItems)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var items = routingItems?.ToList() ?? new List<RoutingItem>();
|
||||
var savedItems = db.CreateRoutingItems(items);
|
||||
return await Task.FromResult(savedItems.ToList());
|
||||
}
|
||||
|
||||
public async Task<List<RoutingProfile>> CreateRoutingProfiles(List<RoutingProfile> routingProfiles)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var profiles = routingProfiles?.ToList() ?? new List<RoutingProfile>();
|
||||
var savedProfiles = db.CreateRoutingProfiles(profiles);
|
||||
return await Task.FromResult(savedProfiles.ToList());
|
||||
}
|
||||
|
||||
public async Task DeleteRoutingItems()
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
db.DeleteRoutingItems();
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task DeleteRoutingProfiles()
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
db.DeleteRoutingProfiles();
|
||||
await Task.CompletedTask;
|
||||
_options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue