Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1888:

  • Model: OptimizationScenario may be a tree of algorithms (and problems)
  • Model: Renamed InputParameters to ProblemParameters (as they are the parameters of a problem)
  • Model: Added JobExecutionDetails which contain Repetitions + Group (resource to use)
  • ScenarioParser parses the new XML scenario files
  • Website + Model: You are now able to add/remove rows from a table (no JavaScript involved yet)
  • Website + Controller: Added repetitions (enables batch jobs) and group (resource to use) to OaaS which will be used by the controller to schedule the job
  • Website: Updated templates to use new model structure
  • Website + Scenarios: Added the new algorithm Benchmark Algorithm
  • Controller: Added a singleton to make the (Azure/Mockup)-DAL exchangeable
  • Controller: Added mockup classes for DAL + IScenarioManager
  • Website/Result Page: Line Diagrams will be added via JavaScript, crawling their data using AJAX
  • Website: Most configuration parameters can be set in the ServiceDefinition directly
  • Added a mockup for the Membership classes: These can be used if no network connection is available or if other parts of the app shall be tested
  • Scenarios: Updated TSP mappings to new xsd
File size: 3.0 KB
RevLine 
[8384]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 {
[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}
Note: See TracBrowser for help on using the repository browser.