using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using HeuristicLab.Services.Optimization.ControllerService.Model; namespace HeuristicLab.Services.Optimization.Web.Models { public class ScheduleJobModel { public int Repetitions { get; set; } public string Name { get; set; } public string Group { get; set; } } public class OptimizationModel { public IEnumerable Scenarios { get; set; } public IEnumerable Jobs { get; set; } public Operation Operation { get; set; } } public class JobDetailsModel { public IList Runs { get; set; } public Job Job { get; set; } } public enum Operation { DeleteJob } public class ProblemParametersModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var scenario = controllerContext.HttpContext.Session["scenario"] as OptimizationScenario; foreach (var key in controllerContext.RequestContext.HttpContext.Request.Form.AllKeys) { var value = bindingContext.ValueProvider.GetValue(key); string realKey = key; string realValue = value.AttemptedValue; if (key.Contains("_")) { var tableEntry = key.Split('_'); realKey = tableEntry[0]; //var param2 = (from par in scenario.InputParameters.Items where par.Name == tableEntry[0] select par).FirstOrDefault(); realValue = ""; for (int i = 1; i < tableEntry.Length; i++) { realValue += tableEntry[i] + ":"; } realValue += value.AttemptedValue; } var param = (from par in scenario.FirstAlgorithm.Problem.Parameters.Items where par.Value.Name == realKey select par).FirstOrDefault(); if (param != null && !param.Value.TrySetFromString(realValue)) { bindingContext.ModelState.AddModelError(bindingContext.ModelName, new Exception(string.Format("Unable to parse {0} into destination type {1}", value, param.Type))); } } return scenario.FirstAlgorithm.Problem.Parameters; } } public class AlgorithmParametersModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var scenario = controllerContext.HttpContext.Session["scenario"] as OptimizationScenario; foreach (var key in controllerContext.RequestContext.HttpContext.Request.Form.AllKeys) { var value = bindingContext.ValueProvider.GetValue(key); var param = (from par in scenario.FirstAlgorithm.Parameters.Items where par.Value.Name == key select par).FirstOrDefault(); if (param != null && !param.Value.TrySetFromString(value.AttemptedValue)) { bindingContext.ModelState.AddModelError(bindingContext.ModelName, new Exception(string.Format("Unable to parse {0} into destination type {1}", value, param.Type))); } } return scenario.FirstAlgorithm.Parameters; } } }