1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Web;
|
---|
5 | using System.Web.Mvc;
|
---|
6 | using HeuristicLab.Services.Optimization.ControllerService.Model;
|
---|
7 |
|
---|
8 | namespace 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 != null && !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 != null && !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 | } |
---|