2018-07-15 12:31:52 +00:00
|
|
|
|
using BotSharp.Core.Agents;
|
|
|
|
|
|
using BotSharp.Core.Engines;
|
2018-08-03 22:18:40 +00:00
|
|
|
|
using BotSharp.Core.Engines.BotSharp;
|
2018-07-15 12:31:52 +00:00
|
|
|
|
using BotSharp.Core.Models;
|
|
|
|
|
|
using EntityFrameworkCore.BootKit;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2018-07-13 12:21:40 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2018-07-15 12:31:52 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2018-07-13 12:21:40 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.RestApi
|
|
|
|
|
|
{
|
2018-07-15 12:31:52 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Agent
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Route("v1/[controller]/[action]")]
|
2018-07-13 12:21:40 +00:00
|
|
|
|
public class AgentController : ControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Restore a agent from a uploaded zip file
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="agentId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet("{agentId}")]
|
|
|
|
|
|
public ActionResult Restore([FromRoute] String agentId)
|
|
|
|
|
|
{
|
2018-08-03 22:18:40 +00:00
|
|
|
|
var botsHeaderFilePath = Path.Join(AppDomain.CurrentDomain.GetData("DataPath").ToString(), $"DbInitializer{Path.DirectorySeparatorChar}Agents{Path.DirectorySeparatorChar}agents.json");
|
2018-07-15 12:31:52 +00:00
|
|
|
|
var agents = JsonConvert.DeserializeObject<List<AgentImportHeader>>(System.IO.File.ReadAllText(botsHeaderFilePath));
|
|
|
|
|
|
|
2018-08-03 22:18:40 +00:00
|
|
|
|
var rasa = new BotSharpAi();
|
2018-07-15 12:31:52 +00:00
|
|
|
|
var agentHeader = agents.First(x => x.Id == agentId);
|
2018-08-03 22:18:40 +00:00
|
|
|
|
rasa.RestoreAgent<AgentImporterInSebis>(agentHeader);
|
2018-07-15 12:31:52 +00:00
|
|
|
|
|
2018-07-13 12:21:40 +00:00
|
|
|
|
return Ok();
|
|
|
|
|
|
}
|
2018-07-15 12:31:52 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Dump agent
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="agentId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet("{agentId}")]
|
|
|
|
|
|
public ActionResult<Agent> Dump([FromRoute] String agentId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rasa = new RasaAi();
|
|
|
|
|
|
var agent = rasa.LoadAgent(agentId);
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(agent);
|
|
|
|
|
|
}
|
2018-07-13 12:21:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|