Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Models/OptimizationModels.cs @ 8545

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

#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)
File size: 2.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using HeuristicLab.Services.Optimization.ControllerService.Model;
7
8namespace HeuristicLab.Services.Optimization.Web.Models {
9
10  public class OptimizationModel {
11    public IEnumerable<OptimizationScenario> Scenarios { get; set; }
12    public IEnumerable<Job> Jobs { get; set; }
13    public Operation Operation { get; set; }
14  }
15
16  public class JobDetailsModel {
17    public IList<Run> Runs { get; set; }
18    public Job Job { get; set; }
19  }
20
21  public enum Operation {
22    DeleteJob
23  }
24
25  public class ProblemParametersModelBinder : IModelBinder {
26    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
27      var scenario = controllerContext.HttpContext.Session["scenario"] as OptimizationScenario;
28      foreach (var key in controllerContext.RequestContext.HttpContext.Request.Form.AllKeys) {
29        var value = bindingContext.ValueProvider.GetValue(key);
30        string realKey = key;
31        string realValue = value.AttemptedValue;
32
33        if (key.Contains("_")) {
34          var tableEntry = key.Split('_');
35          realKey = tableEntry[0];
36          //var param2 = (from par in scenario.InputParameters.Items where par.Name == tableEntry[0] select par).FirstOrDefault();
37          realValue = "";
38          for (int i = 1; i < tableEntry.Length; i++) {
39            realValue += tableEntry[i] + ":";
40          }
41          realValue += value.AttemptedValue;
42        }
43        var param = (from par in scenario.InputParameters.Items where par.Value.Name == realKey select par).FirstOrDefault();
44        if (!param.Value.TrySetFromString(realValue)) {
45          bindingContext.ModelState.AddModelError(bindingContext.ModelName, new Exception(string.Format("Unable to parse {0} into destination type {1}", value, param.Type)));
46        }
47      }
48      return scenario.InputParameters;
49    }
50  }
51
52  public class AlgorithmParametersModelBinder : IModelBinder {
53    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
54      var scenario = controllerContext.HttpContext.Session["scenario"] as OptimizationScenario;
55      foreach (var key in controllerContext.RequestContext.HttpContext.Request.Form.AllKeys) {
56        var value = bindingContext.ValueProvider.GetValue(key);
57        var param = (from par in scenario.AlgorithmParameters.Items where par.Value.Name == key select par).FirstOrDefault();
58        if (!param.Value.TrySetFromString(value.AttemptedValue)) {
59          bindingContext.ModelState.AddModelError(bindingContext.ModelName, new Exception(string.Format("Unable to parse {0} into destination type {1}", value, param.Type)));
60        }
61      }
62      return scenario.AlgorithmParameters;
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.