- Timestamp:
- 08/20/12 13:00:30 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Web/Models/OptimizationModels.cs
r8384 r8506 7 7 8 8 namespace HeuristicLab.Services.Optimization.Web.Models { 9 public class OptimizationModelBinder : IModelBinder { 9 10 public class ProblemParametersModelBinder : IModelBinder { 10 11 public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { 11 var scenario = new Optimization.ControllerService.Model.OptimizationScenario();12 var scenario = controllerContext.HttpContext.Session["scenario"] as OptimizationScenario; 12 13 foreach (var key in controllerContext.RequestContext.HttpContext.Request.Form.AllKeys) { 13 var value = bindingContext.ValueProvider.GetValue(key); 14 scenario.InputParameters.Add(new HeuristicLab.Services.Optimization.ControllerService.Model.Parameter() { }); 14 var value = bindingContext.ValueProvider.GetValue(key); 15 string realKey = key; 16 string realValue = value.AttemptedValue; 17 18 if (key.Contains("_")) { 19 var tableEntry = key.Split('_'); 20 realKey = tableEntry[0]; 21 //var param2 = (from par in scenario.InputParameters.Items where par.Name == tableEntry[0] select par).FirstOrDefault(); 22 realValue = ""; 23 for (int i = 1; i < tableEntry.Length; i++) { 24 realValue += tableEntry[i] + ":"; 25 } 26 realValue += value.AttemptedValue; 27 } 28 var param = (from par in scenario.InputParameters.Items where par.Value.Name == realKey select par).FirstOrDefault(); 29 if (!param.Value.TrySetFromString(realValue)) { 30 bindingContext.ModelState.AddModelError(bindingContext.ModelName, new Exception(string.Format("Unable to parse {0} into destination type {1}", value, param.Type))); 31 } 15 32 } 16 return new Optimization.ControllerService.Model.OptimizationScenario(); 33 return scenario.InputParameters; 34 } 35 } 36 37 public class AlgorithmParametersModelBinder : IModelBinder { 38 public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { 39 var scenario = controllerContext.HttpContext.Session["scenario"] as OptimizationScenario; 40 foreach (var key in controllerContext.RequestContext.HttpContext.Request.Form.AllKeys) { 41 var value = bindingContext.ValueProvider.GetValue(key); 42 var param = (from par in scenario.AlgorithmParameters.Items where par.Value.Name == key select par).FirstOrDefault(); 43 if (!param.Value.TrySetFromString(value.AttemptedValue)) { 44 bindingContext.ModelState.AddModelError(bindingContext.ModelName, new Exception(string.Format("Unable to parse {0} into destination type {1}", value, param.Type))); 45 } 46 } 47 return scenario.AlgorithmParameters; 17 48 } 18 49 }
Note: See TracChangeset
for help on using the changeset viewer.