Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Models/OptimizationModels.cs @ 8506

Last change on this file since 8506 was 8506, checked in by fschoepp, 12 years ago

#1888:

  • Web project now creates custom html for each type we want to enter / display
  • Added endpointConfigurationName to HiveServiceLocator (because Web Project contains more than one endpoint configuration)
  • Removed logging statement from ConfigurationService to prevent exception during failure of loading ConfigurationSettings
  • ApplicationManager: Changed default implementation to WebApplicationManager (instead of LightWeight) for testing purposes within Web Project
  • WebApplicationManager: The application manager which returns plugin descriptors from the currently loaded assemblies (instead of LightweightAppManager)
  • HiveService: Fixed a transaction bug
  • IControllerService: Created a method to dispatch Scenarios to certain IScenarioManager (in this case HiveScenarioManager)
  • Added more mappable types to ControllerModel
  • PlaceholderControllerService dispatches all Scenarios to the HiveScenarioManager
  • Web project now dispatches the scenario to the controller after pressing "Run Job"
File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using HeuristicLab.Services.Optimization.ControllerService.Model;
7
8namespace HeuristicLab.Services.Optimization.Web.Models {
9
10  public class ProblemParametersModelBinder : IModelBinder {
11    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
12      var scenario = controllerContext.HttpContext.Session["scenario"] as OptimizationScenario;
13      foreach (var key in controllerContext.RequestContext.HttpContext.Request.Form.AllKeys) {
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        }
32      }
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;
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.