1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Web;
|
---|
5 | using System.Web.Mvc;
|
---|
6 | using HeuristicLab.Services.Optimization.Web.Models;
|
---|
7 | using System.IO;
|
---|
8 | using System.Text;
|
---|
9 | using System.Xml;
|
---|
10 | using HeuristicLab.Services.Optimization.ControllerService;
|
---|
11 | using System.ServiceModel;
|
---|
12 | using System.ServiceModel.Description;
|
---|
13 | using System.Web.Security;
|
---|
14 | using HeuristicLab.Services.Optimization.ControllerService.Model;
|
---|
15 | using HeuristicLab.Services.Optimization.Web.Helpers;
|
---|
16 |
|
---|
17 | namespace 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 | }
|
---|