Skip to content

Commit b00dcb5

Browse files
committed
Remove custom UI template paths code
This no longer worked...time to simplify it. We're off jQuery.tmpl now.
1 parent 4ad522e commit b00dcb5

File tree

4 files changed

+13
-129
lines changed

4 files changed

+13
-129
lines changed

src/MiniProfiler.AspNetCore/EmbeddedProvider.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.AspNetCore.Hosting;
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.Extensions.Options;
4-
using StackExchange.Profiling.Internal;
54
using System.Collections.Concurrent;
65
using System.IO;
76
using System.Reflection;
@@ -55,33 +54,16 @@ public bool TryGetResource(string filename, out string resource)
5554
return true;
5655
}
5756

58-
// Check the on-disk location first, if configured
59-
if (_options.Value.UITemplatesPath.HasValue())
57+
// Fall back to embedded
58+
using (var stream = typeof(MiniProfiler).GetTypeInfo().Assembly.GetManifestResourceStream("StackExchange.Profiling.ui." + filename))
6059
{
61-
var customFile = Path.Combine(_options.Value.UITemplatesPath, filename);
62-
var fileInfo = _env.ContentRootFileProvider.GetFileInfo(customFile);
63-
if (fileInfo.Exists)
60+
if (stream == null)
6461
{
65-
using (var stream = fileInfo.CreateReadStream())
66-
using (var reader = new StreamReader(stream))
67-
{
68-
resource = reader.ReadToEnd();
69-
}
62+
return false;
7063
}
71-
}
72-
else
73-
{
74-
// Fall back to embedded
75-
using (var stream = typeof(MiniProfiler).GetTypeInfo().Assembly.GetManifestResourceStream("StackExchange.Profiling.ui." + filename))
64+
using (var reader = new StreamReader(stream))
7665
{
77-
if (stream == null)
78-
{
79-
return false;
80-
}
81-
using (var reader = new StreamReader(stream))
82-
{
83-
resource = reader.ReadToEnd();
84-
}
66+
resource = reader.ReadToEnd();
8567
}
8668
}
8769

src/MiniProfiler.AspNetCore/MiniProfilerOptions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,5 @@ public class MiniProfilerOptions : MiniProfilerBaseOptions
4040
/// Function to provide the unique user ID based on the request, to store MiniProfiler IDs user
4141
/// </summary>
4242
public Func<HttpRequest, string> UserIdProvider { get; set; } = request => request.HttpContext.Connection.RemoteIpAddress.ToString();
43-
44-
/// <summary>
45-
/// Gets or sets the content directory subfolder to load custom template overrides from.
46-
/// For example, if you're using wwwroot and want to use wwwroot/profiler/, set this to "profiler/"
47-
/// </summary>
48-
public string UITemplatesPath { get; set; }
4943
}
5044
}

src/MiniProfiler/MiniProfilerHandler.cs

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -290,53 +290,21 @@ private string ResultsFullPage(HttpContext context, MiniProfiler profiler)
290290
return Render.SingleResultHtml(profiler, VirtualPathUtility.ToAbsolute(Options.RouteBasePath).EnsureTrailingSlash());
291291
}
292292

