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 : 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 | }
|
---|