Updated web ui to razor
This commit is contained in:
71
WebUI_Old/Controllers/HomeController.cs
Normal file
71
WebUI_Old/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using DiscordBotCore.Bot;
|
||||
using DiscordBotCore.PluginManagement.Loading;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ILogger = DiscordBotCore.Logging.ILogger;
|
||||
|
||||
namespace WebUI_OLD.Controllers;
|
||||
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IDiscordBotApplication _discordBotApplication;
|
||||
private readonly IPluginLoader _pluginLoader;
|
||||
|
||||
public HomeController(ILogger logger, IDiscordBotApplication discordBotApplication, IPluginLoader pluginLoader)
|
||||
{
|
||||
_logger = logger;
|
||||
_discordBotApplication = discordBotApplication;
|
||||
_pluginLoader = pluginLoader;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
{
|
||||
_logger.Log("Index page loaded", this);
|
||||
ViewBag.IsRunning = _discordBotApplication.IsReady;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> StartApplication()
|
||||
{
|
||||
if (_discordBotApplication.IsReady)
|
||||
{
|
||||
_logger.Log("Application already started", this);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
await _discordBotApplication.StartAsync();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> StopApplication()
|
||||
{
|
||||
if (!_discordBotApplication.IsReady)
|
||||
{
|
||||
_logger.Log("Application already stopped", this);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
await _discordBotApplication.StopAsync();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public JsonResult GetLogs()
|
||||
{
|
||||
var logText = _logger.GetLogsHistory();
|
||||
var logs = logText.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
|
||||
return Json(logs);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> LoadPlugins()
|
||||
{
|
||||
_logger.Log("Loading plugins", this);
|
||||
await _pluginLoader.LoadPlugins();
|
||||
//_logger.Log("Plugins loaded", this);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user