Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/30/12 16:09:34 (12 years ago)
Author:
fschoepp
Message:

#1888:

  • Controller is now capable of gathering Hive Jobs
  • Hive Jobs will be mapped to independent Job-Class (shared between Controller and Frontend)
  • HiveScenarioManager is capable of gathering Hive Jobs + their results
  • Job Results will be mapped to string properties
  • Frontend renders all Results after opening the job details
  • Misc: Frontend now passes User-object to Controller so that it is able to connect to the Hive Service (hardcoded values removed)
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
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/OptimizationController.cs

    r8506 r8545  
    99using System.ServiceModel.Description;
    1010using System.Web.Security;
     11using HeuristicLab.Services.Optimization.Web.Models;
    1112
    1213namespace HeuristicLab.Services.Optimization.Web.Controllers
     
    1617    {
    1718      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      }
    1842        //
    1943        // GET: /Optimization/       
     
    2145        public ActionResult Index()
    2246        {
    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);
    3255        }
    3356
    3457        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;
    4462          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");
    4585        }
    4686
     
    76116            credentialBehaviour.UserName.Password = Session["pw"] as string;
    77117            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);
    79120          }
    80121          return RedirectToAction("Index");
Note: See TracChangeset for help on using the changeset viewer.