Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/ExperimentController.cs @ 9305

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

#1888:

  • Added an Update / GetExperiment... methods to the controller for updating and querying experiments.
  • The AlgorithmConverter class now properly converts from/to JSON format.
  • Integrated backbone js as MVC provider for JavaScript + jquery.
  • Added experiment.model.js + experiment.view.js + experiment.controller.js containing the MVC impl. for the Experiment pages.
  • Added new methods to the ExperimentController usable by the backbone js model implementation.
  • Added the experiment dialog from HL 3.3.7 (variate experiment parameters). It's capable of variating the algorithm parameters.
File size: 5.6 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 HeuristicLab.Services.Optimization.Web.Helpers;
8using HeuristicLab.Services.Optimization.ControllerService.Model;
9using System.Web.Security;
10using Mvc3TestApplication.Binders;
11using HeuristicLab.Services.Optimization.ControllerService.Parsers;
12
13namespace HeuristicLab.Services.Optimization.Web.Controllers
14{
15    [Authorize(Roles = "Web User")]
16    public class ExperimentController : Controller
17    {
18        private ControllerServiceHelper ControllerService {
19          get {
20            var helper = new ControllerServiceHelper(Session["pw"] as string);
21            if (!helper.Valid) {
22              Response.Redirect("/Account/Logon?ReturnUrl=%2fExperiment");
23            }
24            return helper;
25          }
26        }
27
28        //
29        // GET: /Experiment/
30
31        public ActionResult Index()
32        {
33          return RedirectToAction("New");
34          /*var model = new ExperimentViewModel();
35          var scenarios = ControllerService.withControllerService<IEnumerable<string>>((service) => {
36            return service.GetOptimizationScenarioNames();
37          });
38          var experiments = ControllerService.withControllerService<IEnumerable<string>>((service) => {
39            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
40            return service.GetExperimentNames(u);
41          });
42          foreach (var experiment in experiments)
43            model.Experiments.Add(experiment);
44          foreach (var scenario in scenarios)
45            model.Scenarios.Add(scenario);
46
47          return View(model);*/
48        }
49
50        public ActionResult New() {
51          return View();
52        }
53
54        public ActionResult NewEdit() {
55          return View();
56        }
57
58        public ActionResult Edit() {
59          var model = new ExperimentViewModel();
60          var experiments = ControllerService.withControllerService<IEnumerable<string>>((service) => {
61            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
62            return service.GetExperimentNames(u);
63          });
64          foreach (var experiment in experiments)
65            model.Experiments.Add(experiment);
66          return View(model);
67        }
68
69        public ActionResult DeleteExperiment(string experiment) {
70          ControllerService.withControllerService<bool>((service) => {
71            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
72            return service.DeleteExperiment(u, experiment);
73          });
74          return RedirectToAction("Edit");
75        }
76
77      #region new experiment methdos
78      [HttpGet]
79      public ActionResult Scenario(string nodeId) {
80        var optimizationScenario = ControllerService.withControllerService<OptimizationScenario>(service => {
81          return service.GetOptimizationScenarioByName(nodeId);
82        });
83        return Content(AlgorithmConverter.ConvertScenarioToJson(optimizationScenario).ToString(), "application/json", System.Text.Encoding.UTF8);
84      }
85
86      [HttpGet]
87      public ActionResult ExperimentList() {
88        var experiments = ControllerService.withControllerService<IEnumerable<Experiment>>(service => {
89          User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
90          return service.GetExperiments(u);
91        });
92        return Content(AlgorithmConverter.ConvertExperimentsToJson(experiments).ToString(), "application/json", System.Text.Encoding.UTF8);
93      }
94
95      [HttpGet]
96      public ActionResult ScenarioList() {
97        var scenarios = ControllerService.withControllerService<IEnumerable<OptimizationScenario>>(service => {
98          User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
99          return service.GetOptimizationScenarios();
100        });
101        return Content(AlgorithmConverter.ConvertScenariosToJson(scenarios).ToString(), "application/json", System.Text.Encoding.UTF8);
102      }
103
104      [HttpPut]
105      public JsonResult Experiment(string nodeId, [ExperimentJson] Experiment exp) {
106        return Json(
107            new {
108              nodeId = ControllerService.withControllerService<string>(service => {
109                User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
110                return service.SaveExperiment(u, exp);
111              })
112            });
113      }
114
115      [HttpPost]
116      public JsonResult Experiment([ExperimentJson] Experiment exp) {
117        return Json(
118            new {
119              nodeId = ControllerService.withControllerService<string>(service => {
120                User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
121                return service.SaveExperiment(u, exp);
122              })
123            });
124      }
125
126
127      [HttpGet]
128      public ActionResult Experiment(string nodeId) {
129        var experiment = ControllerService.withControllerService<Experiment>(service => {
130          User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
131          return service.GetExperimentById(u, nodeId);
132        });
133        var str = AlgorithmConverter.ConvertExperimentToJson(experiment).ToString();
134        return Content(str, "application/json", System.Text.Encoding.UTF8);
135      }
136      #endregion
137    }
138}
Note: See TracBrowser for help on using the repository browser.