[8384] | 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 {
|
---|
[9166] | 9 | public class ScheduleJobModel {
|
---|
| 10 | public int Repetitions { get; set; }
|
---|
| 11 | public string Name { get; set; }
|
---|
| 12 | public string Group { get; set; }
|
---|
| 13 | }
|
---|
[8506] | 14 |
|
---|
[8545] | 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 |
|
---|
[8506] | 30 | public class ProblemParametersModelBinder : IModelBinder {
|
---|
[8384] | 31 | public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
|
---|
[8506] | 32 | var scenario = controllerContext.HttpContext.Session["scenario"] as OptimizationScenario;
|
---|
[8384] | 33 | foreach (var key in controllerContext.RequestContext.HttpContext.Request.Form.AllKeys) {
|
---|
[8506] | 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 | }
|
---|
[9166] | 48 | var param = (from par in scenario.FirstAlgorithm.Problem.Parameters.Items where par.Value.Name == realKey select par).FirstOrDefault();
|
---|
[9062] | 49 | if (param != null && !param.Value.TrySetFromString(realValue)) {
|
---|
[8506] | 50 | bindingContext.ModelState.AddModelError(bindingContext.ModelName, new Exception(string.Format("Unable to parse {0} into destination type {1}", value, param.Type)));
|
---|
| 51 | }
|
---|
[8384] | 52 | }
|
---|
[9166] | 53 | return scenario.FirstAlgorithm.Problem.Parameters;
|
---|
[8384] | 54 | }
|
---|
| 55 | }
|
---|
[8506] | 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);
|
---|
[9166] | 62 | var param = (from par in scenario.FirstAlgorithm.Parameters.Items where par.Value.Name == key select par).FirstOrDefault();
|
---|
[9062] | 63 | if (param != null && !param.Value.TrySetFromString(value.AttemptedValue)) {
|
---|
[8506] | 64 | bindingContext.ModelState.AddModelError(bindingContext.ModelName, new Exception(string.Format("Unable to parse {0} into destination type {1}", value, param.Type)));
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
[9166] | 67 | return scenario.FirstAlgorithm.Parameters;
|
---|
[8506] | 68 | }
|
---|
| 69 | }
|
---|
[8384] | 70 | } |
---|