using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using GreenTree.Nachtragsmanagement.Services.Configuration; using GreenTree.Nachtragsmanagement.Services.Test; using GreenTree.Nachtragsmanagement.Services.User; using GreenTree.Nachtragsmanagement.Web.Framework; using GreenTree.Nachtragsmanagement.Web.Models.Test; using GreenTree.Nachtragsmanagement.Web.Models.User; using Newtonsoft.Json; using GreenTree.Nachtragsmanagement.Core.Plugins; using GreenTree.Nachtragsmanagement.Core; using GreenTree.Nachtragsmanagement.Web.Framework.Authorization; namespace GreenTree.Nachtragsmanagement.Web.Controllers { [RoleAuthorize("Controller-Home")] public class HomeController : Controller { private readonly IDbRelationService _dbRelationService; private readonly IConfigurationService _configurationService; private readonly IUserService _userService; private readonly IPluginFinder _pluginFinder; private readonly IWebHelper _webHelper; public HomeController( IDbRelationService dbRelationService, IConfigurationService configurationService, IUserService userService, IPluginFinder pluginFinder, IWebHelper webHelper) { _dbRelationService = dbRelationService; _configurationService = configurationService; _userService = userService; _pluginFinder = pluginFinder; _webHelper = webHelper; } // GET: Home public ActionResult Index() { return View("~/Views/Home/Index.cshtml"); } public ActionResult Relations() { var users = _userService.GetAllUsers(); var relations = _dbRelationService.GetRelations(3, DbRelationFormat.Json); var model = new DbRelationModel { UserJson = relations[0], DeviationJson = relations[1], SiteJson = relations[2], AppendixJson = relations[3] }; var configSection = _configurationService.GetCurrentConfiguration(); return View("~/Views/Home/Relations.cshtml", model); } public ActionResult Plugins() { var model = new PluginModel { PluginNames = new List() }; var uninstalledPlugins = _pluginFinder.GetPlugins(LoadPluginsMode.NotInstalledOnly); var installedPlugins = _pluginFinder.GetPlugins(LoadPluginsMode.InstalledOnly); if (installedPlugins.Any()) model.PluginNames.AddRange(new List() { new [] { installedPlugins.First().PluginDescriptor.SystemName, "installed" } }); if (uninstalledPlugins.Any()) model.PluginNames.AddRange(new List() { new [] { uninstalledPlugins.First().PluginDescriptor.SystemName, "uninstalled" } }); return View("~/Views/Home/Plugins.cshtml", model); } [HttpPost] public ActionResult InstallPlugin(string pluginName) { var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName(pluginName, LoadPluginsMode.All); if (pluginDescriptor == null) return RedirectToAction("Plugins"); if (pluginDescriptor.Installed) return RedirectToAction("Plugins"); var routes = System.Web.Routing.RouteTable.Routes; pluginDescriptor.Instance().Install(); _webHelper.RestartAppDomain(); return RedirectToAction("Plugins"); } [HttpPost] public ActionResult UninstallPlugin(string pluginName) { var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName(pluginName, LoadPluginsMode.All); if (pluginDescriptor == null) return RedirectToAction("Plugins"); if (!pluginDescriptor.Installed) return RedirectToAction("Plugins"); pluginDescriptor.Instance().Uninstall(); _webHelper.RestartAppDomain(); return RedirectToAction("Plugins"); } } }