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;
|
---|
10 | using Mvc3TestApplication.Binders;
|
---|
11 | using HeuristicLab.Services.Optimization.ControllerService.Parsers;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.Services.Optimization.Web.Controllers
|
---|
14 | {
|
---|
15 | [Authorize(Roles = "Web User")]
|
---|
16 | public class ExperimentController : BaseController
|
---|
17 | {
|
---|
18 | //
|
---|
19 | // GET: /Experiment/
|
---|
20 |
|
---|
21 | public ActionResult Index()
|
---|
22 | {
|
---|
23 | RedirectToLoginIfNecessary("%2fExperiment%2fIndex");
|
---|
24 | return RedirectToAction("New", "Experiment");
|
---|
25 | /*var model = new ExperimentViewModel();
|
---|
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 };
|
---|
31 | return service.GetExperimentNames(u);
|
---|
32 | });
|
---|
33 | foreach (var experiment in experiments)
|
---|
34 | model.Experiments.Add(experiment);
|
---|
35 | foreach (var scenario in scenarios)
|
---|
36 | model.Scenarios.Add(scenario);
|
---|
37 |
|
---|
38 | return View(model);*/
|
---|
39 | }
|
---|
40 |
|
---|
41 | public ActionResult New() {
|
---|
42 | RedirectToLoginIfNecessary("%2fExperiment%2fNew");
|
---|
43 | return View();
|
---|
44 | }
|
---|
45 |
|
---|
46 | public ActionResult NewEdit() {
|
---|
47 | RedirectToLoginIfNecessary("%2fExperiment%2fNewEdit");
|
---|
48 | return View();
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
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 };
|
---|
56 | return service.GetExperimentNames(u);
|
---|
57 | });
|
---|
58 | foreach (var experiment in experiments)
|
---|
59 | model.Experiments.Add(experiment);
|
---|
60 | return View(model);
|
---|
61 | }
|
---|
62 |
|
---|
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 };
|
---|
76 | return service.GetExperiments(u, namesOnly: true);
|
---|
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 => {
|
---|
95 | User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
|
---|
96 | return service.SaveExperiment(u, exp);
|
---|
97 | })
|
---|
98 | });
|
---|
99 | }
|
---|
100 |
|
---|
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 | })
|
---|
109 | });
|
---|
110 | }
|
---|
111 |
|
---|
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 | }
|
---|
121 |
|
---|
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
|
---|
132 | }
|
---|
133 | }
|
---|