-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathConstantsFile.cs
More file actions
54 lines (44 loc) · 1.37 KB
/
ConstantsFile.cs
File metadata and controls
54 lines (44 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace ServicePulse;
using System.Reflection;
class ConstantsFile
{
public static string GetContent(Settings settings)
{
var version = GetVersionInformation();
string serviceControlUrl;
string monitoringUrl;
if (settings.EnableReverseProxy)
{
serviceControlUrl = "/api/";
monitoringUrl = settings.MonitoringUri == null ? "!" : "/monitoring-api/";
}
else
{
serviceControlUrl = settings.ServiceControlUri.ToString();
monitoringUrl = settings.MonitoringUri?.ToString() ?? "!";
}
var constantsFile = $$"""
window.defaultConfig = {
default_route: '{{settings.DefaultRoute}}',
version: '{{version}}',
service_control_url: '{{serviceControlUrl}}',
monitoring_urls: ['{{monitoringUrl}}'],
showPendingRetry: {{(settings.ShowPendingRetry ? "true" : "false")}},
}
""";
return constantsFile;
}
static string GetVersionInformation()
{
var majorMinorPatch = "0.0.0";
var attributes = Assembly.GetExecutingAssembly().GetCustomAttributes<AssemblyMetadataAttribute>();
foreach (var attribute in attributes)
{
if (attribute.Key == "MajorMinorPatch")
{
majorMinorPatch = attribute.Value ?? "0.0.0";
}
}
return majorMinorPatch;
}
}