Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Binders/AlgorithmJsonAttribute.cs @ 9311

Last change on this file since 9311 was 9305, checked in by fschoepp, 11 years ago

#1888:

  • Added an Update / GetExperiment... methods to the controller for updating and querying experiments.
  • The AlgorithmConverter class now properly converts from/to JSON format.
  • Integrated backbone js as MVC provider for JavaScript + jquery.
  • Added experiment.model.js + experiment.view.js + experiment.controller.js containing the MVC impl. for the Experiment pages.
  • Added new methods to the ExperimentController usable by the backbone js model implementation.
  • Added the experiment dialog from HL 3.3.7 (variate experiment parameters). It's capable of variating the algorithm parameters.
File size: 1.3 KB
Line 
1// http://blog.duc.as/2011/06/07/making-mvc-3-a-little-more-dynamic/
2
3using System;
4using System.Collections.Generic;
5using System.Linq;
6using System.Web;
7using System.Web.Mvc;
8using System.IO;
9using System.Web.Helpers;
10using HeuristicLab.Services.Optimization.ControllerService.Model;
11using HeuristicLab.Services.Optimization.ControllerService.Parsers;
12
13namespace Mvc3TestApplication.Binders
14{
15  public class ExperimentJsonAttribute : CustomModelBinderAttribute {
16    public override IModelBinder GetBinder() {
17      return new ExperimentJsonBinder();
18    }
19  }
20
21  public class ExperimentJsonBinder : IModelBinder {
22    public ExperimentJsonBinder() {
23    }
24
25    public object BindModel(ControllerContext controllerCtx, ModelBindingContext bindingCtx) {
26      var contentType = controllerCtx.HttpContext.Request.ContentType;
27      if (!contentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
28        return null;
29
30      string body;
31      using (var stream = controllerCtx.HttpContext.Request.InputStream) {
32        stream.Seek(0, System.IO.SeekOrigin.Begin);
33        using (var reader = new StreamReader(stream))
34          body = reader.ReadToEnd();
35      }
36      if (string.IsNullOrEmpty(body)) return null;
37      return AlgorithmConverter.ConvertJsonToExperiment(body);
38    }
39
40
41  }
42}
Note: See TracBrowser for help on using the repository browser.