Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1888:
Backend changes:

  • Simplified job state detection (only one hive call will be made to detect all states now, instead of one additional call per job)
  • Reorganized classes (moved model classes into Model folder)

Website changes:

  • Website now heavily uses JavaScript to achieve better user experience
  • JavaScript degrades gracefully, except for plots
  • Tables: Added jquery-datatable-plugin to extend tables (pagination + search functionality)
  • OaaS-Website now uses the design of the HL websites (found in WebApplication branch)
  • Added jqplot to render zoomable line plots for HL-Datatables
  • Styling.js: Plots will be generated by using an ajax call; additional jquery-styling occurs within this file.
  • Added jquery-ui-1.9.2 which is capable of handling/rendering tabs, accordions and resizers.
File size: 5.6 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;
12
13namespace HeuristicLab.Services.Optimization.Web.Controllers
14{
15    [Authorize(Roles="Web User")]
16    public class OptimizationController : Controller
17    {
18      public const string DEFAULT_CONTROLLER_ENDPOINT = "WSHttpBinding_IControllerService";
19
20      public delegate T ControllerServiceDelegate<T>(IControllerService service);
21      public delegate void ControllerServiceDelegate(IControllerService service);
22
23      public T withControllerService<T>(ControllerServiceDelegate<T> del) {
24        if (Session["pw"] == null)
25          Response.Redirect("/Account/Logon");
26
27        using (var cf = new ChannelFactory<IControllerService>(OptimizationController.DEFAULT_CONTROLLER_ENDPOINT)) {
28          var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>();
29          credentialBehaviour.UserName.UserName = Membership.GetUser().UserName;
30          credentialBehaviour.UserName.Password = Session["pw"] as string;
31          var controllerProxy = cf.CreateChannel();
32          return del(controllerProxy);
33        }
34      }
35
36      public void withControllerService(ControllerServiceDelegate del) {
37        if (Session["pw"] == null)
38          Response.Redirect("/Account/Logon");
39
40        using (var cf = new ChannelFactory<IControllerService>(OptimizationController.DEFAULT_CONTROLLER_ENDPOINT)) {         
41          var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>();
42          credentialBehaviour.UserName.UserName = Membership.GetUser().UserName;
43          credentialBehaviour.UserName.Password = Session["pw"] as string;         
44          var controllerProxy = cf.CreateChannel();
45          del(controllerProxy);
46        }
47      }
48        //
49        // GET: /Optimization/       
50
51        public ActionResult Index()
52        {
53          var optModel = withControllerService<OptimizationModel>((service) => {
54            OptimizationModel model = new OptimizationModel();
55            model.Scenarios = service.GetOptimizationScenarios();
56            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
57            model.Jobs = service.GetJobs(u);
58            return model;
59          });
60          return View(optModel);
61        }
62
63        public ActionResult ProblemParameters(string scenario) {
64          var optScenario = withControllerService<OptimizationScenario>((service) => {
65            return service.GetOptimizationScenarioByName(scenario);
66          });
67          Session["scenario"] = optScenario;
68          return View(optScenario.InputParameters);
69        }
70
71        public ActionResult JobDetails(string jobId) {
72          Job job = withControllerService<Job>((service) => {
73            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
74            return service.GetJob(u, jobId);
75          });
76          var runs = withControllerService<IList<Run>>((service) => {
77            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
78            return service.GetJobResults(u, jobId);
79          });
80          JobDetailsModel jdm = new JobDetailsModel() { Job = job, Runs = runs };
81          Session["jobDetails"] = jdm;
82          return View(jdm);
83        }
84
85        [HttpPost]
86        public ActionResult JobDetails(Job job) {
87          withControllerService((service) => {
88            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
89            service.DeleteJob(u, job.Id);
90          });
91          return RedirectToAction("Index");
92        }
93
94        [HttpPost]
95        public ActionResult ProblemParameters(InputParameters parameters) {
96          if (ModelState.IsValid) {
97            return RedirectToAction("AlgorithmParameters", parameters);
98          }
99          return View(parameters);       
100        }
101
102        public ActionResult AlgorithmParameters() {
103          return View((Session["scenario"] as OptimizationScenario).AlgorithmParameters);
104        }
105
106        [HttpPost]
107        public ActionResult AlgorithmParameters(AlgorithmParameters parameters) {
108          if (ModelState.IsValid) {
109            return RedirectToAction("ScheduleJob");
110          }
111          return View(parameters);
112        }
113
114        public ActionResult ScheduleJob() {
115          return View(Session["scenario"]);
116        }
117
118        [HttpPost]
119        public ActionResult ScheduleJob(OptimizationScenario scenario) {
120          using (var cf = new ChannelFactory<IControllerService>(OptimizationController.DEFAULT_CONTROLLER_ENDPOINT)) {
121            var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>();
122            credentialBehaviour.UserName.UserName = Membership.GetUser().UserName;
123            credentialBehaviour.UserName.Password = Session["pw"] as string;
124            var controllerProxy = cf.CreateChannel();
125            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
126            controllerProxy.ScheduleOptimizationScenario(u, Session["scenario"] as OptimizationScenario);
127          }
128          return RedirectToAction("Index");
129        }
130    }
131}
Note: See TracBrowser for help on using the repository browser.