| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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;
- namespace GreenTree.Nachtragsmanagement.Web.Controllers
- {
- 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<string[]>()
- };
- var uninstalledPlugins = _pluginFinder.GetPlugins<IPlugin>(LoadPluginsMode.NotInstalledOnly);
- var installedPlugins = _pluginFinder.GetPlugins<IPlugin>(LoadPluginsMode.InstalledOnly);
- if (installedPlugins.Any())
- model.PluginNames.AddRange(new List<string[]>()
- {
- new [] { installedPlugins.First().PluginDescriptor.SystemName, "installed" }
- });
- if (uninstalledPlugins.Any())
- model.PluginNames.AddRange(new List<string[]>()
- {
- 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");
- 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");
- }
- }
- }
|