Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1888_OaaS/HeuristicLab.Services.Optimization.Web/Controllers/AdminController.cs

Last change on this file was 9395, checked in by fschoepp, 11 years ago

#1888:

  • Added visual extensions (dynamic JavaScript) which will be used to render additional result parameters specific to scenarios (e. g. create a graphical representation of a TSP).
  • Added relationship between jobs and experiments (otherwise, it's not possible to get the job's experiment).
  • Updated Admin page to allow removal/addition of visual extensions.
  • Added back-end logic to store/retrieve/delete visual extensions.
  • Added visual extension functionality to the JavaScript views/controllers (job.*.js).
  • Added tsp.js which is a visual extension for the "Genetic Algorithm - TSP" scenario. It adds a graphical representation of the TSP (just like the C# version does) to the results.
File size: 4.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using HeuristicLab.Services.Optimization.Web.Models;
7using System.IO;
8using System.Text;
9using System.Xml;
10using HeuristicLab.Services.Optimization.ControllerService;
11using System.ServiceModel;
12using System.ServiceModel.Description;
13using System.Web.Security;
14using HeuristicLab.Services.Optimization.ControllerService.Model;
15using HeuristicLab.Services.Optimization.Web.Helpers;
16
17namespace HeuristicLab.Services.Optimization.Web.Controllers
18{
19    [Authorize(Roles = "Web User")]
20    public class AdminController : Controller
21    {
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          }
30        }
31        //
32        // GET: /Admin/
33        [HttpGet]
34        public ActionResult Index()
35        {
36          var names = ControllerService.withControllerService<IEnumerable<ScenarioModel>>((service) => {           
37            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
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;
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
63          var ok = ControllerService.withControllerService<bool>((service) => {
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
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
95        public ActionResult DeleteScenario(string id) {
96          ControllerService.withControllerService<bool>((service) => {           
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}
Note: See TracBrowser for help on using the repository browser.