Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/OptimizationController.cs @ 9311

Last change on this file since 9311 was 9227, checked in by fschoepp, 12 years ago

#1888:

  • Experiments will be saved as JSON elements within the blob store.
  • Added simple model and JSON converters.
  • Backend stores and runs experiments.
  • Updated interfaces to save/read experiments.
  • Added a binding to automatically map incoming JSON ajax requests to experiment models.
  • Added the javascript DatatypeMapper to map parameter inputs to the right html elements and vice versa.
  • Added smartwizard to generate Wizards for creating new experiments (New.cshtml).
File size: 6.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using System.ServiceModel;
7using HeuristicLab.Services.Optimization.ControllerService;
8using HeuristicLab.Services.Optimization.ControllerService.Model;
9using System.ServiceModel.Description;
10using System.Web.Security;
11using HeuristicLab.Services.Optimization.Web.Models;
12using HeuristicLab.Services.Optimization.ControllerService.General;
13using HeuristicLab.Services.Optimization.Web.Helpers;
14
15namespace HeuristicLab.Services.Optimization.Web.Controllers
16{
17    [Authorize(Roles="Web User")]
18    public class OptimizationController : Controller
19    {     
20        private ControllerServiceHelper ControllerService {
21          get {
22            var helper = new ControllerServiceHelper(Session["pw"] as string);
23            if (!helper.Valid) {
24              Response.Redirect("/Account/Logon?ReturnUrl=%2fOptimization");
25            }
26            return helper;
27          }
28        }
29
30        //
31        // GET: /Optimization/   
32        public ActionResult Index()
33        {
34          var optModel = ControllerService.withControllerService<OptimizationModel>((service) => {
35            OptimizationModel model = new OptimizationModel();
36            model.Scenarios = service.GetOptimizationScenarios();
37            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
38            model.Jobs = service.GetJobs(u);
39            return model;
40          });         
41          return View(optModel);
42        }
43
44        public ActionResult ProblemParameters(string scenario) {
45          var optScenario = ControllerService.withControllerService<OptimizationScenario>((service) => {
46            return service.GetOptimizationScenarioByName(scenario);
47          });
48          Session["scenario"] = optScenario;
49          if (optScenario.FirstAlgorithm.Problem == null)
50            return RedirectToAction("AlgorithmParameters");
51          return View(optScenario.FirstAlgorithm.Problem.Parameters);
52        }
53
54        public ActionResult ProblemParameters2() {                   
55          return View("ProblemParameters", (Session["scenario"] as OptimizationScenario).FirstAlgorithm.Problem.Parameters);
56        }
57
58        public ActionResult JobDetails(string jobId) {
59          var model = ControllerService.withControllerService<JobDetailsModel>((service) => {
60            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
61            var job = service.GetJob(u, jobId);
62            var runs = service.GetJobResults(u, jobId);
63            return new JobDetailsModel() { Job = job, Runs = runs };
64          });
65          Session["jobDetails"] = model;
66          return View(model);
67       }
68
69        [HttpPost]
70        public ActionResult JobDetails(Job job) {
71          ControllerService.withControllerService<bool>((service) => {
72            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
73            return service.DeleteJob(u, job.Id);
74          });
75          return RedirectToAction("Index");
76        }
77
78        [HttpPost]
79        public ActionResult ProblemParameters(ProblemParameters parameters) {
80          if (ModelState.IsValid) {
81            return RedirectToAction("AlgorithmParameters", parameters);
82          }
83          return View(parameters);       
84        }
85
86        public ActionResult AlgorithmParameters() {
87          return View((Session["scenario"] as OptimizationScenario).FirstAlgorithm.Parameters);
88        }
89
90        [HttpPost]
91        public ActionResult AlgorithmParameters(AlgorithmParameters parameters) {
92          if (ModelState.IsValid) {
93            return RedirectToAction("ScheduleJob");
94          }
95          return View(parameters);
96        }
97
98        public ActionResult ScheduleJob() {
99          return View(Session["scenario"]);
100        }
101
102        [HttpPost]
103        public ActionResult ScheduleJob(ScheduleJobModel jobModel) {
104          var success = ControllerService.withControllerService<bool>((service) => {
105            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
106            var scenario = Session["scenario"] as OptimizationScenario;
107            var details = new JobExecutionDetails() { Group = jobModel.Group, JobTitle = jobModel.Name, Repititions = jobModel.Repetitions };
108            return service.ScheduleOptimizationScenario(u, scenario, details);
109          });
110          return RedirectToAction("Index");
111        }
112        // TODO: Add unique identifier for algorithm / input parameters
113        public ActionResult AddRow(int id, string paramName) {
114          var os = Session["scenario"] as OptimizationScenario;
115          var parameter = os.FirstAlgorithm.Problem.Parameters.FindByName(paramName);
116          bool inputParam = true;
117          if (parameter == null) {
118            parameter = os.FirstAlgorithm.Parameters.FindByName(paramName);
119            inputParam = false;
120          }
121          var dm = parameter.Value as DecimalMatrix;
122          dm.CopyRow(id);
123          return inputParam ? View("ProblemParameters", os.FirstAlgorithm.Problem.Parameters) : View("AlgorithmParameters", os.FirstAlgorithm.Parameters);
124        }
125
126        public ActionResult DeleteRow(int id, string paramName) {
127          var os = Session["scenario"] as OptimizationScenario;
128          var parameter = os.FirstAlgorithm.Problem.Parameters.FindByName(paramName);
129          bool inputParam = true;
130          if (parameter == null) {
131            parameter = os.FirstAlgorithm.Parameters.FindByName(paramName);
132            inputParam = false;
133          }
134          var dm = parameter.Value as DecimalMatrix;
135          dm.DeleteRow(id);
136          return inputParam ? View("ProblemParameters", os.FirstAlgorithm.Problem.Parameters) : View("AlgorithmParameters", os.FirstAlgorithm.Parameters);
137        }
138    }
139}
Note: See TracBrowser for help on using the repository browser.