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 | public class ScheduleJobModel {
|
---|
10 | public int Repetitions { get; set; }
|
---|
11 | public string Name { get; set; }
|
---|
12 | public string Group { get; set; }
|
---|
13 | }
|
---|
14 |
|
---|
15 | public class OptimizationModel {
|
---|
16 | public IEnumerable<OptimizationScenario> Scenarios { get; set; }
|
---|
17 | public IEnumerable<Job> Jobs { get; set; }
|
---|
18 | public Operation Operation { get; set; }
|
---|
19 | }
|
---|
20 |
|
---|
21 | public class JobDetailsModel {
|
---|
22 | public IList<Run> Runs { get; set; }
|
---|
23 | public Job Job { get; set; }
|
---|
24 | }
|
---|
25 |
|
---|
26 | public enum Operation {
|
---|
27 | DeleteJob
|
---|
28 | }
|
---|
29 |
|
---|
30 | public class ProblemParametersModelBinder : IModelBinder {
|
---|
31 | public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
|
---|
32 | var scenario = controllerContext.HttpContext.Session["scenario"] as OptimizationScenario;
|
---|
33 | foreach (var key in controllerContext.RequestContext.HttpContext.Request.Form.AllKeys) {
|
---|
34 | var value = bindingContext.ValueProvider.GetValue(key);
|
---|
35 | string realKey = key;
|
---|
36 | string realValue = value.AttemptedValue;
|
---|
37 |
|
---|
38 | if (key.Contains("_")) {
|
---|
39 | var tableEntry = key.Split('_');
|
---|
40 | realKey = tableEntry[0];
|
---|
41 | //var param2 = (from par in scenario.InputParameters.Items where par.Name == tableEntry[0] select par).FirstOrDefault();
|
---|
42 | realValue = "";
|
---|
43 | for (int i = 1; i < tableEntry.Length; i++) {
|
---|
44 | realValue += tableEntry[i] + ":";
|
---|
45 | }
|
---|
46 | realValue += value.AttemptedValue;
|
---|
47 | }
|
---|
48 | var param = (from par in scenario.FirstAlgorithm.Problem.Parameters.Items where par.Value.Name == realKey select par).FirstOrDefault();
|
---|
49 | if (param != null && !param.Value.TrySetFromString(realValue)) {
|
---|
50 | bindingContext.ModelState.AddModelError(bindingContext.ModelName, new Exception(string.Format("Unable to parse {0} into destination type {1}", value, param.Type)));
|
---|
51 | }
|
---|
52 | }
|
---|
53 | return scenario.FirstAlgorithm.Problem.Parameters;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | public class AlgorithmParametersModelBinder : IModelBinder {
|
---|
58 | public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
|
---|
59 | var scenario = controllerContext.HttpContext.Session["scenario"] as OptimizationScenario;
|
---|
60 | foreach (var key in controllerContext.RequestContext.HttpContext.Request.Form.AllKeys) {
|
---|
61 | var value = bindingContext.ValueProvider.GetValue(key);
|
---|
62 | var param = (from par in scenario.FirstAlgorithm.Parameters.Items where par.Value.Name == key select par).FirstOrDefault();
|
---|
63 | if (param != null && !param.Value.TrySetFromString(value.AttemptedValue)) {
|
---|
64 | bindingContext.ModelState.AddModelError(bindingContext.ModelName, new Exception(string.Format("Unable to parse {0} into destination type {1}", value, param.Type)));
|
---|
65 | }
|
---|
66 | }
|
---|
67 | return scenario.FirstAlgorithm.Parameters;
|
---|
68 | }
|
---|
69 | }
|
---|
70 | } |
---|