Skip to content

Commit 2bf507f

Browse files
Added AppEnv module
1 parent c3b1aa5 commit 2bf507f

File tree

6 files changed

+145
-98
lines changed

6 files changed

+145
-98
lines changed

DeveloperTools/Controllers/LoadedAssembliesController.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

tests/temp/LoadedAssemblies/Index.cshtml renamed to DeveloperTools/EPiServer.DeveloperTools.Views/Views/AppEnvironment/Index.cshtml

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
@using System.Collections
2-
@using DeveloperTools.Models
3-
@using EPiServer.Shell
4-
@inherits System.Web.Mvc.WebViewPage<DeveloperTools.Models.AssembliesModel>
5-
6-
@{
7-
Layout = Paths.ToResource("EPiServer.DeveloperTools", "Views/Shared/DevToolsMaster.cshtml");
8-
}
2+
@model EPiServer.DeveloperTools.Features.AppEnvironment.AppEnvironmentModel
93

104
<div class="epi-contentArea">
115
<h1 class="EP-prefix">Loaded Assemblies</h1>
@@ -48,36 +42,31 @@
4842
}
4943
</table></pre>
5044

51-
<h2 class="EP-prefix">Misc</h2>
45+
<br/>
46+
<h2 class="EP-prefix">Connection Strings</h2>
5247
<pre><table cellpadding="0" cellspacing="0" border="0" class="display">
48+
@foreach (var entry in Model.ConnectionString)
49+
{
5350
<tr>
54-
<td>Response.Filter</td>
55-
<td>@Request.Filter.ToString()</td>
56-
</tr>
57-
<tr>
58-
<td>Request.ApplicationPath</td>
59-
<td>@Request.ApplicationPath</td>
60-
</tr>
61-
<tr>
62-
<td>Request.PhysicalApplicationPath</td>
63-
<td>@Request.PhysicalApplicationPath</td>
64-
</tr>
65-
<tr>
66-
<td>Request.PhysicalPath</td>
67-
<td>@Request.PhysicalPath</td>
68-
</tr>
69-
<tr>
70-
<td>Request.UrlReferrer</td>
71-
<td>@Request.UrlReferrer</td>
51+
<td>@entry.Key</td>
52+
<td>@entry.Value</td>
7253
</tr>
54+
}
55+
</table></pre>
56+
57+
<h2 class="EP-prefix">Misc</h2>
58+
<pre><table cellpadding="0" cellspacing="0" border="0" class="display">
59+
@foreach (var entry in Model.Misc)
60+
{
7361
<tr>
74-
<td>Request.UserLanguages</td>
75-
<td>@string.Join(",", Request.UserLanguages ?? new string[0])</td>
62+
<td>@entry.Key</td>
63+
<td>@entry.Value</td>
7664
</tr>
65+
}
7766
</table></pre>
7867
</div>
7968