293-
#if DEBUG
294-
private static bool BypassLocalLoad = false;
295-
#endif
296-
297293
private bool TryGetResource(string filename, out string resource)
298294
{
299295
filename = filename.ToLower();
300296

301-
#if DEBUG
302-
// attempt to simply load from file system, this lets up modify js without needing to recompile A MILLION TIMES
303-
if (!BypassLocalLoad)
304-
{
305-
var trace = new System.Diagnostics.StackTrace(true);
306-
var path = Path.GetDirectoryName(trace.GetFrames()[0].GetFileName()) + "\\ui\\" + filename;
307-
try
308-
{
309-
resource = File.ReadAllText(path);
310-
return true;
311-
}
312-
catch
313-
{
314-
BypassLocalLoad = true;
315-
}
316-
}
317-
#endif
318-
319297
if (!ResourceCache.TryGetValue(filename, out resource))
320298
{
321-
string customTemplatesPath = HttpContext.Current.Server.MapPath(Options.CustomUITemplates);
322-
string customTemplateFile = Path.Combine(customTemplatesPath, filename);
323-
324-
if (File.Exists(customTemplateFile))
325-
{
326-
resource = File.ReadAllText(customTemplateFile);
327-
}
328-
else
299+
using (var stream = typeof(MiniProfiler).Assembly.GetManifestResourceStream("StackExchange.Profiling.ui." + filename))
329300
{
330-
using (var stream = typeof(MiniProfiler).Assembly.GetManifestResourceStream("StackExchange.Profiling.ui." + filename))
301+
if (stream == null)
331302
{
332-
if (stream == null)
333-
{
334-
return false;
335-
}
336-
using (var reader = new StreamReader(stream))
337-
{
338-
resource = reader.ReadToEnd();
339-
}
303+
return false;
304+
}
305+
using (var reader = new StreamReader(stream))
306+
{
307+
resource = reader.ReadToEnd();
340308
}
341309
}
342310

src/MiniProfiler/MiniProfilerOptions.cs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.IO;
5-
using System.Security.Cryptography;
62
using System.Web;
73
using StackExchange.Profiling.Helpers;
84
using StackExchange.Profiling.Internal;
@@ -63,62 +59,6 @@ public MiniProfilerOptions()
6359
/// </summary>
6460
public bool EnableCompression { get; set; } = true;
6561

66-
/// <summary>
67-
/// The path where custom UI elements are stored.
68-
/// If the custom file doesn't exist, the standard resource is used.
69-
/// This setting should be in APP RELATIVE FORM, e.g. "~/App_Data/MiniProfilerUI"
70-
/// </summary>
71-
/// <remarks>A web server restart is required to reload new files.</remarks>
72-
public string CustomUITemplates { get; set; } = "~/App_Data/MiniProfilerUI";
73-
74-
private string _versionHash;
75-
/// <summary>
76-
/// The hash to use for file cache breaking, this is automatically calculated.
77-
/// </summary>
78-
public override string VersionHash => _versionHash ?? (_versionHash = GetVersionHash());
79-
80-
/// <summary>
81-
/// On first call, set the version hash for all cache breakers.
82-
/// </summary>
83-
private string GetVersionHash()
84-
{
85-
try
86-
{
87-
if (HttpContext.Current == null) return base.VersionHash;
88-
var files = new List<string>();
89-
90-
var customUITemplatesPath = HttpContext.Current.Server.MapPath(CustomUITemplates);
91-
if (Directory.Exists(customUITemplatesPath))
92-
{
93-
files.AddRange(Directory.EnumerateFiles(customUITemplatesPath));
94-
}
95-
96-
if (files.Count == 0) return base.VersionHash;
97-
98-
using (var sha256 = new SHA256CryptoServiceProvider())
99-
{
100-
var hash = new byte[sha256.HashSize / 8];
101-
foreach (string file in files)
102-
{
103-
// sha256 can throw a FIPS exception, but SHA256CryptoServiceProvider is FIPS BABY - FIPS
104-
byte[] contents = File.ReadAllBytes(file);
105-
byte[] hashfile = sha256.ComputeHash(contents);
106-
for (int i = 0; i < (sha256.HashSize / 8); i++)
107-
{
108-
hash[i] = (byte)(hashfile[i] ^ hash[i]);
109-
}
110-
}
111-
return Convert.ToBase64String(hash);
112-
}
113-
}
114-
catch (Exception e)
115-
{
116-
//VersionHash is pre-populated
117-
Debug.WriteLine($"Error calculating folder hash: {e}\n{e.StackTrace}");
118-
return base.VersionHash;
119-
}
120-
}
121-
12262
/// <summary>
12363
/// Configures the <see cref="MiniProfilerHandler"/>.
12464
/// </summary>

0 commit comments

Comments
 (0)