Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/AdminController.cs @ 9227

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

#1888:

  • Janitor is now working as expected in Windows Azure
  • Added basic support for experiments (draggable experiments)
  • Added methods to save/read experiments from TableStorage
  • The job status can now be retrieved by using the GetTasks/GetTaskData methods
  • Added a class to convert JSON-objects to Algorithm instances
  • Web page: Added experiment button to navigation
File size: 2.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using HeuristicLab.Services.Optimization.Web.Models;
7using System.IO;
8using System.Text;
9using System.Xml;
10using HeuristicLab.Services.Optimization.ControllerService;
11using System.ServiceModel;
12using System.ServiceModel.Description;
13using System.Web.Security;
14using HeuristicLab.Services.Optimization.ControllerService.Model;
15using HeuristicLab.Services.Optimization.Web.Helpers;
16
17namespace HeuristicLab.Services.Optimization.Web.Controllers
18{
19    [Authorize(Roles = "Web User")]
20    public class AdminController : Controller
21    {
22      private ControllerServiceHelper ControllerService {
23          get {
24            var helper = new ControllerServiceHelper(Session["pw"] as string);
25            if (!helper.Valid) {
26              Response.Redirect("/Account/Logon");
27            }
28            return helper;
29          }
30        }
31        //
32        // GET: /Admin/
33        [HttpGet]
34        public ActionResult Index()
35        {
36          var names = ControllerService.withControllerService<IEnumerable<string>>((service) => {           
37            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
38            return service.GetOptimizationScenarioNames();
39          });
40          return View(names);
41        }
42
43        [HttpPost]
44        public ActionResult AddScenario(UploadScenario newSecnario) {
45          StreamReader reader = new StreamReader(newSecnario.ScenarioMapper.InputStream);
46          string scenarioMapper = reader.ReadToEnd();
47
48          XmlDocument doc = new XmlDocument();
49          doc.Load(newSecnario.ScenarioXml.InputStream);
50          string scenarioXml;
51          using (var stringWriter = new StringWriter())
52          using (var xmlTextWriter = XmlWriter.Create(stringWriter)) {
53            doc.WriteTo(xmlTextWriter);
54            xmlTextWriter.Flush();
55            scenarioXml = stringWriter.GetStringBuilder().ToString();
56          }
57
58          var ok = ControllerService.withControllerService<bool>((service) => {
59            OptimizationModel model = new OptimizationModel();
60            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
61            return service.AddHiveScenario(u, scenarioXml, scenarioMapper);                       
62          });
63
64          return RedirectToAction("Index");
65        }
66
67        public ActionResult DeleteScenario(string id) {
68          ControllerService.withControllerService<bool>((service) => {           
69            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
70            return service.DeleteHiveScenario(u, id);
71          });
72          return RedirectToAction("Index");
73        }
74
75    }
76}
Note: See TracBrowser for help on using the repository browser.