80-
@section Scripts {
69+
@section AdditionalScripts {
8170
<script>
8271
$(document).ready(function () {
8372
$('#theList').dataTable(
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Reflection;
6+
using DeveloperTools.Controllers;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Mvc;
9+
using Microsoft.Data.SqlClient;
10+
using Microsoft.Extensions.Configuration;
11+
12+
namespace EPiServer.DeveloperTools.Features.AppEnvironment;
13+
14+
public class AppEnvironmentController : DeveloperToolsController
15+
{
16+
private readonly IWebHostEnvironment _environment;
17+
private readonly IConfiguration _configuration;
18+
19+
public AppEnvironmentController(IWebHostEnvironment environment, IConfiguration configuration)
20+
{
21+
_environment = environment;
22+
_configuration = configuration;
23+
}
24+
25+
public ActionResult Index()
26+
{
27+
var model = new AppEnvironmentModel { Assemblies = GetLoadedAssemblies(), Misc = GetMiscValues(), ConnectionString = GetConnectionStrings() };
28+
29+
return View(model);
30+
}
31+
32+
private IReadOnlyDictionary<string, string> GetConnectionStrings()
33+
{
34+
return _configuration
35+
.GetSection("ConnectionStrings")
36+
.GetChildren()
37+
.ToDictionary(x => x.Key, x => Sanitize(x.Value));
38+
}
39+
40+
private string Sanitize(string value)
41+
{
42+
try
43+
{
44+
var builder = new SqlConnectionStringBuilder(value) { Password = "****" };
45+
return builder.ToString();
46+
}
47+
catch
48+
{
49+
return value;
50+
}
51+
}
52+
53+
private IReadOnlyDictionary<string, string> GetMiscValues()
54+
{
55+
var result = new Dictionary<string, string>
56+
{
57+
{ "ApplicationName", _environment.ApplicationName },
58+
{ "WebRootPath", _environment.WebRootPath },
59+
{ "ContentRootPath", _environment.ContentRootPath },
60+
{ "EnvironmentName", _environment.EnvironmentName },
61+
{ "WebRootFileProvider", _environment.WebRootFileProvider.ToString() },
62+
{ "ContentRootFileProvider", _environment.ContentRootFileProvider.ToString() },
63+
};
64+
65+
return result;
66+
}
67+
68+
private static List<AssemblyInfo> GetLoadedAssemblies()
69+
{
70+
var assemblies = new List<AssemblyInfo>();
71+
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
72+
{
73+
string fileVersion = null;
74+
var location = assembly.IsDynamic ? "dynamic" :
75+
string.IsNullOrEmpty(assembly.Location) ? new Uri(assembly.CodeBase).LocalPath : assembly.Location;
76+
77+
if (!assembly.IsDynamic)
78+
{
79+
var fileVersionAttribute =
80+
(AssemblyFileVersionAttribute)assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)
81+
.FirstOrDefault();
82+
if (fileVersionAttribute != null)
83+
{
84+
fileVersion = fileVersionAttribute.Version;
85+
}
86+
87+
if (fileVersion == null)
88+
{
89+
var versionInfo = assembly.IsDynamic ? null : FileVersionInfo.GetVersionInfo(location);
90+
if (versionInfo != null)
91+
{
92+
fileVersion = versionInfo.FileVersion;
93+
}
94+
}
95+
}
96+
97+
assemblies.Add(new AssemblyInfo
98+
{
99+
Name = assembly.FullName,
100+
AssemblyVersion = assembly.GetName().Version?.ToString(),
101+
FileVersion = fileVersion ?? assembly.GetName().Version?.ToString(),
102+
Location = assembly.IsDynamic ? "dynamic" : location
103+
});
104+
}
105+
106+
return assemblies;
107+
}
108+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.Generic;
2+
3+
namespace EPiServer.DeveloperTools.Features.AppEnvironment;
4+
5+
public class AppEnvironmentModel
6+
{
7+
public IEnumerable<AssemblyInfo> Assemblies { get; set; }
8+
public IReadOnlyDictionary<string, string> Misc { get; set; } = new Dictionary<string, string>();
9+
public IReadOnlyDictionary<string, string> ConnectionString { get; set; }
10+
}
11+
12+
public class AssemblyInfo
13+
{
14+
public string Name { get; set; }
15+
public string AssemblyVersion { get; set; }
16+
public string FileVersion { get; set; }
17+
public string Location { get; set; }
18+
}

DeveloperTools/Infrastructure/MenuProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public IEnumerable<MenuItem> GetMenuItems()
2727
CreateUrlMenuItem("Welcome", "default", 10),
2828
CreateUrlMenuItem("Startup Perf", "StartupPerf", 20),
2929
CreateUrlMenuItem("IoC", "IOC", 30),
30-
CreateUrlMenuItem("Loaded Assemblies", "LoadedAssemblies", 40),
30+
CreateUrlMenuItem("App Environment", "AppEnvironment", 40),
3131
CreateUrlMenuItem("Revert Content Types", "RevertToDefault", 50),
3232
CreateUrlMenuItem("Content Type Analyzer", "ContentTypeAnalyzer", 60),
3333
CreateUrlMenuItem("Templates", "Templates", 70),

DeveloperTools/Models/AssembliesModel.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)