- Timestamp:
- 08/30/12 16:09:34 (12 years ago)
- Location:
- branches/OaaS/HeuristicLab.Services.Optimization.Web
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Web
-
Property
svn:ignore
set to
bin
obj
-
Property
svn:ignore
set to
-
branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/OptimizationController.cs
r8506 r8545 9 9 using System.ServiceModel.Description; 10 10 using System.Web.Security; 11 using HeuristicLab.Services.Optimization.Web.Models; 11 12 12 13 namespace HeuristicLab.Services.Optimization.Web.Controllers … … 16 17 { 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 using (var cf = new ChannelFactory<IControllerService>(OptimizationController.DEFAULT_CONTROLLER_ENDPOINT)) { 25 var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>(); 26 credentialBehaviour.UserName.UserName = Membership.GetUser().UserName; 27 credentialBehaviour.UserName.Password = Session["pw"] as string; 28 var controllerProxy = cf.CreateChannel(); 29 return del(controllerProxy); 30 } 31 } 32 33 public void withControllerService(ControllerServiceDelegate del) { 34 using (var cf = new ChannelFactory<IControllerService>(OptimizationController.DEFAULT_CONTROLLER_ENDPOINT)) { 35 var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>(); 36 credentialBehaviour.UserName.UserName = Membership.GetUser().UserName; 37 credentialBehaviour.UserName.Password = Session["pw"] as string; 38 var controllerProxy = cf.CreateChannel(); 39 del(controllerProxy); 40 } 41 } 18 42 // 19 43 // GET: /Optimization/ … … 21 45 public ActionResult Index() 22 46 { 23 IEnumerable<OptimizationScenario> scenarios; 24 using (var cf = new ChannelFactory<IControllerService>(OptimizationController.DEFAULT_CONTROLLER_ENDPOINT)) { 25 var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>(); 26 credentialBehaviour.UserName.UserName = Membership.GetUser().UserName; 27 credentialBehaviour.UserName.Password = Session["pw"] as string; 28 var controllerProxy = cf.CreateChannel(); 29 scenarios = controllerProxy.GetOptimizationScenarios(); 30 } 31 return View(scenarios); 47 var optModel = withControllerService<OptimizationModel>((service) => { 48 OptimizationModel model = new OptimizationModel(); 49 model.Scenarios = service.GetOptimizationScenarios(); 50 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 51 model.Jobs = service.GetJobs(u); 52 return model; 53 }); 54 return View(optModel); 32 55 } 33 56 34 57 public ActionResult ProblemParameters(string scenario) { 35 OptimizationScenario optScenario; 36 using (var cf = new ChannelFactory<IControllerService>(OptimizationController.DEFAULT_CONTROLLER_ENDPOINT)) { 37 var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>(); 38 credentialBehaviour.UserName.UserName = Membership.GetUser().UserName; 39 credentialBehaviour.UserName.Password = Session["pw"] as string; 40 var controllerProxy = cf.CreateChannel(); 41 optScenario = controllerProxy.GetOptimizationScenarioByName(scenario); 42 Session["scenario"] = optScenario; 43 } 58 var optScenario = withControllerService<OptimizationScenario>((service) => { 59 return service.GetOptimizationScenarioByName(scenario); 60 }); 61 Session["scenario"] = optScenario; 44 62 return View(optScenario.InputParameters); 63 } 64 65 public ActionResult JobDetails(string jobId) { 66 Job job = withControllerService<Job>((service) => { 67 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 68 return service.GetJob(u, jobId); 69 }); 70 var runs = withControllerService<IList<Run>>((service) => { 71 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 72 return service.GetJobResults(u, jobId); 73 }); 74 JobDetailsModel jdm = new JobDetailsModel() { Job = job, Runs = runs }; 75 return View(jdm); 76 } 77 78 [HttpPost] 79 public ActionResult JobDetails(Job job) { 80 withControllerService((service) => { 81 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 82 service.DeleteJob(u, job.Id); 83 }); 84 return RedirectToAction("Index"); 45 85 } 46 86 … … 76 116 credentialBehaviour.UserName.Password = Session["pw"] as string; 77 117 var controllerProxy = cf.CreateChannel(); 78 controllerProxy.ScheduleOptimizationScenario(Session["scenario"] as OptimizationScenario); 118 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 119 controllerProxy.ScheduleOptimizationScenario(u, Session["scenario"] as OptimizationScenario); 79 120 } 80 121 return RedirectToAction("Index");
Note: See TracChangeset
for help on using the changeset viewer.