- Timestamp:
- 02/11/13 10:15:52 (12 years ago)
- Location:
- branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/AdminController.cs ¶
r8958 r9215 13 13 using System.Web.Security; 14 14 using HeuristicLab.Services.Optimization.ControllerService.Model; 15 using HeuristicLab.Services.Optimization.Web.Helpers; 15 16 16 17 namespace HeuristicLab.Services.Optimization.Web.Controllers … … 19 20 public class AdminController : Controller 20 21 { 21 public delegate T ControllerServiceDelegate<T>(IControllerService service); 22 public delegate void ControllerServiceDelegate(IControllerService service); 23 24 public T withControllerService<T>(ControllerServiceDelegate<T> del) { 25 using (var cf = new ChannelFactory<IControllerService>(OptimizationController.DEFAULT_CONTROLLER_ENDPOINT)) { 26 var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>(); 27 credentialBehaviour.UserName.UserName = Membership.GetUser().UserName; 28 credentialBehaviour.UserName.Password = Session["pw"] as string; 29 var controllerProxy = cf.CreateChannel(); 30 return del(controllerProxy); 22 private ControllerServiceHelper ControllerService { 23 get { 24 var helper = new ControllerServiceHelper(Session["pw"] as string); 25 if (!helper.Valid) { 26 Response.Redirect("/Account/Logon"); 27 } 28 return helper; 29 } 31 30 } 32 }33 34 public void withControllerService(ControllerServiceDelegate del) {35 using (var cf = new ChannelFactory<IControllerService>(OptimizationController.DEFAULT_CONTROLLER_ENDPOINT)) {36 var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>();37 credentialBehaviour.UserName.UserName = Membership.GetUser().UserName;38 credentialBehaviour.UserName.Password = Session["pw"] as string;39 var controllerProxy = cf.CreateChannel();40 del(controllerProxy);41 }42 }43 31 // 44 32 // GET: /Admin/ … … 46 34 public ActionResult Index() 47 35 { 48 var names = withControllerService<IEnumerable<string>>((service) => {36 var names = ControllerService.withControllerService<IEnumerable<string>>((service) => { 49 37 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 50 38 return service.GetOptimizationScenarioNames(); … … 68 56 } 69 57 70 var ok = withControllerService<bool>((service) => {58 var ok = ControllerService.withControllerService<bool>((service) => { 71 59 OptimizationModel model = new OptimizationModel(); 72 60 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; … … 78 66 79 67 public ActionResult DeleteScenario(string id) { 80 withControllerService<bool>((service) => {68 ControllerService.withControllerService<bool>((service) => { 81 69 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 82 70 return service.DeleteHiveScenario(u, id); -
TabularUnified branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/OptimizationController.cs ¶
r9166 r9215 11 11 using HeuristicLab.Services.Optimization.Web.Models; 12 12 using HeuristicLab.Services.Optimization.ControllerService.General; 13 using HeuristicLab.Services.Optimization.Web.Helpers; 13 14 14 15 namespace HeuristicLab.Services.Optimization.Web.Controllers … … 16 17 [Authorize(Roles="Web User")] 17 18 public class OptimizationController : Controller 18 { 19 public static readonly string DEFAULT_CONTROLLER_ENDPOINT = Configuration.ControllerEndpointName; 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 } 20 29 21 public delegate T ControllerServiceDelegate<T>(IControllerService service);22 public delegate void ControllerServiceDelegate(IControllerService service);23 24 public T withControllerService<T>(ControllerServiceDelegate<T> del) {25 if (Session["pw"] == null)26 Response.Redirect("/Account/Logon");27 28 using (var cf = new ChannelFactory<IControllerService>(DEFAULT_CONTROLLER_ENDPOINT)) {29 var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>();30 credentialBehaviour.UserName.UserName = Membership.GetUser().UserName;31 credentialBehaviour.UserName.Password = Session["pw"] as string;32 var controllerProxy = cf.CreateChannel();33 return del(controllerProxy);34 }35 }36 37 public void withControllerService(ControllerServiceDelegate del) {38 if (Session["pw"] == null)39 Response.Redirect("/Account/Logon");40 41 using (var cf = new ChannelFactory<IControllerService>(DEFAULT_CONTROLLER_ENDPOINT)) {42 var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>();43 credentialBehaviour.UserName.UserName = Membership.GetUser().UserName;44 credentialBehaviour.UserName.Password = Session["pw"] as string;45 var controllerProxy = cf.CreateChannel();46 del(controllerProxy);47 }48 }49 30 // 50 // GET: /Optimization/ 51 31 // GET: /Optimization/ 52 32 public ActionResult Index() 53 33 { 54 var optModel = withControllerService<OptimizationModel>((service) => {34 var optModel = ControllerService.withControllerService<OptimizationModel>((service) => { 55 35 OptimizationModel model = new OptimizationModel(); 56 36 model.Scenarios = service.GetOptimizationScenarios(); … … 58 38 model.Jobs = service.GetJobs(u); 59 39 return model; 60 }); 40 }); 61 41 return View(optModel); 62 42 } 63 43 64 44 public ActionResult ProblemParameters(string scenario) { 65 var optScenario = withControllerService<OptimizationScenario>((service) => {45 var optScenario = ControllerService.withControllerService<OptimizationScenario>((service) => { 66 46 return service.GetOptimizationScenarioByName(scenario); 67 47 }); … … 77 57 78 58 public ActionResult JobDetails(string jobId) { 79 Job job = withControllerService<Job>((service) => {59 Job job = ControllerService.withControllerService<Job>((service) => { 80 60 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 81 61 return service.GetJob(u, jobId); 82 62 }); 83 var runs = withControllerService<IList<Run>>((service) => {63 var runs = ControllerService.withControllerService<IList<Run>>((service) => { 84 64 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 85 65 return service.GetJobResults(u, jobId); … … 92 72 [HttpPost] 93 73 public ActionResult JobDetails(Job job) { 94 withControllerService((service) => {74 ControllerService.withControllerService<bool>((service) => { 95 75 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 96 service.DeleteJob(u, job.Id);76 return service.DeleteJob(u, job.Id); 97 77 }); 98 78 return RedirectToAction("Index"); … … 125 105 [HttpPost] 126 106 public ActionResult ScheduleJob(ScheduleJobModel jobModel) { 127 using (var cf = new ChannelFactory<IControllerService>(OptimizationController.DEFAULT_CONTROLLER_ENDPOINT)) { 128 var credentialBehaviour = cf.Endpoint.Behaviors.Find<ClientCredentials>(); 129 credentialBehaviour.UserName.UserName = Membership.GetUser().UserName; 130 credentialBehaviour.UserName.Password = Session["pw"] as string; 131 var controllerProxy = cf.CreateChannel(); 107 var success = ControllerService.withControllerService<bool>((service) => { 132 108 User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string }; 133 109 var scenario = Session["scenario"] as OptimizationScenario; 134 110 var details = new JobExecutionDetails() { Group = jobModel.Group, JobTitle = jobModel.Name, Repititions = jobModel.Repetitions }; 135 controllerProxy.ScheduleOptimizationScenario(u, scenario, details);136 } 111 return service.ScheduleOptimizationScenario(u, scenario, details); 112 }); 137 113 return RedirectToAction("Index"); 138 114 }
Note: See TracChangeset
for help on using the changeset viewer.