[8958] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Web;
|
---|
| 5 | using System.Web.Mvc;
|
---|
| 6 | using HeuristicLab.Services.Optimization.Web.Models;
|
---|
| 7 | using System.IO;
|
---|
| 8 | using System.Text;
|
---|
| 9 | using System.Xml;
|
---|
| 10 | using HeuristicLab.Services.Optimization.ControllerService;
|
---|
| 11 | using System.ServiceModel;
|
---|
| 12 | using System.ServiceModel.Description;
|
---|
| 13 | using System.Web.Security;
|
---|
| 14 | using HeuristicLab.Services.Optimization.ControllerService.Model;
|
---|
[9215] | 15 | using HeuristicLab.Services.Optimization.Web.Helpers;
|
---|
[8958] | 16 |
|
---|
| 17 | namespace HeuristicLab.Services.Optimization.Web.Controllers
|
---|
| 18 | {
|
---|
| 19 | [Authorize(Roles = "Web User")]
|
---|
| 20 | public class AdminController : Controller
|
---|
| 21 | {
|
---|
[9215] | 22 | private ControllerServiceHelper ControllerService {
|
---|
| 23 | get {
|
---|
| 24 | var helper = new ControllerServiceHelper(Session["pw"] as string);
|
---|
| 25 | if (!helper.Valid) {
|
---|
| 26 | Response.Redirect("/Account/Logon");
|
---|
| 27 | }
|
---|
| 28 | return helper;
|
---|
| 29 | }
|
---|
[8958] | 30 | }
|
---|
| 31 | //
|
---|
| 32 | // GET: /Admin/
|
---|
| 33 | [HttpGet]
|
---|
| 34 | public ActionResult Index()
|
---|
| 35 | {
|
---|
[9395] | 36 | var names = ControllerService.withControllerService<IEnumerable<ScenarioModel>>((service) => {
|
---|
[8958] | 37 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
[9395] | 38 | var scenModel = new List<ScenarioModel>();
|
---|
| 39 | var scenarios = service.GetOptimizationScenarioNames();
|
---|
| 40 | foreach (var scenario in scenarios) {
|
---|
| 41 | scenModel.Add(new ScenarioModel() { Exists = service.ExistsVisualExtension(scenario), Scenario = scenario });
|
---|
| 42 | }
|
---|
| 43 | return scenModel;
|
---|
[8958] | 44 | });
|
---|
| 45 | return View(names);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | [HttpPost]
|
---|
| 49 | public ActionResult AddScenario(UploadScenario newSecnario) {
|
---|
| 50 | StreamReader reader = new StreamReader(newSecnario.ScenarioMapper.InputStream);
|
---|
| 51 | string scenarioMapper = reader.ReadToEnd();
|
---|
| 52 |
|
---|
| 53 | XmlDocument doc = new XmlDocument();
|
---|
| 54 | doc.Load(newSecnario.ScenarioXml.InputStream);
|
---|
| 55 | string scenarioXml;
|
---|
| 56 | using (var stringWriter = new StringWriter())
|
---|
| 57 | using (var xmlTextWriter = XmlWriter.Create(stringWriter)) {
|
---|
| 58 | doc.WriteTo(xmlTextWriter);
|
---|
| 59 | xmlTextWriter.Flush();
|
---|
| 60 | scenarioXml = stringWriter.GetStringBuilder().ToString();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[9215] | 63 | var ok = ControllerService.withControllerService<bool>((service) => {
|
---|
[8958] | 64 | OptimizationModel model = new OptimizationModel();
|
---|
| 65 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
| 66 | return service.AddHiveScenario(u, scenarioXml, scenarioMapper);
|
---|
| 67 | });
|
---|
| 68 |
|
---|
| 69 | return RedirectToAction("Index");
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[9395] | 72 | [HttpPost]
|
---|
| 73 | public ActionResult AddVisualExtension(UploadVisualExtension extension) {
|
---|
| 74 | StreamReader reader = new StreamReader(extension.ScenarioJs.InputStream);
|
---|
| 75 | string scenarioJs = reader.ReadToEnd();
|
---|
| 76 |
|
---|
| 77 | var ok = ControllerService.withControllerService<bool>((service) => {
|
---|
| 78 | OptimizationModel model = new OptimizationModel();
|
---|
| 79 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
| 80 | return service.AddVisualExtension(extension.ScenarioId, scenarioJs);
|
---|
| 81 | });
|
---|
| 82 | return RedirectToAction("Index");
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | [HttpPost]
|
---|
| 86 | public ActionResult DeleteVisualExtension(UploadVisualExtension extension) {
|
---|
| 87 | var ok = ControllerService.withControllerService<bool>((service) => {
|
---|
| 88 | OptimizationModel model = new OptimizationModel();
|
---|
| 89 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
| 90 | return service.DeleteVisualExtension(extension.ScenarioId);
|
---|
| 91 | });
|
---|
| 92 | return RedirectToAction("Index");
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[8958] | 95 | public ActionResult DeleteScenario(string id) {
|
---|
[9215] | 96 | ControllerService.withControllerService<bool>((service) => {
|
---|
[8958] | 97 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
| 98 | return service.DeleteHiveScenario(u, id);
|
---|
| 99 | });
|
---|
| 100 | return RedirectToAction("Index");
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | }
|
---|
| 104 | }
|
---|