Skip to content

Commit 7c600eb

Browse files
committed
Started working on a new configuration wizard
1 parent a45b2b3 commit 7c600eb

File tree

16 files changed

+516
-25
lines changed

16 files changed

+516
-25
lines changed

src/Server/Coderr.Server.Web/App_Start/CompositionRoot.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Reflection;
44
using System.Web.Http;
55
using System.Web.Mvc;
6+
using codeRR.Server.App.Configuration;
67
using codeRR.Server.App.Core.Accounts.Requests;
78
using codeRR.Server.Infrastructure;
89
using codeRR.Server.Infrastructure.Configuration;
@@ -18,6 +19,11 @@
1819

1920
namespace codeRR.Server.Web
2021
{
22+
public interface IConfiguration<out TConfigType>
23+
{
24+
TConfigType Value { get; }
25+
}
26+
2127
public class CompositionRoot
2228
{
2329
public static IContainer Container;
@@ -42,6 +48,7 @@ public void Build(Action<ContainerRegistrar> action, ConfigurationStore configSt
4248
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
4349
builder.RegisterControllers(Assembly.GetExecutingAssembly());
4450

51+
builder.RegisterService(x => Startup.ConfigurationStore.Load<BaseConfiguration>());
4552
var ioc = builder.Build();
4653

4754
DependencyResolver.SetResolver(new GriffinDependencyResolver(ioc));

src/Server/Coderr.Server.Web/Areas/Installation/Controllers/SetupController.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ namespace codeRR.Server.Web.Areas.Installation.Controllers
1414
[OutputCache(Duration = 0, NoStore = true)]
1515
public class SetupController : Controller
1616
{
17-
private IConnectionFactory _connectionFactory;
18-
19-
public SetupController(IConnectionFactory connectionFactory)
20-
{
21-
_connectionFactory = connectionFactory;
22-
}
17+
private readonly IConnectionFactory _connectionFactory = new Net452ConnectionFactory();
2318

2419
[HttpPost]
2520
[AllowAnonymous]

src/Server/Coderr.Server.Web/Areas/Installation/Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,13 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>@ViewBag.Title - codeRR</title>
77
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
8+
<link rel="stylesheet" href="/Content/bootstrap/bootstrap.min.css"/>
89
@Styles.Render("~/Content/css")
910
@Scripts.Render("~/bundles/modernizr")
1011
@RenderSection("Styles", false)
1112
<meta name="description" content="The description of my page"/>
1213
</head>
1314
<body class="full-width">
14-
<div class="navbar navbar-fixed-top navbar-default">
15-
<div class="container">
16-
<div class="navbar-header">
17-
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
18-
<span class="icon-bar"></span>
19-
<span class="icon-bar"></span>
20-
<span class="icon-bar"></span>
21-
</button>
22-
</div>
23-
<span class="navbar-brand">codeRR - Installation</span>
24-
<div class="navbar-collapse collapse">
25-
<ul class="nav navbar-nav" id="main-navigation"></ul>
26-
<ul class="nav navbar-nav navbar-right settings"></ul>
27-
</div>
28-
29-
</div>
30-
</div>
3115

3216
<div class="container body-content">
3317
<div class="row">
@@ -42,7 +26,7 @@
4226
<hr/>
4327
<footer>
4428
<p>
45-
&copy; 2015 - Gauffin Interactive AB | <a href="mailto:support@coderrapp.com">support@coderrapp.com</a>
29+
&copy; 2017 1TCompany AB | <a href="mailto:support@coderrapp.com">support@coderrapp.com</a>
4630
</p>
4731
</footer>
4832
</div>
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Threading.Tasks;
4+
using System.Web.Mvc;
5+
using codeRR.Server.Api.Core.Applications;
6+
using codeRR.Server.Api.Core.Applications.Commands;
7+
using codeRR.Server.Api.Core.Applications.Queries;
8+
using codeRR.Server.Api.Core.Incidents.Queries;
9+
using codeRR.Server.App.Configuration;
10+
using codeRR.Server.Infrastructure.Security;
11+
using codeRR.Server.Web.Models.Wizard;
12+
using DotNetCqs;
13+
using Newtonsoft.Json;
14+
15+
namespace codeRR.Server.Web.Controllers
16+
{
17+
[Authorize]
18+
public class WizardController : Controller
19+
{
20+
private readonly BaseConfiguration _baseConfiguration;
21+
private readonly IQueryBus _queryBus;
22+
private ICommandBus _cmdBus;
23+
24+
public WizardController(BaseConfiguration baseConfiguration, IQueryBus queryBus, ICommandBus cmdBus)
25+
{
26+
_baseConfiguration = baseConfiguration;
27+
_queryBus = queryBus;
28+
_cmdBus = cmdBus;
29+
}
30+
31+
public async Task<ActionResult> Application()
32+
{
33+
await Init();
34+
return View();
35+
}
36+
37+
[HttpPost]
38+
public async Task<ActionResult> Application(ApplicationViewModel model)
39+
{
40+
await Init();
41+
42+
if (!ModelState.IsValid)
43+
{
44+
return View(model);
45+
}
46+
47+
var app = new CreateApplication(model.Name, TypeOfApplication.DesktopApplication)
48+
{
49+
ApplicationKey = Guid.NewGuid().ToString("N"),
50+
UserId = User.GetAccountId()
51+
};
52+
await _cmdBus.ExecuteAsync(app);
53+
54+
return RedirectToAction("Packages", new {appKey = app.ApplicationKey});
55+
}
56+
57+
58+
public async Task<ActionResult> Packages(int? applicationId, string appKey)
59+
{
60+
await Init();
61+
62+
if (applicationId == null)
63+
{
64+
var appInfo = await _queryBus.QueryAsync(new GetApplicationInfo(appKey));
65+
applicationId = appInfo.Id;
66+
}
67+
68+
var model = new PackagesViewModel {ApplicationId = applicationId.Value};
69+
70+
try
71+
{
72+
var client = new HttpClient { Timeout = TimeSpan.FromSeconds(10) };
73+
var clientsJSON = await client.GetStringAsync("https://coderrapp.com/configure/packages/");
74+
model.Packages = JsonConvert.DeserializeObject<NugetPackage[]>(clientsJSON);
75+
}
76+
catch (Exception)
77+
{
78+
model.ErrorMessage = "Failed to download package information";
79+
}
80+
81+
return View(model);
82+
}
83+
84+
85+
[HttpPost]
86+
public async Task<ActionResult> Packages(PackagesViewModel model)
87+
{
88+
await Init();
89+
try
90+
{
91+
var client = new HttpClient { Timeout = TimeSpan.FromSeconds(10) };
92+
var clientsJSON = await client.GetStringAsync("https://coderrapp.com/configure/packages/");
93+
model.Packages = JsonConvert.DeserializeObject<NugetPackage[]>(clientsJSON);
94+
}
95+
catch (Exception)
96+
{
97+
model.ErrorMessage = "Failed to download package information";
98+
}
99+
100+
if (string.IsNullOrEmpty(model.LibraryName))
101+
{
102+
ModelState.AddModelError("LibraryName", "A package must be selected");
103+
return View(model);
104+
}
105+
106+
return RedirectToAction("ConfigurePackage", new { model.LibraryName, model.ApplicationId });
107+
}
108+
109+
110+
111+
public async Task<ActionResult> ConfigurePackage(ConfigurePackageViewModel model, bool validationFailed = false)
112+
{
113+
await Init();
114+
var query = new GetApplicationInfo(model.ApplicationId);
115+
var appInfo = await _queryBus.QueryAsync(query);
116+
117+
try
118+
{
119+
var uri =
120+
$"https://coderrapp.com/client/{model.LibraryName}/configure/?appKey={appInfo.AppKey}&sharedSecret={appInfo.SharedSecret}&hostName={_baseConfiguration.BaseUrl}";
121+
var client = new HttpClient { Timeout = TimeSpan.FromSeconds(10) };
122+
var html = await client.GetStringAsync(uri);
123+
model.Instruction = html;
124+
}
125+
catch (Exception)
126+
{
127+
model.ErrorMessage = "Failed to download package information";
128+
}
129+
130+
model.SharedSecret = appInfo.SharedSecret;
131+
model.AppKey = appInfo.AppKey;
132+
model.ReportUrl = _baseConfiguration.BaseUrl;
133+
return View(model);
134+
}
135+
136+
public async Task<ActionResult> Validate(ValidateViewModel model)
137+
{
138+
var query = new FindIncidents()
139+
{
140+
ApplicationId = model.ApplicationId
141+
};
142+
var result = await _queryBus.QueryAsync(query);
143+
if (result.TotalCount == 0)
144+
{
145+
return View();
146+
}
147+
148+
return Redirect("~/#/application/" + model.ApplicationId);
149+
}
150+
151+
protected async Task Init(int maxCount = 0)
152+
{
153+
var query = new GetApplicationList();
154+
var result = await _queryBus.QueryAsync(query);
155+
ViewBag.FirstApplication = result.Length <= maxCount;
156+
}
157+
158+
}
159+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Linq;
5+
using System.Web;
6+
7+
namespace codeRR.Server.Web.Models.Wizard
8+
{
9+
public class ApplicationViewModel
10+
{
11+
[Required]
12+
public string Name { get; set; }
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace codeRR.Server.Web.Models.Wizard
4+
{
5+
public class ConfigurePackageViewModel
6+
{
7+
public string AppKey { get; set; }
8+
public string LibraryName { get; set; }
9+
public Uri ReportUrl { get; set; }
10+
11+
public string SharedSecret { get; set; }
12+
public int ApplicationId { get; set; }
13+
public string Instruction { get; set; }
14+
public string ErrorMessage { get; set; }
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace codeRR.Server.Web.Models.Wizard
7+
{
8+
public class NugetPackage
9+
{
10+
public string Id { get; set; }
11+
public string Description { get; set; }
12+
public string LibraryName { get; set; }
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace codeRR.Server.Web.Models.Wizard
7+
{
8+
public class PackagesViewModel
9+
{
10+
public int ApplicationId { get; set; }
11+
public string ErrorMessage { get; set; }
12+
public NugetPackage[] Packages { get; set; }
13+
public string LibraryName { get; set; }
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace codeRR.Server.Web.Models.Wizard
7+
{
8+
public class ValidateViewModel
9+
{
10+
public int ApplicationId { get; set; }
11+
public int LibraryName { get; set; }
12+
}
13+
}

src/Server/Coderr.Server.Web/Views/Shared/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta name="viewport" content="width=device-width, initial-scale=1.0">
88
<title>@ViewBag.Title - codeRR</title>
99
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
10-
<link rel="stylesheet" href="@Url.Content("~/Content/bootstrap.min.css")">
10+
<link rel="stylesheet" href="@Url.Content("~/Content/bootstrap/bootstrap.min.css")">
1111
@Styles.Render("~/Content/css")
1212
@RenderSection("Styles", false)
1313
<script>window.bootScripts = []</script>

0 commit comments

Comments
 (0)