using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using HeuristicLab.Services.Optimization.Web.Models; using System.IO; using System.Text; using System.Xml; using HeuristicLab.Services.Optimization.ControllerService; using System.ServiceModel; using System.ServiceModel.Description; using System.Web.Security; using HeuristicLab.Services.Optimization.ControllerService.Model; using HeuristicLab.Services.Optimization.Web.Helpers; namespace HeuristicLab.Services.Optimization.Web.Controllers { [Authorize(Roles = "Web User")] public class AdminController : Controller { private ControllerServiceHelper ControllerService { get { var helper = new ControllerServiceHelper(Session["pw"] as string); if (!helper.Valid) { Response.Redirect("/Account/Logon"); } return helper; } } // // GET: /Admin/ [HttpGet] public ActionResult Index() { var names = ControllerService.withControllerService>((service) => { User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; var scenModel = new List(); var scenarios = service.GetOptimizationScenarioNames(); foreach (var scenario in scenarios) { scenModel.Add(new ScenarioModel() { Exists = service.ExistsVisualExtension(scenario), Scenario = scenario }); } return scenModel; }); return View(names); } [HttpPost] public ActionResult AddScenario(UploadScenario newSecnario) { StreamReader reader = new StreamReader(newSecnario.ScenarioMapper.InputStream); string scenarioMapper = reader.ReadToEnd(); XmlDocument doc = new XmlDocument(); doc.Load(newSecnario.ScenarioXml.InputStream); string scenarioXml; using (var stringWriter = new StringWriter()) using (var xmlTextWriter = XmlWriter.Create(stringWriter)) { doc.WriteTo(xmlTextWriter); xmlTextWriter.Flush(); scenarioXml = stringWriter.GetStringBuilder().ToString(); } var ok = ControllerService.withControllerService((service) => { OptimizationModel model = new OptimizationModel(); User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.AddHiveScenario(u, scenarioXml, scenarioMapper); }); return RedirectToAction("Index"); } [HttpPost] public ActionResult AddVisualExtension(UploadVisualExtension extension) { StreamReader reader = new StreamReader(extension.ScenarioJs.InputStream); string scenarioJs = reader.ReadToEnd(); var ok = ControllerService.withControllerService((service) => { OptimizationModel model = new OptimizationModel(); User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.AddVisualExtension(extension.ScenarioId, scenarioJs); }); return RedirectToAction("Index"); } [HttpPost] public ActionResult DeleteVisualExtension(UploadVisualExtension extension) { var ok = ControllerService.withControllerService((service) => { OptimizationModel model = new OptimizationModel(); User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.DeleteVisualExtension(extension.ScenarioId); }); return RedirectToAction("Index"); } public ActionResult DeleteScenario(string id) { ControllerService.withControllerService((service) => { User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; return service.DeleteHiveScenario(u, id); }); return RedirectToAction("Index"); } } }