[9215] | 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 HeuristicLab.Services.Optimization.Web.Helpers;
|
---|
| 8 | using HeuristicLab.Services.Optimization.ControllerService.Model;
|
---|
| 9 | using System.Web.Security;
|
---|
[9227] | 10 | using Mvc3TestApplication.Binders;
|
---|
| 11 | using HeuristicLab.Services.Optimization.ControllerService.Parsers;
|
---|
[9215] | 12 |
|
---|
| 13 | namespace HeuristicLab.Services.Optimization.Web.Controllers
|
---|
| 14 | {
|
---|
| 15 | [Authorize(Roles = "Web User")]
|
---|
[9324] | 16 | public class ExperimentController : BaseController
|
---|
[9215] | 17 | {
|
---|
| 18 | //
|
---|
| 19 | // GET: /Experiment/
|
---|
| 20 |
|
---|
| 21 | public ActionResult Index()
|
---|
| 22 | {
|
---|
[9324] | 23 | RedirectToLoginIfNecessary("%2fExperiment%2fIndex");
|
---|
| 24 | return RedirectToAction("New", "Experiment");
|
---|
[9305] | 25 | /*var model = new ExperimentViewModel();
|
---|
[9215] | 26 | var scenarios = ControllerService.withControllerService<IEnumerable<string>>((service) => {
|
---|
| 27 | return service.GetOptimizationScenarioNames();
|
---|
| 28 | });
|
---|
| 29 | var experiments = ControllerService.withControllerService<IEnumerable<string>>((service) => {
|
---|
| 30 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
[9305] | 31 | return service.GetExperimentNames(u);
|
---|
[9215] | 32 | });
|
---|
| 33 | foreach (var experiment in experiments)
|
---|
| 34 | model.Experiments.Add(experiment);
|
---|
| 35 | foreach (var scenario in scenarios)
|
---|
| 36 | model.Scenarios.Add(scenario);
|
---|
[9227] | 37 |
|
---|
[9305] | 38 | return View(model);*/
|
---|
[9215] | 39 | }
|
---|
| 40 |
|
---|
[9227] | 41 | public ActionResult New() {
|
---|
[9324] | 42 | RedirectToLoginIfNecessary("%2fExperiment%2fNew");
|
---|
[9305] | 43 | return View();
|
---|
[9227] | 44 | }
|
---|
| 45 |
|
---|
[9305] | 46 | public ActionResult NewEdit() {
|
---|
[9324] | 47 | RedirectToLoginIfNecessary("%2fExperiment%2fNewEdit");
|
---|
[9305] | 48 | return View();
|
---|
[9215] | 49 | }
|
---|
| 50 |
|
---|
[9324] | 51 |
|
---|
[9215] | 52 | public ActionResult Edit() {
|
---|
| 53 | var model = new ExperimentViewModel();
|
---|
| 54 | var experiments = ControllerService.withControllerService<IEnumerable<string>>((service) => {
|
---|
| 55 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
[9305] | 56 | return service.GetExperimentNames(u);
|
---|
[9215] | 57 | });
|
---|
| 58 | foreach (var experiment in experiments)
|
---|
| 59 | model.Experiments.Add(experiment);
|
---|
| 60 | return View(model);
|
---|
[9324] | 61 | }
|
---|
[9215] | 62 |
|
---|
[9305] | 63 | #region new experiment methdos
|
---|
| 64 | [HttpGet]
|
---|
| 65 | public ActionResult Scenario(string nodeId) {
|
---|
| 66 | var optimizationScenario = ControllerService.withControllerService<OptimizationScenario>(service => {
|
---|
| 67 | return service.GetOptimizationScenarioByName(nodeId);
|
---|
| 68 | });
|
---|
| 69 | return Content(AlgorithmConverter.ConvertScenarioToJson(optimizationScenario).ToString(), "application/json", System.Text.Encoding.UTF8);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | [HttpGet]
|
---|
| 73 | public ActionResult ExperimentList() {
|
---|
| 74 | var experiments = ControllerService.withControllerService<IEnumerable<Experiment>>(service => {
|
---|
| 75 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
[9324] | 76 | return service.GetExperiments(u, namesOnly: true);
|
---|
[9305] | 77 | });
|
---|
| 78 | return Content(AlgorithmConverter.ConvertExperimentsToJson(experiments).ToString(), "application/json", System.Text.Encoding.UTF8);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | [HttpGet]
|
---|
| 82 | public ActionResult ScenarioList() {
|
---|
| 83 | var scenarios = ControllerService.withControllerService<IEnumerable<OptimizationScenario>>(service => {
|
---|
| 84 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
| 85 | return service.GetOptimizationScenarios();
|
---|
| 86 | });
|
---|
| 87 | return Content(AlgorithmConverter.ConvertScenariosToJson(scenarios).ToString(), "application/json", System.Text.Encoding.UTF8);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | [HttpPut]
|
---|
| 91 | public JsonResult Experiment(string nodeId, [ExperimentJson] Experiment exp) {
|
---|
| 92 | return Json(
|
---|
| 93 | new {
|
---|
| 94 | nodeId = ControllerService.withControllerService<string>(service => {
|
---|
[9227] | 95 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
[9305] | 96 | return service.SaveExperiment(u, exp);
|
---|
[9227] | 97 | })
|
---|
| 98 | });
|
---|
[9305] | 99 | }
|
---|
[9227] | 100 |
|
---|
[9305] | 101 | [HttpPost]
|
---|
| 102 | public JsonResult Experiment([ExperimentJson] Experiment exp) {
|
---|
| 103 | return Json(
|
---|
| 104 | new {
|
---|
| 105 | nodeId = ControllerService.withControllerService<string>(service => {
|
---|
| 106 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
| 107 | return service.SaveExperiment(u, exp);
|
---|
| 108 | })
|
---|
[9227] | 109 | });
|
---|
[9305] | 110 | }
|
---|
[9227] | 111 |
|
---|
[9324] | 112 | [HttpDelete]
|
---|
| 113 | [ActionName("Experiment")]
|
---|
| 114 | public JsonResult DeleteExperiment(string nodeId) {
|
---|
| 115 | var isExperimentDeleted = ControllerService.withControllerService<bool>(service => {
|
---|
| 116 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
| 117 | return service.DeleteExperiment(u, nodeId);
|
---|
| 118 | });
|
---|
| 119 | return Json(isExperimentDeleted, JsonRequestBehavior.DenyGet);
|
---|
| 120 | }
|
---|
[9227] | 121 |
|
---|
[9305] | 122 | [HttpGet]
|
---|
| 123 | public ActionResult Experiment(string nodeId) {
|
---|
| 124 | var experiment = ControllerService.withControllerService<Experiment>(service => {
|
---|
| 125 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
| 126 | return service.GetExperimentById(u, nodeId);
|
---|
| 127 | });
|
---|
| 128 | var str = AlgorithmConverter.ConvertExperimentToJson(experiment).ToString();
|
---|
| 129 | return Content(str, "application/json", System.Text.Encoding.UTF8);
|
---|
| 130 | }
|
---|
| 131 | #endregion
|
---|
[9215] | 132 | }
|
---|
| 133 | }
|
---|