Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Binders/ExperimentJsonAttribute.cs @ 11813

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

#1888:
HL:

  • Web projects requires different users to interact with hive. The singleton HiveServiceLocator.Instance doesn't allow different users at the same time, resulting in serialization during access of HiveClient methods.

The following changes have been introduced in favor of a parallel use of the HL libs:

  • HiveClient, TaskDownloader and ConcurrentTaskDownloader may now use a different IHiveServiceLocator than HiveServiceLocator.Instance (all methods have appropriate overloads now).
  • The default instance is still HiveServiceLocator.Instance.

Automated Scaling of Instances:

  • Added Scaler project to solution which represents a WorkerRole that scales the slave instances based on the global cpu utilization of all slaves.
  • Scaler is based on WASABi, rules can be adjusted in rulesstore.xml. Basic rule is: if < 45% global cpu utilization => remove an instance; if > 65% cpu => add an instance. Minimum boundary is 1 and maximum boundary is 8 slave instances.
  • Adjusted Slave project to automatically register itself to a SlaveGroup during WebRole startup (can be adjusted in service configuration).

Web-Frontend:

  • Added basic error messages to the dialogs when an ajax call fails.
  • Removed Styling.js from scripts.
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.