Free cookie consent management tool by TermsFeed Policy Generator

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

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